<UserControl x:Class="DataViewDashboard.Views.BookView"
             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:v="clr-namespace:DataViewDashboard.Views"
             xmlns:vm="clr-namespace:DataViewDashboard.ViewModels"
             xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
             mc:Ignorable="d">
    <UserControl.Resources>
        <Style x:Key="myBookStyle" TargetType="c1:C1Book">
            <Setter Property="ItemsSource" Value="{Binding Source.View}" />
        </Style>
        
        <!-- Orders -->
        <DataTemplate DataType="{x:Type vm:OrdersViewModel}">
            <c1:C1Book Style="{StaticResource myBookStyle}">
                <c1:C1Book.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="20"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <v:OrderTile />
                            <v:SalesOrderDetailsGrid Grid.Row="2" />
                        </Grid>
                    </DataTemplate>
                </c1:C1Book.ItemTemplate>
            </c1:C1Book>
        </DataTemplate>

        <!-- Customers -->
        <DataTemplate DataType="{x:Type vm:CustomersViewModel}">
            <c1:C1Book Style="{StaticResource myBookStyle}">
                <c1:C1Book.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <v:CustomerTile />
                            <v:SalesOrderHeadersGrid Grid.Row="1" />
                        </Grid>
                    </DataTemplate>
                </c1:C1Book.ItemTemplate>
            </c1:C1Book>

        </DataTemplate>

        <!-- Products -->
        <DataTemplate DataType="{x:Type vm:ProductsViewModel}">
            <c1:C1Book Style="{StaticResource myBookStyle}">
                <c1:C1Book.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Margin" Value="2" />
                                </Style>
                            </Grid.Resources>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <v:ProductTile Grid.ColumnSpan="4"/>
                            <StackPanel Orientation="Horizontal" Grid.Row="2" >
                                <TextBlock Text="Total Quantity:" />
                                <TextBlock Text="{Binding SalesOrderDetails, Converter={StaticResource orderQuantityConverter}}" FontWeight="Bold"/>
                                <TextBlock Text="Total Sale:" Margin="10 2 2 2"/>
                                <TextBlock Text="{Binding SalesOrderDetails, Converter={StaticResource orderLineTotalConverter}}" FontWeight="Bold" Foreground="Green"/>
                                <TextBlock Text="Total Cost:" Margin="10 2 2 2"/>
                                <TextBlock Text="{Binding ., Converter={StaticResource orderCostConverter}}" FontWeight="Bold" Foreground="Red"/>
                            </StackPanel>
                            <v:SalesOrderDetailsChart Grid.Row="3" Grid.ColumnSpan="4"/>
                        </Grid>
                    </DataTemplate>
                </c1:C1Book.ItemTemplate>
            </c1:C1Book>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <ContentControl Content="{Binding SelectedDataView}" />
    </Grid>
</UserControl>
