<Page
    x:Class="FoxTube.MainPage"
    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:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
    xmlns:Windows10version1803="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 6)"
    mc:Ignorable="d">

    <Grid Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Windows10version1809:Grid.BackgroundTransition>
            <BrushTransition/>
        </Windows10version1809:Grid.BackgroundTransition>

        <Border x:Name="AppTitleBar"
                IsHitTestVisible="True"
                VerticalAlignment="Top"
                Background="Transparent"
                Canvas.ZIndex="1"
                Margin="12, 8">

                <TextBlock x:Name="AppTitle"
                       Text="FoxTube"
                       VerticalAlignment="Center"
                       Style="{StaticResource CaptionTextBlockStyle}" />
        </Border>

        <NavigationView SelectedItem="toHome" Windows10version1803:BackRequested="Nav_BackRequested" Windows10version1803:PaneClosing="Nav_PaneChanged" Windows10version1803:PaneOpening="Nav_PaneChanged" Windows10version1803:PaneTitle="FoxTube" OpenPaneLength="300" Name="nav" SelectionChanged="Nav_SelectionChanged">

            <NavigationView.MenuItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Padding="5" Margin="-5,0,0,0" Tag="{Binding Snippet.ResourceId.ChannelId}">
                        <PersonPicture Height="20" ProfilePicture="{Binding Snippet.Thumbnails.Medium.Url}" Margin="-5,0,15,0"/>
                        <TextBlock Text="{Binding Snippet.Title}"/>
                    </StackPanel>
                </DataTemplate>
            </NavigationView.MenuItemTemplate>

            <NavigationView.MenuItems>
                <NavigationViewItem x:Uid="/Main/home" Icon="Home" Content="Home" Name="toHome"/>
                <NavigationViewItem x:Uid="/Main/myChannel" Icon="Contact" Content="My channel" Name="toChannel" Visibility="Collapsed"/>
                <NavigationViewItem x:Uid="/Main/subscriptions" Icon="People" Content="Subscriptions" Name="toSubscriptions" Visibility="Collapsed"/>
                <NavigationViewItemHeader x:Uid="/Main/myLibrary" Content="My library" Name="libHeader" Visibility="Collapsed"/>
                <NavigationViewItem x:Uid="/Main/history" Content="History" Name="toHistory" Visibility="Collapsed">
                    <NavigationViewItem.Icon>
                        <FontIcon Glyph="&#xE81C;"/>
                    </NavigationViewItem.Icon>
                </NavigationViewItem>
                <NavigationViewItem x:Uid="/Main/liked" Icon="Like" Content="Liked videos" Name="toLiked" Visibility="Collapsed"/>
                <NavigationViewItem x:Uid="/Main/later" Icon="Clock" Content="Watch later" Name="toLater" Visibility="Collapsed"/>
                <NavigationViewItem x:Uid="/Main/downloads" Icon="Download" Content="Downloads" Name="toDownloads"/>
                <NavigationViewItemHeader x:Uid="/Main/subscriptions" Content="Subscriptions" Name="subsHeader" Visibility="Collapsed"/>
            </NavigationView.MenuItems>

            <NavigationView.PaneFooter>
                <NavigationViewList>
                    <NavigationViewList.ItemContainerTransitions>
                        <TransitionCollection>
                            <EntranceThemeTransition IsStaggeringEnabled="True"/>
                            <ReorderThemeTransition/>
                        </TransitionCollection>
                    </NavigationViewList.ItemContainerTransitions>
                    <NavigationViewItem Name="openWeb" Tapped="Web_Tapped" Icon="Globe" Content="Browser" Visibility="Collapsed"/>
                    <NavigationViewItem x:Uid="/Main/feedback" Name="feedback" Content="Give a feedback" Tapped="Feedback_Click">
                        <NavigationViewItem.Icon>
                            <FontIcon Glyph="&#xED15;"/>
                        </NavigationViewItem.Icon>
                    </NavigationViewItem>

                    <NavigationViewItem x:Uid="/Main/adsFree" Content="Remove ads" Visibility="Collapsed" Tapped="RemoveAds_Tapped" Name="removeAds">
                        <NavigationViewItem.Icon>
                            <FontIcon Glyph="&#xE14D;"/>
                        </NavigationViewItem.Icon>
                    </NavigationViewItem>

                    <NavigationViewItem Name="account" Tapped="OpenContext">
                        <StackPanel Orientation="Horizontal">
                            <FontIcon Glyph="&#xE8FA;" FontSize="16" Margin="0,0,16,0"/>
                            <TextBlock x:Uid="/Main/signIn" Text="Add account"/>
                        </StackPanel>

                        <NavigationViewItem.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem x:Uid="/Main/signEx" Text="Sign in with existing account" Name="signIn" Click="SignIn_Click"/>
                                <MenuFlyoutItem x:Uid="/Main/signNew" Text="Create new Google account" Name="createAccount" Click="CreateAccount_Click"/>
                            </MenuFlyout>
                        </NavigationViewItem.ContextFlyout>
                    </NavigationViewItem>

                    <NavigationViewItem Visibility="Collapsed" Name="avatar" Tapped="OpenContext" Padding="-5">
                        <StackPanel Orientation="Horizontal" Padding="5">
                            <PersonPicture Height="20" Margin="-5,0,15,0"/>
                            <TextBlock Name="myName" Text="My account"/>
                        </StackPanel>

                        <NavigationViewItem.ContextFlyout>
                            <Flyout>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <PersonPicture Width="50" Name="avatarFlyout" VerticalAlignment="Top"/>
                                    <StackPanel Grid.Column="1" Margin="5">
                                        <TextBlock Name="myNameFlyout"/>
                                        <TextBlock Style="{StaticResource CaptionTextBlockStyle}" Name="myEmail"/>
                                        <HyperlinkButton x:Uid="/Main/signOut" Content="Log out" Click="Logout_Click"/>
                                    </StackPanel>
                                </Grid>
                            </Flyout>
                        </NavigationViewItem.ContextFlyout>
                    </NavigationViewItem>
                </NavigationViewList>
            </NavigationView.PaneFooter>

            <NavigationView.AutoSuggestBox>
                <AutoSuggestBox x:Name="search" QueryIcon="Find" QuerySubmitted="Search_QuerySubmitted" TextChanged="Search_TextChanged" x:Uid="/Main/searchPlaceholder" PlaceholderText="Search"/>
            </NavigationView.AutoSuggestBox>

            <Grid>
                <Frame Name="content" Navigated="Content_Navigated"/>
                <Frame Name="videoPlaceholder"/>
            </Grid>

        </NavigationView>
    </Grid>
</Page>
