<Page x:Class="XFEToolBox.Client.Views.Pages.SettingPage"
      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:pages="clr-namespace:XFEToolBox.Client.ViewModel.Pages"
      xmlns:controls="clr-namespace:XFEToolBox.WpfCore.Controls;assembly=XFEToolBox.WpfCore"
      mc:Ignorable="d"
      d:DesignHeight="450" d:DesignWidth="800"
      Title="SettingPage" d:DataContext="{d:DesignInstance Type=pages:SettingPageViewModel}"
      Loaded="Page_Loaded">

    <controls:RoundedClipBorder Background="{DynamicResource BackgroundColor}" CornerRadius="15" Margin="15,5,15,15">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="5*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="33"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Border Grid.Column="1" Background="{DynamicResource BackgroundColor}">
                <Grid>
                    <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" VerticalAlignment="Center">
                        <StackPanel x:Name="tabUnderLinePanel" Orientation="Horizontal">
                            <controls:TabUnderLineButton x:Name="generalTabUnderLineButton" Margin="0,0,10,0" Tag="general" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
                                <TextBlock Text="常规" Style="{StaticResource TabUnderLineText}"/>
                            </controls:TabUnderLineButton>
                            <controls:TabUnderLineButton Tag="console" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
                                <TextBlock Text="控制台" Style="{StaticResource TabUnderLineText}"/>
                            </controls:TabUnderLineButton>
                            <controls:TabUnderLineButton Tag="download" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
                                <TextBlock Text="下载" Style="{StaticResource TabUnderLineText}"/>
                            </controls:TabUnderLineButton>
                            <controls:TabUnderLineButton Tag="performance" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
                                <TextBlock Text="性能" Style="{StaticResource TabUnderLineText}"/>
                            </controls:TabUnderLineButton>
                        </StackPanel>
                    </ScrollViewer>
                    <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1"/>
                </Grid>
            </Border>

            <controls:SmoothScrollViewer x:Name="scrollViewer" Grid.Row="1" Grid.ColumnSpan="3"
                                         VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled"
                                         ScrollChanged="ScrollViewer_ScrollChanged">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel Grid.Column="1">
                        <Grid Margin="0,20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="generalSettingBlock" VerticalAlignment="Center" Text="常规" Style="{StaticResource TabUnderLineText}"/>
                            <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" Height="1" Tag="常规"/>
                            <StackPanel Grid.Row="1" Margin="0,6,0,0">
                                <controls:SettingsCard Header="开机自启动" Description="登录 Windows 后自动启动工具箱">
                                    <controls:SwitchButton x:Name="autoSelfLaunchSwitch" Margin="0"
                                                           Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.AutoSelfLaunch"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="最大化窗口启动" Description="启动工具箱时直接最大化主窗口">
                                    <controls:SwitchButton x:Name="startWithMaximize" Margin="0"
                                                           Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.StartWithMaximize"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="关闭到托盘" Description="关闭主窗口后继续响应全局快捷键和后台任务">
                                    <controls:SwitchButton Margin="0"
                                                           Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.CloseToTray"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="聊天单栏模式" Description="进入聊天时先显示会话列表，选择后再显示聊天内容；默认关闭">
                                    <controls:SwitchButton Margin="0"
                                                           Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.ChatSinglePaneMode"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="命令面板快捷键" Description="{Binding GlobalHotkeyStatus}">
                                    <StackPanel Orientation="Horizontal">
                                        <controls:SwitchButton Margin="0,0,12,0"
                                                               VerticalAlignment="Center"
                                                               Command="{Binding SwitchedCommand}"
                                                               CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                               Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.LauncherHotkeyEnabled"/>
                                        <controls:TextEditor Width="150" Height="34" Margin="0,0,8,0"
                                                             Text="{Binding LauncherHotkeyText, UpdateSourceTrigger=PropertyChanged}"
                                                             HintText="Ctrl+Alt+Space"/>
                                        <Button Content="应用" MinWidth="62" Command="{Binding ApplyLauncherHotkeyCommand}"/>
                                    </StackPanel>
                                </controls:SettingsCard>
                                <controls:SettingsExpander Header="软件更新" Description="{Binding UpgradeStatus}" IsExpanded="True">
                                    <controls:SettingsExpander.Content>
                                        <Button Content="检查更新" MinWidth="96"
                                                controls:ButtonAssist.IsPrimary="True"
                                                Command="{Binding CheckUpgradeCommand}"/>
                                    </controls:SettingsExpander.Content>
                                    <controls:SettingsCard Header="当前版本" Description="升级服务中的应用名为 XFEToolBox">
                                        <TextBlock Text="{Binding CurrentApplicationVersion}" VerticalAlignment="Center"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="启动时自动检查" Description="主窗口加载完成后在后台检测新版本">
                                        <controls:SwitchButton Margin="0"
                                                               Command="{Binding SwitchedCommand}"
                                                               CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                               Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.SystemProfile.CheckForUpdatesOnStartup"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="忽略的版本" Description="手动检查不会跳过被忽略的版本">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding IgnoredUpgradeVersionDisplay}" Margin="0,0,12,0" VerticalAlignment="Center"/>
                                            <Button Content="清除" Command="{Binding ClearIgnoredUpgradeVersionCommand}"/>
                                        </StackPanel>
                                    </controls:SettingsCard>
                                </controls:SettingsExpander>
                            </StackPanel>
                        </Grid>

                        <Grid Margin="0,20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="consoleSettingBlock" VerticalAlignment="Center" Text="控制台" Style="{StaticResource TabUnderLineText}"/>
                            <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" Height="1"/>
                            <StackPanel Grid.Row="1" Margin="0,6,0,0">
                                <controls:SettingsExpander Header="远程调试模式"
                                                           Description="由工具箱主动连接调试程序服务器"
                                                           IsHeaderClickEnabled="False"
                                                           IsExpanded="{Binding IsChecked, ElementName=remoteDebugModeSwitch, Mode=OneWay}">
                                    <controls:SettingsExpander.Content>
                                        <controls:SwitchButton x:Name="remoteDebugModeSwitch" Margin="0"
                                                               Command="{Binding SwitchedCommand}"
                                                               CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                               Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.ConnectToRemoteServer"/>
                                    </controls:SettingsExpander.Content>
                                    <controls:SettingsCard Header="远程服务器地址" Description="支持 ws:// 与 wss:// 地址">
                                        <controls:TextEditor Height="38" Width="260" Margin="0" Padding="10,0"
                                                             HorizontalAlignment="Right" VerticalAlignment="Center"
                                                             CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                             HintText="ws://服务器地址:3280/" TextChanged="TextEditor_TextChanged"
                                                             Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.RemoteServerAddress"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="远程服务器连接密码" Description="必须与调试程序服务器设置的密码一致">
                                        <controls:PasswordEditor Height="38" Width="180" Margin="0" Padding="12,0,4,0"
                                                                 HorizontalAlignment="Right" VerticalAlignment="Center"
                                                                 CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                                 HintText="默认为空" PasswordChanged="PasswordEditor_PasswordChanged"
                                                                 Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.RemoteServerPassword"/>
                                    </controls:SettingsCard>
                                </controls:SettingsExpander>

                                <controls:SettingsCard Header="控制台端口" Description="调试程序连接工具箱时使用的监听端口">
                                    <controls:TextEditor Height="38" Width="88" Margin="0" Padding="10,0"
                                                         HorizontalAlignment="Right" VerticalAlignment="Center"
                                                         CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                         HintText="3280" TextChanged="TextEditor_TextChanged"
                                                         Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePort"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="连接密码" Description="调试程序连接本工具箱监听服务时使用">
                                    <controls:PasswordEditor Height="38" Width="180" Margin="0" Padding="12,0,4,0"
                                                             HorizontalAlignment="Right" VerticalAlignment="Center"
                                                             CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                             HintText="默认为空" PasswordChanged="PasswordEditor_PasswordChanged"
                                                             Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePassword"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="仅本机开放" Description="只允许 localhost 上的调试程序连接">
                                    <controls:SwitchButton Margin="0" Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.LocalHostOnly"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="最大显示行数" Description="设置为 -1 时不限制控制台保留行数">
                                    <controls:TextEditor Height="38" Width="88" Margin="0" Padding="10,0"
                                                         HorizontalAlignment="Right" VerticalAlignment="Center"
                                                         CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                         HintText="8000" TextChanged="TextEditor_TextChanged"
                                                         Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.ConsoleProfile.MaxLine"/>
                                </controls:SettingsCard>
                            </StackPanel>
                        </Grid>

                        <Grid Margin="0,20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="downloadSettingBlock" VerticalAlignment="Center" Text="下载" Style="{StaticResource TabUnderLineText}"/>
                            <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" Height="1" Tag="下载"/>
                            <StackPanel Grid.Row="1" Margin="0,6,0,0">
                                <controls:SettingsCard Header="普通下载模式" Description="禁用多线程加速并使用普通下载方式">
                                    <controls:SwitchButton Margin="0" Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.DownloadProfile.UseNormalDownloader"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="下载目录" Description="{Binding DownloadDirectory}">
                                    <StackPanel Orientation="Horizontal">
                                        <Button Command="{Binding OpenDownloadDirectoryCommand}" Margin="0,0,6,0">
                                            <TextBlock Text="打开目录" Margin="4" Foreground="{DynamicResource MainColor}"/>
                                        </Button>
                                        <Button Command="{Binding ChoiceDownloadDirectoryCommand}">
                                            <TextBlock Text="更改目录" Margin="4" Foreground="{DynamicResource MainColor}"/>
                                        </Button>
                                    </StackPanel>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="加速下载线程数" Description="并行下载时使用的线程数量">
                                    <controls:TextEditor Height="38" Width="64" Margin="0" Padding="10,0"
                                                         HorizontalAlignment="Right" VerticalAlignment="Center"
                                                         CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}"
                                                         HintText="9" TextChanged="TextEditor_TextChanged"
                                                         Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.DownloadProfile.DownloadThread"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="完成后自动运行" Description="下载完成后自动运行 exe 文件">
                                    <controls:SwitchButton Margin="0" Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.DownloadProfile.AutoRunWhenComplete"/>
                                </controls:SettingsCard>
                                <controls:SettingsCard Header="完成后打开目录" Description="下载完成后在资源管理器中打开目标目录">
                                    <controls:SwitchButton Margin="0" Command="{Binding SwitchedCommand}"
                                                           CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"
                                                           Tag="XFEToolBox.Client.Profiles.CrossVersionProfiles.DownloadProfile.OpenFolderWhenComplete"/>
                                </controls:SettingsCard>
                            </StackPanel>
                        </Grid>

                        <Grid Margin="0,20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="performanceSettingBlock" VerticalAlignment="Center" Text="性能" Style="{StaticResource TabUnderLineText}"/>
                            <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" Height="1" Tag="性能"/>
                            <StackPanel Grid.Row="1" Margin="0,6,0,0">
                                <controls:SettingsExpander Header="存储使用" Description="{Binding TotalProfileSize}" IsExpanded="True">
                                    <controls:SettingsCard Header="缓存配置文件" Description="可以安全清理，使用时会按需重新生成">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding CacheProfileSize}" Margin="0,0,10,0" VerticalAlignment="Center"/>
                                            <Button Command="{Binding ClearCacheCommand}">
                                                <TextBlock Text="清理缓存" Margin="5,0" Foreground="{DynamicResource MainColor}"/>
                                            </Button>
                                        </StackPanel>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="跨版本配置文件">
                                        <TextBlock Text="{Binding CrossVersionProfileSize}"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="当前版本配置文件">
                                        <TextBlock Text="{Binding CurrentVersionProfileSize}"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="同步配置文件">
                                        <TextBlock Text="{Binding SynchronizeProfileSize}"/>
                                    </controls:SettingsCard>
                                    <controls:SettingsCard Header="全部配置文件">
                                        <TextBlock Text="{Binding TotalProfileSize}"/>
                                    </controls:SettingsCard>
                                </controls:SettingsExpander>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </Grid>
            </controls:SmoothScrollViewer>
        </Grid>
    </controls:RoundedClipBorder>
</Page>
