@{
    ViewBag.Title = "Home Page";
}

@model IEnumerable<ServerDetailsEditing.Models.Employee>

@{ Html.Kendo().Grid(Model)
    .Name("Employees")
    
    .Columns(columns =>
    {
        columns.Bound(e => e.FirstName).Width(140);
        columns.Bound(e => e.LastName).Width(140);
        columns.Bound(e => e.Title).Width(200);
        columns.Bound(e => e.Country).Width(200);
        columns.Bound(e => e.City);
    })
    .DetailTemplate(e =>
    {            
            Html.Kendo().TabStrip()
                    .Name("TabStrip_" + e.EmployeeID)
                    .SelectedIndex(0)
                    .Items(items =>
                    {
                        items.Add().Text("Orders").Content(@<text>
                                
                                @(Html.Kendo().Grid(e.Orders)
                                        .Name("Orders_" + e.EmployeeID)
                                        .ToolBar(tb => tb.Create())
                                        .Columns(columns =>
                                        {
                                            columns.Bound(o => o.OrderID).Width(101);
                                            columns.Bound(o => o.ShipCountry).Width(140);
                                            columns.Bound(o => o.ShipAddress).Width(200);
                                            columns.Bound(o => o.ShipName).Width(200);
                                            columns.Bound(o => o.ShippedDate).Format("{0:d}");
                                            columns.Command(o => o.Edit());
                                        })
                                        .Editable(m => m.Mode(GridEditMode.PopUp))
                                        .DataSource(source => source.Server()
                                                .Model(n => n.Id(o => o.OrderID))
                                                .Read(read => read.Action("Index", "Home", new {orderEmployeeID = e.EmployeeID }))
                                                .Update(update => update.Action("Update_Order", "Home"))
                                                .Create(cr=>cr.Action("not","implemented"))
                                                )
                                        .Pageable()
                                        .Sortable()
                                )
                                
                        </text>);
                        items.Add().Text("Contact Information").Content(                                
                                @<div class="employee-details">                                    
                                    <ul>
                                        <li>
                                            <label>Birth Date:</label>@e.BirthDate.Value.ToString("d") 
                                        </li>
                                        <li>
                                            <label>Country:</label>@e.Country 
                                        </li>
                                        <li>
                                            <label>City:</label>@e.City 
                                        </li>
                                        <li>
                                            <label>Address:</label>@e.Address 
                                        </li>
                                        <li>
                                            <label>Home Phone:</label>@e.HomePhone 
                                        </li>
                                    </ul>
                                </div>);                                                       

                    })
                    .Render();
    })
    .RowAction(row =>
    {
        if (row.DataItem.EmployeeID.ToString() == Request.QueryString["orderEmployeeID"])
        {
            row.DetailRow.Expanded = true;
        }
    })
    .ToolBar(tb => tb.Create())
    .Pageable()
    .DataSource(dataSource => dataSource.Server().PageSize(5).Create(cr=>cr.Action("not","implemented"))
        .Model(m=>{
            m.Id(id => id.EmployeeID);
            m.Field(f => f.EmployeeID).DefaultValue(0);
            m.Field(f => f.Address).DefaultValue("");
            m.Field(f => f.BirthDate).DefaultValue(DateTime.Now);
            m.Field(f => f.City).DefaultValue(0);
            m.Field(f => f.LastName).DefaultValue("");
            m.Field(f => f.FirstName).DefaultValue("");
            m.Field(f => f.City).DefaultValue("");
        })
        )
    .Sortable()
    .Render();
}