<UserControl x:Class="DataViewDashboard.Views.DataGridView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:DataViewDashboard"
             xmlns:vm="clr-namespace:DataViewDashboard.ViewModels"
             xmlns:v="clr-namespace:DataViewDashboard.Views"
             xmlns:c="clr-namespace:DataViewDashboard.Converters"
             mc:Ignorable="d" 
             xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">
    <UserControl.Resources>
        <c:AlphabeticTextGroupConverter x:Key="alphabetTextGroupConverter" />
        <c:CustomerOrdersVisibilityConverter x:Key="customerOrdersVisibilityConverter" />

        <Style TargetType="TextBlock">
            <Setter Property="Margin" Value="2" />
            <Setter Property="FontSize" Value="12"/>
        </Style>

        <!-- Customers -->
        <DataTemplate DataType="{x:Type vm:CustomersViewModel}">
            <Grid>
                <c1:C1DataGrid x:Name="c1DataGrid1" 
                               ItemsSource="{Binding Source.View}" 
                               AutoGenerateColumns="False"
                               RowHeight="30" 
                               CanUserAddRows="False"
                               CanUserGroup="True" >
                    <c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                        <c1:C1AdvancedFiltersBehavior/>
                    </c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                    <c1:C1DataGrid.Columns>
                        <c1:DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" FilterMemberPath="FirstName" SortMemberPath="FirstName" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                        <c1:DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" FilterMemberPath="LastName" SortMemberPath="LastName" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                        <c1:DataGridTextColumn Header="Company Name" Binding="{Binding CompanyName}" FilterMemberPath="CompanyName" SortMemberPath="CompanyName" />
                        <c1:DataGridTextColumn Header="Email Address" Binding="{Binding EmailAddress}" FilterMemberPath="EmailAddress" SortMemberPath="EmailAddress" />
                        <c1:DataGridTextColumn Header="Phone" Binding="{Binding Phone}" FilterMemberPath="Phone" SortMemberPath="Phone" />
                        <c1:DataGridDateTimeColumn Header="Last Modified" Binding="{Binding ModifiedDate}" FilterMemberPath="ModifiedDate" SortMemberPath="ModifiedDate" />
                    </c1:C1DataGrid.Columns>
                    <c1:C1DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <c1:C1TabControl TabItemShape="Rectangle" >
                                <c1:C1TabItem Header="Addresses">
                                    <c1:C1DataGrid ItemsSource="{Binding CustomerAddresses}" CanUserGroup="False"
                                                   AutoGenerateColumns="False"
                                                   RowHeight="30" 
                                                   CanUserAddRows="False">
                                        <c1:C1DataGrid.Columns>
                                            <c1:DataGridTextColumn Header="Address Type" Binding="{Binding AddressType}" SortMemberPath="AddressType" FilterMemberPath="AddressType" />
                                            <c1:DataGridTextColumn Header="Line 1" Binding="{Binding Address.AddressLine1}" SortMemberPath="AddressLine1" FilterMemberPath="AddressLine1" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                                            <c1:DataGridTextColumn Header="Line 2" Binding="{Binding Address.AddressLine2}" SortMemberPath="Address.AddressLine2" FilterMemberPath="Address.AddressLine2" />
                                            <c1:DataGridTextColumn Header="City" Binding="{Binding Address.City}" SortMemberPath="Address.City" FilterMemberPath="Address.City" />
                                            <c1:DataGridTextColumn Header="State/Province" Binding="{Binding Address.StateProvince}" SortMemberPath="Address.StateProvince" FilterMemberPath="Address.StateProvince" />
                                            <c1:DataGridTextColumn Header="Country/Region" Binding="{Binding Address.CountryRegion}" SortMemberPath="Address.CountryRegion" FilterMemberPath="Address.CountryRegion" />
                                            <c1:DataGridTextColumn Header="Postal Code" Binding="{Binding Address.PostalCode}" SortMemberPath="Address.PostalCode" FilterMemberPath="Address.PostalCode" />
                                            <c1:DataGridDateTimeColumn Header="Last Modified" Binding="{Binding Address.ModifiedDate}" SortMemberPath="Address.ModifiedDate" FilterMemberPath="Address.ModifiedDate" />
                                        </c1:C1DataGrid.Columns>
                                    </c1:C1DataGrid>
                                </c1:C1TabItem>
                                <c1:C1TabItem Header="Orders">
                                    <v:SalesOrderHeadersGrid />
                                </c1:C1TabItem>
                            </c1:C1TabControl>
                        </DataTemplate>
                    </c1:C1DataGrid.RowDetailsTemplate>
                </c1:C1DataGrid>
            </Grid>
        </DataTemplate>
        <!-- Products -->
        <DataTemplate DataType="{x:Type vm:ProductsViewModel}">
            <Grid>
                <c1:C1DataGrid x:Name="c1DataGrid1" ItemsSource="{Binding Source.View}"
                               AutoGenerateColumns="False"
                               RowHeight="30" 
                               CanUserAddRows="False"
                               CanUserGroup="True" >
                    <c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                        <c1:C1AdvancedFiltersBehavior/>
                    </c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                    <c1:C1DataGrid.Columns>
                        <c1:DataGridImageColumn Header="Thumbnail" Binding="{Binding ThumbNailPhoto, Converter={StaticResource imageFromDBConverter}}" SortMemberPath="ThumbnailPhotoFileName" />
                        <c1:DataGridTextColumn Header="Product Number" Binding="{Binding ProductNumber}" SortMemberPath="ProductNumber" FilterMemberPath="ProductNumber" />
                        <c1:DataGridTextColumn Header="Name" Binding="{Binding Name}" SortMemberPath="Name" FilterMemberPath="Name" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                        <c1:DataGridTextColumn Header="Category" Binding="{Binding ProductCategory.Name}" SortMemberPath="ProductCategory.Name" FilterMemberPath="ProductCategory.Name" />
                        <c1:DataGridTextColumn Header="Product Model" Binding="{Binding ProductModel.Name}" SortMemberPath="ProductModel.Name" FilterMemberPath="ProductModel.Name" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                        <!--<c1:DataGridTemplateColumn Header="Color" SortMemberPath="Color">
                            <c1:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <c1:C1CheckeredBorder Background="{Binding Color, Converter={StaticResource colorConverter}, Mode=OneWay}" Width="50" Height="30"/>
                                </DataTemplate>
                            </c1:DataGridTemplateColumn.CellTemplate>
                        </c1:DataGridTemplateColumn>-->
                        <c1:DataGridBoundColumn Header="Color" Binding="{Binding Color}" SortMemberPath="Color" FilterMemberPath="Color" />
                        <c1:DataGridNumericColumn Header="Standard Cost" Binding="{Binding StandardCost}" SortMemberPath="StandardCost" FilterMemberPath="StandardCost" Format="c2"/>
                        <c1:DataGridNumericColumn Header="List Price" Binding="{Binding ListPrice}" SortMemberPath="ListPrice" FilterMemberPath="ListPrice" />
                        <c1:DataGridTextColumn Header="Size" Binding="{Binding Size}" SortMemberPath="Size" FilterMemberPath="Size" />
                        <c1:DataGridTextColumn Header="Weight" Binding="{Binding Weight}" SortMemberPath="Weight" FilterMemberPath="Weight" />
                        <c1:DataGridDateTimeColumn Header="Sell Start Date" Binding="{Binding SellStartDate}" SortMemberPath="SellStartDate" FilterMemberPath="SellStartDate" DateFormat="Short" EditMode="Date" />
                        <c1:DataGridDateTimeColumn Header="Sell End Date" Binding="{Binding SellEndDate}" SortMemberPath="SellEndDate" FilterMemberPath="SellEndDate" DateFormat="Short" EditMode="Date"/>
                    </c1:C1DataGrid.Columns>
                    <c1:C1DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <c1:C1TabControl TabItemShape="Rectangle">
                                <c1:C1TabItem Header="Product Descriptions">
                                    <c1:C1DataGrid ItemsSource="{Binding ProductModel.ProductModelProductDescriptions}" 
                                                   CanUserGroup="False"
                                                   AutoGenerateColumns="False"
                                                   RowHeight="30" 
                                                   CanUserAddRows="False">
                                        <c1:C1DataGrid.Columns>
                                            <c1:DataGridTextColumn Header="Culture" Binding="{Binding Culture}" SortMemberPath="Culture" FilterMemberPath="Culture" />
                                            <c1:DataGridTextColumn Header="Product Model" Binding="{Binding ProductModel.Name}" SortMemberPath="ProductModel.Name" FilterMemberPath="ProductModel.Name" GroupConverter="{StaticResource alphabetTextGroupConverter}"/>
                                            <c1:DataGridTextColumn Header="Description" Binding="{Binding ProductDescription.Description}" SortMemberPath="ProductDescription.Description" FilterMemberPath="ProductDescription.Description" />
                                        </c1:C1DataGrid.Columns>
                                    </c1:C1DataGrid>
                                </c1:C1TabItem>
                                <c1:C1TabItem Header="Sales">
                                    <v:SalesOrderDetailsChart Height="275" />
                                </c1:C1TabItem>
                            </c1:C1TabControl>
                        </DataTemplate>
                    </c1:C1DataGrid.RowDetailsTemplate>
                </c1:C1DataGrid>
            </Grid>
        </DataTemplate>
        <!-- Orders -->
        <DataTemplate DataType="{x:Type vm:OrdersViewModel}">
            <Grid>
                <c1:C1DataGrid x:Name="c1DataGrid1" ItemsSource="{Binding Source.View}"
                               AutoGenerateColumns="False"
                               RowHeight="30" 
                               CanUserAddRows="False"
                               CanUserGroup="True" >
                    <c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                        <c1:C1AdvancedFiltersBehavior/>
                    </c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
                    <c1:C1DataGrid.Columns>
                        <c1:DataGridTextColumn Header="Order Number" Binding="{Binding SalesOrderNumber}" FilterMemberPath="SalesOrderNumber" SortMemberPath="SalesOrderNumber"/>
                        <c1:DataGridTextColumn Header="Purchase Number" Binding="{Binding PurchaseOrderNumber}" FilterMemberPath="PurchaseOrderNumber" SortMemberPath="PurchaseOrderNumber"/>
                        <c1:DataGridTextColumn Header="Account Number" Binding="{Binding AccountNumber}" FilterMemberPath="AccountNumber" SortMemberPath="AccountNumber"/>
                        <c1:DataGridTextColumn Header="Company" Binding="{Binding Customer.CompanyName}" FilterMemberPath="Customer.CompanyName" SortMemberPath="Customer.CompanyName"/>
                        <c1:DataGridTextColumn Header="Sales Person" Binding="{Binding Customer.SalesPerson}" FilterMemberPath="Customer.SalesPerson" SortMemberPath="Customer.SalesPerson"/>
                        <c1:DataGridDateTimeColumn Header="Order Date" Binding="{Binding OrderDate}" FilterMemberPath="OrderDate" SortMemberPath="OrderDate" />
                        <c1:DataGridNumericColumn Header="Sub Total" Binding="{Binding SubTotal}" FilterMemberPath="SubTotal" SortMemberPath="SubTotal" Format="c2"/>
                        <c1:DataGridNumericColumn Header="Tax Amount" Binding="{Binding TaxAmt}" FilterMemberPath="TaxAmt" SortMemberPath="TaxAmt" Format="c2"/>
                        <c1:DataGridNumericColumn Header="Freight" Binding="{Binding Freight}" FilterMemberPath="Freight" SortMemberPath="Freight" />
                        <c1:DataGridNumericColumn Header="Total Due" Binding="{Binding TotalDue}" FilterMemberPath="TotalDue" SortMemberPath="TotalDue" Format="c2" />
                        <c1:DataGridDateTimeColumn Header="Due Date" Binding="{Binding DueDate}" FilterMemberPath="DueDate" SortMemberPath="DueDate" />
                        <c1:DataGridDateTimeColumn Header="Ship Date" Binding="{Binding ShipDate}" FilterMemberPath="ShipDate" SortMemberPath="ShipDate" />
                        <c1:DataGridTextColumn Header="Status" Binding="{Binding Status}" FilterMemberPath="Status" SortMemberPath="Status"/>
                        <c1:DataGridCheckBoxColumn Header="Online Order" Binding="{Binding OnlineOrderFlag}" FilterMemberPath="OnlineOrderFlag" SortMemberPath="OnlineOrderFlag" />
                        <c1:DataGridDateTimeColumn Header="Last Modified" Binding="{Binding ModifiedDate}" FilterMemberPath="ModifiedDate" SortMemberPath="ModifiedDate" />
                    </c1:C1DataGrid.Columns>
                    <c1:C1DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <c1:C1TabControl TabItemShape="Rectangle">
                                <c1:C1TabItem Header="Order Details">
                                    <v:SalesOrderDetailsGrid MaxHeight="400"/>
                                </c1:C1TabItem>
                                <c1:C1TabItem Header="Customer">
                                    <Grid>
                                        <c1:C1PropertyGrid x:Name="c1PropertyGrid1" SelectedObject="{Binding Customer}" AutoGenerateProperties="False">
                                            <c1:C1PropertyGrid.PropertyAttributes>
                                                <c1:PropertyAttribute MemberName="FirstName" DisplayName="First Name"  />
                                                <c1:PropertyAttribute MemberName="LastName" DisplayName="Last Name"  />
                                                <c1:PropertyAttribute MemberName="CompanyName" DisplayName="Company Name" />
                                                <c1:PropertyAttribute MemberName="EmailAddress" DisplayName="Email" />
                                                <c1:PropertyAttribute MemberName="Phone" />
                                            </c1:C1PropertyGrid.PropertyAttributes>
                                        </c1:C1PropertyGrid>
                                    </Grid>
                                </c1:C1TabItem>
                            </c1:C1TabControl>
                        </DataTemplate>
                    </c1:C1DataGrid.RowDetailsTemplate>
                </c1:C1DataGrid>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <ContentControl Content="{Binding SelectedDataView}" />
    </Grid>
</UserControl>
