<ui:Page xmlns:props="clr-namespace:Ink_Canvas.Properties" x:Class="Ink_Canvas.Windows.SettingsViews.Pages.UpdatePage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews.Pages"
      xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
      xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:controls="clr-namespace:Ink_Canvas.Controls;assembly=InkCanvas.Controls"
      xmlns:c="clr-namespace:Ink_Canvas.Converter"
      xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
      mc:Ignorable="d"
      Title="{x:Static props:NotificationStrings.Type_Update}">

    <ScrollViewer PanningMode="VerticalFirst">
        <Grid Margin="59,0,59,0">
            <FrameworkElement.Resources>
                <sys:Double x:Key="SettingsCardSpacing">4</sys:Double>
                <c:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
                <Style x:Key="SettingsSectionHeaderTextBlockStyle"
                       BasedOn="{StaticResource BodyStrongTextBlockStyle}"
                       TargetType="TextBlock">
                    <Setter Property="Margin" Value="1,30,0,6" />
                </Style>
            </FrameworkElement.Resources>

            <ikw:SimpleStackPanel MaxWidth="1000"
                                  HorizontalAlignment="Stretch"
                                  Spacing="{StaticResource SettingsCardSpacing}">

                <!-- 状态横幅 -->
                <Border Margin="0,16,0,0">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Grid Grid.Column="0"
                              Width="48" Height="48"
                              VerticalAlignment="Top"
                              Margin="0,0,16,0">
                            <Ellipse Fill="{DynamicResource SystemControlHighlightAccentBrush}" />
                            <Grid x:Name="CompletedStatusGlyph"
                                  Width="22" Height="22"
                                  HorizontalAlignment="Center" VerticalAlignment="Center">
                                <Ellipse Stroke="White" StrokeThickness="2" />
                                <Path Data="M 5,11 L 9,15 L 17,7"
                                      Stroke="White"
                                      StrokeThickness="2"
                                      StrokeStartLineCap="Round"
                                      StrokeEndLineCap="Round"
                                      StrokeLineJoin="Round" />
                            </Grid>
                            <ui:FontIcon x:Name="StatusIcon"
                                         FontSize="22"
                                         Foreground="White"
                                         Visibility="Collapsed"
                                         HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>

                        <ikw:SimpleStackPanel Grid.Column="1" Spacing="4">
                            <TextBlock x:Name="StatusTitle"
                                       FontSize="22" FontWeight="SemiBold"
                                       Text="{x:Static props:UpdateStrings.Status_Loading}" />
                            <TextBlock x:Name="StatusSubtitle"
                                       Opacity="0.75"
                                       TextWrapping="Wrap"
                                       Text="" />

                            <!-- 进度区 -->
                            <ikw:SimpleStackPanel x:Name="ProgressPanel"
                                                  Visibility="Collapsed"
                                                  Margin="0,8,0,0"
                                                  Spacing="4">
                                <TextBlock x:Name="ProgressText" FontSize="13" Opacity="0.8" />
                                <ProgressBar x:Name="ProgressBar"
                                             Style="{DynamicResource DefaultProgressBarStyle}"
                                             Height="6"
                                             Minimum="0" Maximum="100"
                                             Value="0" />
                            </ikw:SimpleStackPanel>

                            <!-- 操作按钮 -->
                            <ikw:SimpleStackPanel Orientation="Horizontal"
                                                  Margin="0,12,0,0"
                                                  Spacing="8">
                                <Button x:Name="CheckUpdateButton"
                                        Style="{DynamicResource AccentButtonStyle}"
                                        Click="CheckUpdateButton_Click">
                                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Refresh}" FontSize="14" />
                                        <TextBlock Text="{x:Static props:UpdateStrings.Btn_CheckUpdate}" />
                                    </ikw:SimpleStackPanel>
                                </Button>
                                <Button x:Name="UpdateNowButton"
                                        Visibility="Collapsed"
                                        Style="{DynamicResource AccentButtonStyle}"
                                        Click="UpdateNowButton_Click">
                                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Download}" FontSize="14" />
                                        <TextBlock Text="{x:Static props:UpdateStrings.Btn_DownloadAndInstall}" />
                                    </ikw:SimpleStackPanel>
                                </Button>
                                <Button x:Name="UpdateLaterButton"
                                        Visibility="Collapsed"
                                        Click="UpdateLaterButton_Click">
                                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.QuietHours}" FontSize="14" />
                                        <TextBlock Text="{x:Static props:UpdateStrings.Btn_InstallOnExit}" />
                                    </ikw:SimpleStackPanel>
                                </Button>
                                <Button x:Name="SkipVersionButton"
                                        Visibility="Collapsed"
                                        Click="SkipVersionButton_Click">
                                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Cancel}" FontSize="14" />
                                        <TextBlock Text="{x:Static props:UpdateStrings.Btn_SkipVersion}" />
                                    </ikw:SimpleStackPanel>
                                </Button>
                                <Button x:Name="CancelDownloadButton"
                                        Visibility="Collapsed"
                                        Click="CancelDownloadButton_Click">
                                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Cancel}" FontSize="14" />
                                        <TextBlock Text="{x:Static props:CommonStrings.Common_Cancel}" />
                                    </ikw:SimpleStackPanel>
                                </Button>
                            </ikw:SimpleStackPanel>
                        </ikw:SimpleStackPanel>
                    </Grid>
                </Border>

                <!-- Tab 切换 -->
                <TabControl x:Name="UpdateTabControl"
                            Margin="0,16,0,0"
                            HorizontalContentAlignment="Left"
                            Style="{StaticResource TabControlPivotStyle}"
                            BorderThickness="0"
                            Background="Transparent"
                            SelectionChanged="UpdateTabControl_SelectionChanged">
                    <TabControl.Resources>
                        <sys:Double x:Key="PivotHeaderItemFontSize">16</sys:Double>
                    </TabControl.Resources>
                    <!-- 更新日志 -->
                    <TabItem Header="{x:Static props:UpdateStrings.Tab_Changelog}">
                        <Border Margin="0,8,0,0"
                                Padding="16"
                                CornerRadius="8"
                                MinHeight="200"
                                Background="{DynamicResource LayerFillColorDefaultBrush}">
                            <ScrollViewer VerticalScrollBarVisibility="Auto"
                                          HorizontalScrollBarVisibility="Disabled"
                                          PanningMode="VerticalOnly"
                                          MaxHeight="500">
                                <mdxam:MarkdownScrollViewer x:Name="ChangelogViewer"
                                                            MarkdownStyleName="GithubLike" />
                            </ScrollViewer>
                        </Border>
                    </TabItem>

                    <!-- 更新设置 -->
                    <TabItem Header="{x:Static props:UpdateStrings.Tab_UpdateSettings}">
                        <ikw:SimpleStackPanel Margin="0,8,0,0"
                                              Spacing="{StaticResource SettingsCardSpacing}">
                            <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                                       Text="{x:Static props:StorageStrings.Storage_Legend_Update}" />

                            <controls:LabeledSettingsCard x:Name="CardAutoUpdate"
                                                          Header="{x:Static props:UpdateStrings.Header_AutoUpdate}"
                                                          Description="{x:Static props:StartupStrings.AutoUpdateHint}"
                                                          Icon="{x:Static ui:SegoeFluentIcons.Sync}"
                                                          SwitchName="ToggleSwitchIsAutoUpdate"
                                                          Toggled="ToggleSwitchIsAutoUpdate_Toggled" />

                            <controls:LabeledSettingsCard x:Name="CardSilentUpdate"
                                                          Header="{x:Static props:UpdateStrings.Header_SilentUpdate}"
                                                          Description="{x:Static props:StartupStrings.SilentUpdateHint}"
                                                          Icon="{x:Static ui:SegoeFluentIcons.QuietHours}"
                                                          SwitchName="ToggleSwitchIsAutoUpdateWithSilence"
                                                          ShowWhen="{Binding IsOn, ElementName=CardAutoUpdate}"
                                                          d:Visibility="Visible"
                                                          Toggled="ToggleSwitchIsAutoUpdateWithSilence_Toggled" />

                            <controls:LabeledSettingsCard x:Name="CardSmartUpdate"
                                                          Header="{x:Static props:StartupStrings.SmartUpdate}"
                                                          Description="{x:Static props:StartupStrings.SmartUpdateHint}"
                                                          Icon="{x:Static ui:SegoeFluentIcons.CloudDownload}"
                                                          SwitchName="ToggleSwitchIsSmartUpdate"
                                                          Toggled="ToggleSwitchIsSmartUpdate_Toggled" />

                            <ui:SettingsExpander x:Name="ExpanderSilentUpdateTime"
                                                 Header="{x:Static props:StartupStrings.SilentUpdate_TimeRange}"
                                                 Visibility="{Binding IsOn, ElementName=CardSilentUpdate, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                 IsExpanded="{Binding IsOn, ElementName=CardSilentUpdate, Mode=OneWay}"
                                                 d:Visibility="Visible" d:IsExpanded="True">
                                <ui:SettingsExpander.HeaderIcon>
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Settings}" />
                                </ui:SettingsExpander.HeaderIcon>
                                <ui:SettingsExpander.Items>
                                    <ui:SettingsCard Header="{x:Static props:UpdateStrings.SilentUpdate_TimeRangeSettings}"
                                                     Description="{x:Static props:StartupStrings.SilentUpdateFullHint}">
                                        <ui:SettingsCard.Content>
                                            <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="12">
                                                <ikw:SimpleStackPanel Orientation="Horizontal">
                                                    <TextBlock Margin="0,0,10,0" VerticalAlignment="Center"
                                                               Text="{x:Static props:CommonStrings.Time_Start}" FontSize="14" />
                                                    <ComboBox x:Name="AutoUpdateWithSilenceStartTimeComboBox"
                                                              SelectionChanged="AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged" />
                                                </ikw:SimpleStackPanel>
                                                <ikw:SimpleStackPanel Orientation="Horizontal">
                                                    <TextBlock Margin="0,0,10,0" VerticalAlignment="Center"
                                                               Text="{x:Static props:CommonStrings.Time_End}" FontSize="14" />
                                                    <ComboBox x:Name="AutoUpdateWithSilenceEndTimeComboBox"
                                                              SelectionChanged="AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged" />
                                                </ikw:SimpleStackPanel>
                                            </ikw:SimpleStackPanel>
                                        </ui:SettingsCard.Content>
                                    </ui:SettingsCard>
                                    <ui:SettingsCard Header="{x:Static props:StartupStrings.TimePeriodHint}" />
                                </ui:SettingsExpander.Items>
                            </ui:SettingsExpander>

                            <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                                       Text="{x:Static props:UpdateStrings.Update_Channel}" />

                            <ui:SettingsCard Header="{x:Static props:UpdateStrings.Update_Channel}"
                                             Description="{x:Static props:StartupStrings.UpdateChannelHint}">
                                <ui:SettingsCard.HeaderIcon>
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.SyncFolder}" />
                                </ui:SettingsCard.HeaderIcon>
                                <ComboBox x:Name="UpdateChannelSelector"
                                          SelectionChanged="UpdateChannelSelector_SelectionChanged">
                                    <ComboBoxItem Content="{x:Static props:UpdateStrings.Update_Release}" Tag="Release" />
                                    <ComboBoxItem Content="{x:Static props:UpdateStrings.Update_Preview}" Tag="Preview" />
                                    <ComboBoxItem Content="{x:Static props:UpdateStrings.Update_Beta}" Tag="Beta" />
                                </ComboBox>
                            </ui:SettingsCard>

                            <ui:SettingsCard Header="{x:Static props:StartupStrings.UpdatePackageArchitecture}"
                                             Description="{x:Static props:StartupStrings.UpdatePackageArchitectureHint}">
                                <ui:SettingsCard.HeaderIcon>
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.DeveloperTools}" />
                                </ui:SettingsCard.HeaderIcon>
                                <ComboBox x:Name="UpdatePackageArchitectureSelector"
                                          SelectionChanged="UpdatePackageArchitectureSelector_SelectionChanged">
                                    <ComboBoxItem Content="{x:Static props:UpdateStrings.Update_PackageArch_X86}" Tag="X86" />
                                    <ComboBoxItem Content="{x:Static props:UpdateStrings.Update_PackageArch_X64}" Tag="X64" />
                                </ComboBox>
                            </ui:SettingsCard>

                            <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                                       Text="{x:Static props:UpdateStrings.Section_Maintenance}" />

                            <ui:SettingsCard Header="{x:Static props:BtnStrings.VersionFix}"
                                             Description="{x:Static props:StartupStrings.FixVersionHint}">
                                <ui:SettingsCard.HeaderIcon>
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Repair}" />
                                </ui:SettingsCard.HeaderIcon>
                                <Button x:Name="FixVersionButton" Content="{x:Static props:BtnStrings.VersionFix}"
                                        Click="FixVersionButton_Click" />
                            </ui:SettingsCard>
                        </ikw:SimpleStackPanel>
                    </TabItem>

                    <!-- 历史版本 -->
                    <TabItem x:Name="HistoryTabItem" Header="{x:Static props:UpdateStrings.Tab_HistoryVersions}">
                        <ikw:SimpleStackPanel Margin="0,8,0,0" Spacing="12">
                            <ui:SettingsCard Header="{x:Static props:UpdateStrings.History_SelectVersion}"
                                             Description="{x:Static props:UpdateStrings.History_SelectVersionDesc}">
                                <ui:SettingsCard.HeaderIcon>
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.History}" />
                                </ui:SettingsCard.HeaderIcon>
                                <ComboBox x:Name="VersionComboBox"
                                          DisplayMemberPath="Version"
                                          SelectionChanged="VersionComboBox_SelectionChanged" />
                            </ui:SettingsCard>

                            <Border Padding="16"
                                    CornerRadius="8"
                                    MinHeight="200"
                                    Background="{DynamicResource LayerFillColorDefaultBrush}">
                                <ScrollViewer x:Name="ReleaseNotesScrollViewer"
                                              VerticalScrollBarVisibility="Auto"
                                              HorizontalScrollBarVisibility="Disabled"
                                              PanningMode="VerticalOnly"
                                              MaxHeight="350">
                                    <mdxam:MarkdownScrollViewer x:Name="ReleaseNotesViewer"
                                                                MarkdownStyleName="GithubLike"
                                                                IsHitTestVisible="False" />
                                </ScrollViewer>
                            </Border>

                            <Button x:Name="RollbackButton"
                                    HorizontalAlignment="Left"
                                    IsEnabled="False"
                                    Style="{DynamicResource AccentButtonStyle}"
                                    Click="RollbackButton_Click">
                                <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
                                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Undo}" FontSize="14" />
                                    <TextBlock Text="{x:Static props:UpdateStrings.Btn_RollbackToVersion}" />
                                </ikw:SimpleStackPanel>
                            </Button>

                            <Border x:Name="RollbackProgressPanel"
                                    Visibility="Collapsed"
                                    Padding="12"
                                    CornerRadius="8"
                                    Background="{DynamicResource LayerFillColorDefaultBrush}"
                                    BorderBrush="{DynamicResource SettingsPageBorderBrush}"
                                    BorderThickness="1">
                                <ikw:SimpleStackPanel Spacing="6">
                                    <TextBlock x:Name="RollbackProgressText" Text="{x:Static props:UpdateStrings.Progress_PreparingDownload}" FontSize="13" />
                                    <ProgressBar x:Name="RollbackProgressBar"
                                                 Style="{DynamicResource DefaultProgressBarStyle}"
                                                 Height="6"
                                                 Minimum="0" Maximum="100" Value="0" />
                                </ikw:SimpleStackPanel>
                            </Border>
                        </ikw:SimpleStackPanel>
                    </TabItem>
                </TabControl>

                <Rectangle Height="48" />

            </ikw:SimpleStackPanel>
        </Grid>
    </ScrollViewer>
</ui:Page>
