<Common:LayoutAwarePage
    x:Class="WintellogMvvm.ImageDetailsPage"
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:DataModel="using:WintellogMvvm.DataModel" xmlns:Common="using:WintellogMvvm.Common"
    xmlns:Data="using:PortableWintellog.Data" mc:Ignorable="d">

    <Page.BottomAppBar>
        <AppBar x:Name="AppBar" Margin="10,0,10,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="LeftBar" Orientation="Horizontal" HorizontalAlignment="Left">                    
                </StackPanel>
                <StackPanel x:Name="RightBar" Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1">
                    <Button x:Name="Home" HorizontalAlignment="Right" Style="{StaticResource HomeAppBarButtonStyle}" Click="Home_Click_1"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
    
    <Grid
        x:Name="LayoutRoot"
        Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
        DataContext="{Binding CurrentItem}"
        d:DataContext="{Binding GroupList[0].Items[0], Source={d:DesignInstance Type=Data:BlogDataSource, IsDesignTimeCreatable=True}}">

        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}" Grid.Column="1"/>
        </Grid>

        <!--
            The remainder of the page is one large FlipView that displays details for
            one item at a time, allowing the user to flip through all items in the chosen
            group
        -->
        <FlipView
            x:Name="flipView"
            AutomationProperties.AutomationId="ImagesFlipView"
            AutomationProperties.Name="Image Details"
            Grid.Row="1"
            Margin="0,-3,0,0"
            ItemsSource="{Binding FilteredList}">
            
            <FlipView.ItemTemplate>
                <DataTemplate>
                    <Image x:Name="image" MaxHeight="480" Margin="0,20,0,10" Stretch="None">
                        <Image.Source>
                            <BitmapImage UriSource="{Binding}"/>
                        </Image.Source>
                    </Image>
                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup>
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The back button respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <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>
</Common:LayoutAwarePage>