<controls:EnhancedPage
    x:Class="Pixeval.Pages.IllustrationViewer.IllustrationViewerPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Pixeval.Controls"
    xmlns:controls1="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:flyoutContent="using:Pixeval.Controls.FlyoutContent"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    KeyboardAcceleratorPlacementMode="Hidden"
    Loaded="IllustrationViewerPage_OnLoaded"
    mc:Ignorable="d">
    <controls:EnhancedPage.Resources>
        <Thickness x:Key="NormalMargin">0,48,0,0</Thickness>
        <AcrylicBrush
            x:Key="BottomCommandSectionBackground"
            FallbackColor="{StaticResource SecondaryAccentColor}"
            TintColor="{StaticResource SecondaryAccentColor}"
            TintLuminosityOpacity="0.8"
            TintOpacity="0.8" />
    </controls:EnhancedPage.Resources>
    <controls:EnhancedPage.KeyboardAccelerators>
        <KeyboardAccelerator Key="Left" Invoked="PrevButton_OnClicked" />
        <KeyboardAccelerator Key="Right" Invoked="NextButton_OnClicked" />
        <KeyboardAccelerator Key="Up" Invoked="PrevButton_OnRightTapped" />
        <KeyboardAccelerator Key="Down" Invoked="NextButton_OnRightTapped" />
    </controls:EnhancedPage.KeyboardAccelerators>
    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="48" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="48" />
            </Grid.RowDefinitions>
            <controls:WorkViewerSplitView
                x:Name="EntryViewerSplitView"
                Grid.Row="1"
                MenuItemsSource="{x:Bind _viewModel.Tags}">
                <controls:WorkViewerSplitView.PaneContent>
                    <Grid Background="Transparent">
                        <Frame
                            x:Name="IllustrationImageShowcaseFrame"
                            Grid.Row="0"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch" />
                        <controls1:DockPanel LastChildFill="False">
                            <controls:PageButton
                                Width="150"
                                controls1:DockPanel.Dock="Left"
                                ButtonClick="PrevButton_OnClicked"
                                ButtonRightTapped="PrevButton_OnRightTapped"
                                ButtonVisibility="{x:Bind controls:C.IsNotNullToVisibility(_viewModel.PrevButtonText), Mode=OneWay}"
                                IsPrev="True"
                                ToolTip="{x:Bind _viewModel.PrevButtonText, Mode=OneWay}" />
                            <controls:PageButton
                                Width="150"
                                controls1:DockPanel.Dock="Right"
                                ButtonClick="NextButton_OnClicked"
                                ButtonRightTapped="NextButton_OnRightTapped"
                                ButtonVisibility="{x:Bind controls:C.IsNotNullToVisibility(_viewModel.NextButtonText), Mode=OneWay}"
                                IsPrev="False"
                                ToolTip="{x:Bind _viewModel.NextButtonText, Mode=OneWay}" />
                        </controls1:DockPanel>

                        <!--  工具栏的识别区  -->
                        <Grid
                            Width="600"
                            Height="200"
                            Padding="50"
                            VerticalAlignment="Bottom"
                            Background="Transparent"
                            Opacity="0">
                            <Grid.OpacityTransition>
                                <ScalarTransition />
                            </Grid.OpacityTransition>
                            <interactivity:Interaction.Behaviors>
                                <interactivity:EventTriggerBehavior EventName="PointerEntered">
                                    <interactivity:ChangePropertyAction PropertyName="Opacity" Value="1" />
                                </interactivity:EventTriggerBehavior>
                                <interactivity:EventTriggerBehavior EventName="PointerExited">
                                    <interactivity:ChangePropertyAction PropertyName="Opacity" Value="0" />
                                </interactivity:EventTriggerBehavior>
                            </interactivity:Interaction.Behaviors>
                            <Border
                                HorizontalAlignment="Center"
                                VerticalAlignment="Bottom"
                                Background="{StaticResource BottomCommandSectionBackground}"
                                BorderBrush="{ThemeResource SecondaryAccentBorderBrush}"
                                BorderThickness="0.5"
                                CornerRadius="{ThemeResource ControlCornerRadius}"
                                Opacity="0.7"
                                Translation="0,0,30">
                                <Border.Shadow>
                                    <ThemeShadow x:Name="CommandBorderDropShadow" />
                                </Border.Shadow>
                                <Border.OpacityTransition>
                                    <ScalarTransition />
                                </Border.OpacityTransition>
                                <interactivity:Interaction.Behaviors>
                                    <interactivity:EventTriggerBehavior EventName="PointerEntered">
                                        <interactivity:ChangePropertyAction PropertyName="Opacity" Value="1" />
                                    </interactivity:EventTriggerBehavior>
                                    <interactivity:EventTriggerBehavior EventName="PointerExited">
                                        <interactivity:ChangePropertyAction PropertyName="Opacity" Value="0.7" />
                                    </interactivity:EventTriggerBehavior>
                                </interactivity:Interaction.Behaviors>
                                <controls1:DockPanel>
                                    <PipsPager
                                        x:Name="PipsPager"
                                        Margin="5"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        controls1:DockPanel.Dock="Top"
                                        MaxVisiblePips="10"
                                        NextButtonVisibility="Visible"
                                        NumberOfPages="{x:Bind _viewModel.PageCount, Mode=OneWay}"
                                        PreviousButtonVisibility="Visible"
                                        SelectedPageIndex="{x:Bind _viewModel.CurrentPageIndex, Mode=TwoWay}"
                                        Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}" />
                                    <CommandBar DefaultLabelPosition="Collapsed" OverflowButtonVisibility="Collapsed">
                                        <AppBarButton
                                            Command="{x:Bind _viewModel.CurrentIllustration.BookmarkCommand, Mode=OneWay}"
                                            CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}"
                                            IsEnabled="{x:Bind _viewModel.CurrentImage.LoadSuccessfully, Mode=OneWay}" />
                                        <AppBarButton Command="{x:Bind _viewModel.CurrentImage.RotateCounterclockwiseCommand, Mode=OneWay}" />
                                        <AppBarToggleButton Command="{x:Bind _viewModel.CurrentImage.MirrorCommand, Mode=OneWay}" IsChecked="{x:Bind _viewModel.CurrentImage.IsMirrored, Mode=OneWay}" />
                                        <AppBarButton Command="{x:Bind _viewModel.CurrentImage.RotateClockwiseCommand, Mode=OneWay}" />
                                        <AppBarButton
                                            Command="{x:Bind _viewModel.CurrentPage.SaveCommand, Mode=OneWay}"
                                            CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}"
                                            IsEnabled="{x:Bind _viewModel.CurrentImage.LoadSuccessfully, Mode=OneWay}" />
                                        <AppBarButton
                                            Command="{x:Bind _viewModel.CurrentIllustration.MangaSaveCommand, Mode=OneWay}"
                                            CommandParameter="{x:Bind}"
                                            Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}" />
                                    </CommandBar>
                                </controls1:DockPanel>
                            </Border>
                        </Grid>
                    </Grid>
                </controls:WorkViewerSplitView.PaneContent>
            </controls:WorkViewerSplitView>
            <Grid Grid.Row="0" VerticalAlignment="Top">
                <CommandBar HorizontalAlignment="Center" DefaultLabelPosition="Collapsed">
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.PlayGifCommand, Mode=OneWay}" Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsUgoira), Mode=OneWay}" />
                    <AppBarButton
                        Command="{x:Bind _viewModel.CurrentPage.CopyCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}"
                        IsEnabled="{x:Bind _viewModel.CurrentImage.LoadSuccessfully, Mode=OneWay}" />
                    <AppBarButton
                        Command="{x:Bind _viewModel.CurrentPage.SaveCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}"
                        IsEnabled="{x:Bind _viewModel.CurrentImage.LoadSuccessfully, Mode=OneWay}" />
                    <AppBarButton
                        Command="{x:Bind _viewModel.CurrentPage.SaveAsCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}"
                        IsEnabled="{x:Bind _viewModel.CurrentImage.LoadSuccessfully, Mode=OneWay}" />
                    <AppBarButton
                        Command="{x:Bind _viewModel.CurrentIllustration.MangaSaveCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind}"
                        Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}" />
                    <AppBarButton
                        Command="{x:Bind _viewModel.CurrentIllustration.MangaSaveAsCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind}"
                        Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}" />
                    <AppBarSeparator />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.SetAsCommand, Mode=OneWay}">
                        <AppBarButton.Flyout>
                            <MenuFlyout>
                                <MenuFlyoutItem Command="{x:Bind _viewModel.CurrentImage.SetAsBackgroundCommand, Mode=OneWay}" />
                                <MenuFlyoutItem Command="{x:Bind _viewModel.CurrentImage.SetAsLockScreenCommand, Mode=OneWay}" />
                            </MenuFlyout>
                        </AppBarButton.Flyout>
                    </AppBarButton>
                    <AppBarSeparator />
                    <AppBarButton
                        x:Name="AddToBookmarkButton"
                        Click="AddToBookmarkButton_OnClicked"
                        Command="{x:Bind _viewModel.AddToBookmarkCommand}"
                        CommandParameter="{x:Bind _viewModel.CurrentImage.DownloadParameter, Mode=OneWay}" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentIllustration.GenerateLinkCommand, Mode=OneWay}" CommandParameter="{x:Bind}" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentIllustration.GenerateWebLinkCommand, Mode=OneWay}" CommandParameter="{x:Bind}" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentIllustration.OpenInWebBrowserCommand, Mode=OneWay}" />
                    <AppBarButton
                        x:Name="ShowQrCodeButton"
                        Command="{x:Bind _viewModel.CurrentIllustration.ShowQrCodeCommand, Mode=OneWay}"
                        CommandParameter="{x:Bind ShowQrCodeTeachingTip}" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.ShareCommand, Mode=OneWay}" />
                </CommandBar>
            </Grid>
            <controls:AdvancedItemsView
                x:Name="ThumbnailItemsView"
                Grid.Row="2"
                Margin="5"
                Padding="0,0,0,15"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                ItemsSource="{x:Bind _viewModel.Illustrations}"
                LayoutType="HorizontalStack"
                MinItemHeight="80"
                MinItemWidth="80"
                PreviewKeyDown="ThumbnailItemsView_OnPreviewKeyDown"
                SelectedIndex="{x:Bind _viewModel.CurrentIllustrationIndex, Mode=TwoWay}"
                SelectionMode="Single"
                Visibility="{x:Bind controls:C.ToVisibility(_viewModel.IsBottomListOpen), Mode=OneWay}">
                <controls:AdvancedItemsView.ItemTemplate>
                    <DataTemplate x:DataType="controls:IllustrationItemViewModel">
                        <ItemContainer Width="80" Height="80">
                            <controls:LazyImage
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                DataContext="{x:Bind}"
                                DataContextChanged="FrameworkElement_OnDataContextChanged"
                                Source="{x:Bind ThumbnailSource, Mode=OneWay}" />
                        </ItemContainer>
                    </DataTemplate>
                </controls:AdvancedItemsView.ItemTemplate>
                <controls:AdvancedItemsView.ItemTransitionProvider>
                    <LinedFlowLayoutItemCollectionTransitionProvider />
                </controls:AdvancedItemsView.ItemTransitionProvider>
            </controls:AdvancedItemsView>
            <Grid
                Grid.Row="3"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="{ThemeResource SolidBackgroundFillColorTertiaryBrush}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" MaxWidth="310" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <CommandBar
                    Grid.Column="0"
                    HorizontalAlignment="Stretch"
                    DefaultLabelPosition="Collapsed">
                    <AppBarToggleButton Command="{x:Bind _viewModel.InfoAndCommentsCommand}" IsChecked="{x:Bind EntryViewerSplitView.IsPaneOpen, Mode=TwoWay}" />
                    <AppBarToggleButton Command="{x:Bind _viewModel.BottomListCommand}" IsChecked="{x:Bind _viewModel.IsBottomListOpen, Mode=TwoWay}" />
                    <AppBarSeparator />
                    <controls:AppBarTextItem
                        Padding="15,0"
                        Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
                        Symbol="SlideGrid"
                        Text="{x:Bind _viewModel.CurrentIllustration.SizeText, Mode=OneWay}" />
                    <AppBarSeparator />
                    <controls:AppBarTextItem
                        Padding="15,0"
                        Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
                        Symbol="AppTitle"
                        Text="{x:Bind _viewModel.CurrentIllustration.Title, Mode=OneWay}" />
                </CommandBar>
                <CommandBar
                    x:Name="ExtensionsCommandBar"
                    Grid.Column="2"
                    HorizontalAlignment="Stretch"
                    DefaultLabelPosition="Collapsed"
                    Visibility="{x:Bind controls:C.ToVisibilityNegation(_viewModel.CurrentIllustration.IsUgoira), Mode=OneWay}" />
                <CommandBar
                    Grid.Column="3"
                    HorizontalAlignment="Stretch"
                    DefaultLabelPosition="Collapsed">
                    <AppBarElementContainer VerticalContentAlignment="Center">
                        <TextBlock Style="{StaticResource ViewerTextBlockStyle}" Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}">
                            <Run Text="{x:Bind controls:C.PlusOneToString(_viewModel.CurrentPageIndex), Mode=OneWay}" />
                            <Run Text="/" />
                            <Run Text="{x:Bind _viewModel.PageCount, Mode=OneWay}" />
                        </TextBlock>
                    </AppBarElementContainer>
                    <AppBarSeparator Visibility="{x:Bind controls:C.ToVisibility(_viewModel.CurrentIllustration.IsManga), Mode=OneWay}" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.RestoreResolutionCommand, Mode=OneWay}" IsCompact="True" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.ZoomOutCommand, Mode=OneWay}" IsCompact="True" />
                    <AppBarButton Command="{x:Bind _viewModel.CurrentImage.ZoomInCommand, Mode=OneWay}" IsCompact="True" />
                    <AppBarSeparator />
                    <AppBarElementContainer VerticalContentAlignment="Center">
                        <TextBlock
                            MinWidth="60"
                            Style="{StaticResource ViewerTextBlockStyle}"
                            Text="{x:Bind controls:C.ToPercentageString(_viewModel.CurrentImage.Scale, 2), Mode=OneWay}" />
                    </AppBarElementContainer>
                </CommandBar>
            </Grid>
        </Grid>
        <TeachingTip
            x:Name="ShowQrCodeTeachingTip"
            x:Uid="/EntryViewerPage/QrCodeTeachingTip"
            IsLightDismissEnabled="True"
            Tag="{x:Bind ShowQrCodeButton}">
            <TeachingTip.HeroContent>
                <Image Loading="Content_OnLoading" Tag="{x:Bind ShowQrCodeTeachingTip}" />
            </TeachingTip.HeroContent>
        </TeachingTip>
        <TeachingTip
            x:Name="AddToBookmarkTeachingTip"
            x:Uid="/EntryViewerPage/AddToBookmarkTeachingTip"
            CloseButtonClick="AddToBookmarkTeachingTip_OnCloseButtonClick"
            IsLightDismissEnabled="True"
            Tag="{x:Bind AddToBookmarkButton}">
            <flyoutContent:BookmarkTagSelector
                x:Name="BookmarkTagSelector"
                MaxHeight="{StaticResource TeachingTipContentMaxHeightWithTarget}"
                Loading="Content_OnLoading"
                Tag="{x:Bind AddToBookmarkTeachingTip}"
                Type="IllustAndManga" />
        </TeachingTip>
    </Grid>
</controls:EnhancedPage>
