<?xml version="1.0" encoding="utf-8" ?>
<local:RootLayoutBase
    x:Class="RodelAgent.UI.Controls.RootLayout"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animations="using:CommunityToolkit.WinUI.Animations"
    xmlns:base="using:Richasy.WinUI.Share.Base"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:RodelAgent.UI.Extensions"
    xmlns:local="using:RodelAgent.UI.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodels="using:Richasy.WinUI.Share.ViewModels"
    mc:Ignorable="d">

    <UserControl.Resources>
        <DataTemplate x:Key="AppNavItemTemplate" x:DataType="viewmodels:AppNavigationItemViewModel">
            <base:AppNavigationViewItem
                Content="{x:Bind Title}"
                IsSelected="{x:Bind IsSelected, Mode=TwoWay}"
                SelectsOnInvoked="True"
                ShowUnread="{x:Bind ShowUnread, Mode=OneWay}"
                Style="{StaticResource MainNavigationViewItemStyle}"
                Symbol="{x:Bind Symbol}"
                Tag="{x:Bind}" />
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <base:AppTitleBar
            x:Name="MainTitleBar"
            Title="{ext:Locale Name=AppName}"
            BackRequested="OnBackRequested"
            IsBackButtonVisible="{x:Bind ViewModel.IsOverlayOpen, Mode=OneWay}"
            IsBackEnabled="True">
            <Grid HorizontalAlignment="Center" />
            <base:AppTitleBar.IconElement>
                <BitmapIcon ShowAsMonochrome="False" UriSource="Assets/small-logo.png" />
            </base:AppTitleBar.IconElement>
        </base:AppTitleBar>

        <NavigationView
            x:Name="NavView"
            Grid.Row="1"
            BackRequested="OnNavViewBackRequested"
            FooterMenuItemsSource="{x:Bind ViewModel.FooterItems, Mode=OneWay}"
            ItemInvoked="OnNavViewItemInvoked"
            MenuItemTemplate="{StaticResource AppNavItemTemplate}"
            MenuItemsSource="{x:Bind ViewModel.MenuItems, Mode=OneWay}"
            SelectionFollowsFocus="Disabled"
            Style="{StaticResource MainNavigationViewStyle}">
            <Grid
                x:Name="MainGrid"
                BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
                BorderThickness="1,1,0,0">
                <Grid>
                    <Frame x:Name="MainFrame" Visibility="{x:Bind ViewModel.IsOverlayOpen, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                    <Grid x:Name="OverlayGrid" Visibility="{x:Bind ViewModel.IsOverlayOpen, Mode=OneWay}">
                        <Frame x:Name="OverlayFrame" />
                    </Grid>
                    <animations:Implicit.ShowAnimations>
                        <animations:OpacityAnimation
                            From="0"
                            To="1"
                            Duration="0:0:0.26" />
                    </animations:Implicit.ShowAnimations>
                </Grid>
            </Grid>
        </NavigationView>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="WideState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource WindowNarrowMinWidth}" />
                    </VisualState.StateTriggers>
                </VisualState>
                <VisualState x:Name="NarrowState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="MainTitleBar.Title" Value="" />
                        <Setter Target="MainTitleBar.Subtitle" Value="" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="PlayerStates">
                <VisualState x:Name="NormalState" />
                <VisualState x:Name="PlayerState">
                    <VisualState.Setters>
                        <Setter Target="MainGrid.BorderThickness" Value="0" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</local:RootLayoutBase>
