<?xml version="1.0" encoding="utf-8" ?>
<local:GalleryPageBase
    x:Class="BiliCopilot.UI.Pages.GalleryPage"
    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:appearance="using:Richasy.BiliKernel.Models.Appearance"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:components="using:BiliCopilot.UI.Controls.Components"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:BiliCopilot.UI.Pages"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <Style
            x:Key="CustomButtonStyle"
            BasedOn="{StaticResource DefaultAppBarButtonStyle}"
            TargetType="AppBarButton">
            <Setter Property="Width" Value="40" />
        </Style>
    </Page.Resources>

    <Grid>
        <Button
            x:Name="NextButton"
            Command="{x:Bind ViewModel.NextImageCommand, Mode=OneWay}"
            Style="{StaticResource HiddenButtonStyle}">
            <Button.KeyboardAccelerators>
                <KeyboardAccelerator Key="Right" IsEnabled="True" />
            </Button.KeyboardAccelerators>
        </Button>
        <Button
            x:Name="PrevButton"
            Command="{x:Bind ViewModel.PreviousImageCommand, Mode=OneWay}"
            IsTabStop="False"
            Style="{StaticResource HiddenButtonStyle}">
            <Button.KeyboardAccelerators>
                <KeyboardAccelerator Key="Left" IsEnabled="True" />
            </Button.KeyboardAccelerators>
        </Button>

        <ScrollView
            x:Name="ImageScrollView"
            HorizontalScrollBarVisibility="Auto"
            HorizontalScrollMode="Enabled"
            MaxZoomFactor="1.5"
            MinZoomFactor="0.2"
            Tapped="OnScrollViewTapped"
            VerticalScrollBarVisibility="Auto"
            VerticalScrollMode="Enabled"
            ViewChanged="OnScrollViewChanged"
            ZoomMode="Enabled">
            <Image x:Name="Image" Source="{x:Bind ViewModel.SelectedImage.SourceUri, Mode=OneWay, Converter={StaticResource BitmapConverter}}" />
        </ScrollView>

        <!--  用于进行图片操作  -->
        <Grid
            x:Name="TopContainer"
            Margin="0,20,0,0"
            HorizontalAlignment="Center"
            VerticalAlignment="Top"
            Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
            BorderBrush="{ThemeResource ControlStrokeColorDefaultBrush}"
            BorderThickness="1"
            CornerRadius="{StaticResource OverlayCornerRadius}"
            Visibility="{x:Bind ViewModel.IsMenuHide, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <CommandBar
                x:Name="TopBar"
                VerticalAlignment="Center"
                DefaultLabelPosition="Collapsed">
                <AppBarButton
                    x:Name="ZoomInButton"
                    Click="OnZoomInButtonClick"
                    Label="{ext:Locale Name=ZoomIn}"
                    Style="{StaticResource CustomButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=ZoomIn}">
                    <AppBarButton.Icon>
                        <ic:SymbolIcon Symbol="ZoomIn" />
                    </AppBarButton.Icon>
                    <AppBarButton.KeyboardAccelerators>
                        <KeyboardAccelerator
                            Key="Add"
                            IsEnabled="True"
                            Modifiers="Control" />
                    </AppBarButton.KeyboardAccelerators>
                </AppBarButton>
                <AppBarElementContainer Padding="12,0" VerticalAlignment="Center">
                    <TextBlock
                        x:Name="FactoryBlock"
                        VerticalAlignment="Center"
                        Style="{StaticResource CaptionTextBlockStyle}" />
                </AppBarElementContainer>
                <AppBarButton
                    x:Name="ZoomOutButton"
                    Click="OnZoomOutButtonClick"
                    Label="{ext:Locale Name=ZoomOut}"
                    Style="{StaticResource CustomButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=ZoomOut}">
                    <AppBarButton.Icon>
                        <ic:SymbolIcon Symbol="ZoomOut" />
                    </AppBarButton.Icon>
                    <AppBarButton.KeyboardAccelerators>
                        <KeyboardAccelerator
                            Key="Subtract"
                            IsEnabled="True"
                            Modifiers="Control" />
                    </AppBarButton.KeyboardAccelerators>
                </AppBarButton>
                <AppBarSeparator />
                <AppBarButton
                    Command="{x:Bind ViewModel.CopyImageCommand, Mode=OneWay}"
                    Label="{ext:Locale Name=CopyToClipboard}"
                    Style="{StaticResource CustomButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=CopyToClipboard}">
                    <AppBarButton.Icon>
                        <ic:SymbolIcon Symbol="Copy" />
                    </AppBarButton.Icon>
                    <AppBarButton.KeyboardAccelerators>
                        <KeyboardAccelerator
                            Key="C"
                            IsEnabled="True"
                            Modifiers="Control" />
                    </AppBarButton.KeyboardAccelerators>
                </AppBarButton>
                <AppBarButton
                    Command="{x:Bind ViewModel.SaveImageCommand, Mode=OneWay}"
                    Label="{ext:Locale Name=SaveTo}"
                    Style="{StaticResource CustomButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=SaveTo}">
                    <AppBarButton.Icon>
                        <ic:SymbolIcon Symbol="Save" />
                    </AppBarButton.Icon>
                    <AppBarButton.KeyboardAccelerators>
                        <KeyboardAccelerator
                            Key="S"
                            IsEnabled="True"
                            Modifiers="Control" />
                    </AppBarButton.KeyboardAccelerators>
                </AppBarButton>

                <CommandBar.SecondaryCommands>
                    <AppBarButton Label="{ext:Locale Name=SettingTo}">
                        <AppBarButton.Flyout>
                            <MenuFlyout>
                                <MenuFlyoutItem Click="OnSettingToBackgroundClickAsync" Text="{ext:Locale Name=SettingToBackground}">
                                    <MenuFlyoutItem.Icon>
                                        <ic:SymbolIcon Symbol="VideoBackgroundEffect" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem Click="OnSettingToLockScreenClickAsync" Text="{ext:Locale Name=SettingToLockScreen}">
                                    <MenuFlyoutItem.Icon>
                                        <ic:SymbolIcon Symbol="LockClosed" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </AppBarButton.Flyout>
                        <AppBarButton.Icon>
                            <ic:SymbolIcon Symbol="ImageArrowForward" />
                        </AppBarButton.Icon>
                    </AppBarButton>
                </CommandBar.SecondaryCommands>
            </CommandBar>

            <animations:Implicit.ShowAnimations>
                <animations:TranslationAnimation
                    From="0,-20"
                    To="0,0"
                    Duration="0:0:0.24" />
                <animations:OpacityAnimation
                    From="0.0"
                    To="1.0"
                    Duration="0:0:0.2" />
            </animations:Implicit.ShowAnimations>
            <animations:Implicit.HideAnimations>
                <animations:TranslationAnimation
                    From="0,0"
                    To="0,-20"
                    Duration="0:0:0.24" />
                <animations:OpacityAnimation
                    From="1.0"
                    To="0.0"
                    Duration="0:0:0.2" />
            </animations:Implicit.HideAnimations>
        </Grid>

        <Grid
            x:Name="ImageListContainer"
            Margin="20,0,20,20"
            Padding="8"
            HorizontalAlignment="Center"
            VerticalAlignment="Bottom"
            Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
            CornerRadius="{StaticResource OverlayCornerRadius}"
            Visibility="{x:Bind ViewModel.IsMenuHide, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <ItemsView
                x:Name="ImageView"
                ItemsSource="{x:Bind ViewModel.Images, Mode=OneWay}"
                SelectionChanged="OnImageSelectionChanged">
                <ItemsView.Layout>
                    <StackLayout Orientation="Horizontal" Spacing="4" />
                </ItemsView.Layout>
                <ItemsView.ItemTemplate>
                    <DataTemplate x:DataType="appearance:BiliImage">
                        <ItemContainer Style="{StaticResource AppItemContainerStyle}">
                            <components:VideoCoverImage
                                Width="100"
                                Height="80"
                                Source="{x:Bind Uri}" />
                        </ItemContainer>
                    </DataTemplate>
                </ItemsView.ItemTemplate>
            </ItemsView>

            <animations:Implicit.ShowAnimations>
                <animations:TranslationAnimation
                    From="0,20"
                    To="0,0"
                    Duration="0:0:0.24" />
                <animations:OpacityAnimation
                    From="0.0"
                    To="1.0"
                    Duration="0:0:0.2" />
            </animations:Implicit.ShowAnimations>
            <animations:Implicit.HideAnimations>
                <animations:TranslationAnimation
                    From="0,0"
                    To="0,20"
                    Duration="0:0:0.24" />
                <animations:OpacityAnimation
                    From="1.0"
                    To="0.0"
                    Duration="0:0:0.2" />
            </animations:Implicit.HideAnimations>
        </Grid>
    </Grid>
</local:GalleryPageBase>
