<Page
    x:Class="WinPrint.Views.MasterDetailPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Style="{StaticResource PageStyle}"
    xmlns:model="using:WinPrint.Core.Models"
    xmlns:views="using:WinPrint.Views"
    xmlns:behaviors="using:WinPrint.Behaviors"
    behaviors:NavigationViewHeaderBehavior.HeaderMode="Never"
    mc:Ignorable="d">
    <Page.Transitions>
        <TransitionCollection>
            <NavigationThemeTransition />
        </TransitionCollection>
    </Page.Transitions>
    <Page.Resources>
        <DataTemplate x:Key="ItemTemplate" x:DataType="model:SampleOrder">
            <Grid Height="60">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <FontIcon
                    Grid.Column="0"
                    VerticalAlignment="Center"
                    FontSize="32"
                    Glyph="{x:Bind Symbol}" />
                <StackPanel
                    Grid.Column="1"
                    Margin="{StaticResource SmallLeftMargin}"
                    VerticalAlignment="Center">
                    <TextBlock Style="{ThemeResource ListTitleStyle}" Text="{x:Bind Company}" />
                    <TextBlock Style="{StaticResource ListSubTitleStyle}" Text="{x:Bind Status}" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="DetailsTemplate">
            <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
                <views:MasterDetailDetailControl MasterMenuItem="{Binding}" />
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="NoSelectionContentTemplate">
            <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
                <TextBlock
                    x:Uid="MasterDetail_NoSelection"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Style="{StaticResource SubtitleTextBlockStyle}"
                    TextAlignment="Center" />
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="MasterHeaderTemplate">
            <Grid Height="40">
                <TextBlock
                    x:Name="headerText"
                    VerticalAlignment="Center"
                    Style="{StaticResource ListTitleStyle}"
                    Text="{Binding}" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="MinimalMasterHeaderTemplate">
            <Grid Height="40">
                <TextBlock
                    x:Name="headerText"
                    Margin="96,0,0,0"
                    Text="{Binding}"
                    VerticalAlignment="Center"
                    Style="{StaticResource ListTitleStyle}" />
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Grid x:Name="ContentArea">
        <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState>
                        <VisualState.StateTriggers>
                            <!--641 is the default CompactModeThresholdWidth in NavigationView -->
                            <AdaptiveTrigger MinWindowWidth="641" />
                        </VisualState.StateTriggers>
                        <VisualState.Setters>
                            <Setter Target="MasterDetailsViewControl.MasterHeaderTemplate" Value="{StaticResource MasterHeaderTemplate}" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        <controls:MasterDetailsView
            x:Name="MasterDetailsViewControl"
            x:Uid="MasterDetail"
            Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}"
            BorderBrush="Transparent"
            DetailsTemplate="{StaticResource DetailsTemplate}"
            ItemsSource="{x:Bind ViewModel.SampleItems}"
            ItemTemplate="{StaticResource ItemTemplate}"
            BackButtonBehavior="Automatic"
            MasterHeaderTemplate="{StaticResource MinimalMasterHeaderTemplate}"
            NoSelectionContentTemplate="{StaticResource NoSelectionContentTemplate}"
            SelectedItem="{x:Bind ViewModel.Selected, Mode=TwoWay}" />
    </Grid>
</Page>
