<?xml version="1.0" encoding="utf-8" ?>
<local:StartupPageBase
    x:Class="BiliCopilot.UI.Pages.StartupPage"
    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.WinUIKernel.Share.Base"
    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">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Background="{ThemeResource LayerFillColorDefaultBrush}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <StackPanel VerticalAlignment="Center" Spacing="8">
                <Image Width="148" Source="ms-appx:///Assets/StoreLogo.png" />
                <TextBlock
                    HorizontalAlignment="Center"
                    FontSize="20"
                    Style="{StaticResource BodyStrongTextBlockStyle}"
                    Text="{ext:Locale Name=AppName}" />
                <TextBlock
                    HorizontalAlignment="Center"
                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=AppDescription}"
                    TextWrapping="Wrap" />
                <HyperlinkButton
                    HorizontalAlignment="Center"
                    Click="OnWebSignInButtonClick"
                    Content="{ext:Locale Name=WebSignIn}" />
            </StackPanel>
            <Border
                Grid.Column="1"
                Width="1"
                Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
            <StackPanel
                Grid.Column="2"
                VerticalAlignment="Center"
                Spacing="12">
                <TextBlock
                    x:Name="TipBlock"
                    HorizontalAlignment="Center"
                    Foreground="{ThemeResource TextFillColorDisabledBrush}"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=QRLoginTip}"
                    TextWrapping="Wrap" />
                <Grid
                    x:Name="QRLoginContainer"
                    Width="220"
                    HorizontalAlignment="Center"
                    RowSpacing="12">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid CornerRadius="{StaticResource ControlCornerRadius}">
                        <Image
                            x:Name="QRCodeImage"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Stretch="Uniform"
                            Visibility="{x:Bind ViewModel.IsQRCodeLoading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                            <animations:Implicit.ShowAnimations>
                                <animations:OpacityAnimation
                                    From="0.0"
                                    To="1.0"
                                    Duration="0:0:0.4" />
                            </animations:Implicit.ShowAnimations>
                            <animations:Implicit.HideAnimations>
                                <animations:OpacityAnimation
                                    From="1.0"
                                    To="0.0"
                                    Duration="0:0:0.4" />
                            </animations:Implicit.HideAnimations>
                        </Image>
                    </Grid>
                    <Grid
                        x:Name="QRMaskContainer"
                        Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
                        CornerRadius="{ThemeResource ControlCornerRadius}"
                        Visibility="{x:Bind ViewModel.ErrorTip, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                            <TextBlock
                                x:Name="QRTipBlock"
                                MaxWidth="200"
                                HorizontalAlignment="Center"
                                Style="{StaticResource BodyTextBlockStyle}"
                                TextAlignment="Center"
                                TextWrapping="Wrap" />
                        </StackPanel>
                        <animations:Implicit.ShowAnimations>
                            <animations:OpacityAnimation
                                From="0.0"
                                To="1.0"
                                Duration="0:0:0.4" />
                        </animations:Implicit.ShowAnimations>
                        <animations:Implicit.HideAnimations>
                            <animations:OpacityAnimation
                                From="1.0"
                                To="0.0"
                                Duration="0:0:0.4" />
                        </animations:Implicit.HideAnimations>
                    </Grid>

                    <base:Shimmer
                        x:Name="QRLoadingShimmer"
                        Width="220"
                        Height="220"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"
                        CornerRadius="{StaticResource ControlCornerRadius}"
                        IsActive="{x:Bind ViewModel.IsQRCodeLoading, Mode=OneWay}" />
                    <HyperlinkButton
                        x:Name="RefreshQRButton"
                        Grid.Row="1"
                        HorizontalAlignment="Stretch"
                        Click="OnRefreshQRButtonClick"
                        Content="{ext:Locale Name=Refresh}"
                        IsEnabled="{x:Bind ViewModel.IsQRCodeLoading, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" />
                </Grid>
            </StackPanel>
        </Grid>

        <Grid
            Grid.Row="1"
            Padding="28,16"
            BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
            BorderThickness="0,1,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                Style="{StaticResource CaptionTextBlockStyle}">
                <Run Text="{ext:Locale Name=Version}" />
                <Run Text=":" />
                <Run Text="{x:Bind ViewModel.Version, Mode=OneWay}" />
            </TextBlock>
            <StackPanel
                Grid.Column="1"
                Margin="0,0,8,0"
                Padding="0,0,8,0"
                HorizontalAlignment="Center"
                BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
                BorderThickness="0,0,1,0"
                Orientation="Horizontal"
                Spacing="4">
                <Button
                    BorderThickness="1"
                    Click="OnRepoButtonClickAsync"
                    Style="{StaticResource IconButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=ProjectHomePage}">
                    <ic:SymbolIcon
                        FontSize="14"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        Symbol="BranchFork" />
                </Button>
                <Button
                    BorderThickness="1"
                    Click="OnBiliButtonClickAsync"
                    Style="{StaticResource IconButtonStyle}"
                    ToolTipService.ToolTip="{ext:Locale Name=BiliHomePage}">
                    <ic:SymbolIcon
                        FontSize="14"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        Symbol="Tv" />
                </Button>
            </StackPanel>
            <HyperlinkButton
                Grid.Column="2"
                HorizontalAlignment="Right"
                VerticalAlignment="Stretch"
                NavigateUri="https://bili.richasy.net">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <ic:SymbolIcon
                        VerticalAlignment="Center"
                        FontSize="14"
                        Symbol="Book" />
                    <TextBlock
                        VerticalAlignment="Center"
                        FontSize="12"
                        Text="{ext:Locale Name=ReadDocument}" />
                </StackPanel>
            </HyperlinkButton>
        </Grid>
    </Grid>
</local:StartupPageBase>
