<Page
    x:Class="DisplayHighSchoolStudents.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DisplayHighSchoolStudents"
    xmlns:elpaso="using:ElPasoHighSchool"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    
    <Page.Resources>
        <elpaso:StudentBodyPresenter x:Key="presenter" />

        <DataTemplate x:Key="studentTemplate">
            <Border Height="120"
                    Width="280">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"
                           Source="{Binding PhotoFilename}"
                           Height="120"
                           Margin="5" />

                    <TextBlock Text="{Binding FullName}"
                               Grid.Row="0" Grid.Column="1"
                               VerticalAlignment="Center"
                               Margin="5 0" />

                    <StackPanel Grid.Row="1" Grid.Column="1"
                                Orientation="Horizontal"
                                VerticalAlignment="Center"
                                Margin="5 0">
                        <TextBlock Text="GPA =&#x00A0;" />
                        <TextBlock Text="{Binding GradePointAverage}" />
                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>
    </Page.Resources>

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
          DataContext="{Binding Source={StaticResource presenter},
                                Path=StudentBody}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <Button Name="backButton"
                    Grid.Column="0"
                    Style="{StaticResource BackButtonStyle}"
                    IsEnabled="False" />

            <TextBlock Name="pageTitle"
                       Text="{Binding School}" 
                       Grid.Column="1" 
                       Style="{StaticResource PageHeaderTextStyle}" />
        </Grid>
                   
        <GridView Name="gridView"
                  Grid.Row="1"
                  ItemsSource="{Binding Students}"
                  Padding="116 0 40 46"
                  SelectionMode="None"
                  IsSwipeEnabled="False"
                  IsItemClickEnabled="True"
                  ItemClick="OnGridViewItemClick"
                  ItemTemplate="{StaticResource studentTemplate}" />
        
        <ListView Name="listView" 
                  Grid.Row="1"
                  ItemsSource="{Binding Students}"
                  Visibility="Collapsed"
                  SelectionMode="None"
                  IsSwipeEnabled="False"
                  IsItemClickEnabled="True"
                  ItemClick="OnGridViewItemClick"
                  ItemTemplate="{StaticResource studentTemplate}" />
        
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ApplicationViewStates">
                
                <VisualState x:Name="FullScreenLandscape" />
                
                <VisualState x:Name="Filled" />
                
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView"
                                                       Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96 0 10 56" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
