<UserControl x:Class="HistoryView.Views.Regions.SettingSubs.OtherSettings"
             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:HistoryView.Views.Regions.SettingSubs"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True" 
             xmlns:Inputs="clr-namespace:HistoryView.Controls.Input"
             xmlns:conterter="clr-namespace:HistoryView.Converters"

             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <conterter:RunningModeToBool x:Key="StateConvert"/>
        <conterter:SizeConvert x:Key="Size"/>
        <conterter:AuthorityToVis x:Key="Authority"/>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="32"/>
        </Grid.RowDefinitions>
        <GroupBox Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Operator}" Margin="0,0,0,32">
            <GroupBox.Header>
                <TextBlock FontSize="14" FontWeight="Bold" Text="重置全部链接"/>
            </GroupBox.Header>
            <Button Style="{StaticResource FunctionButton}" Command="{Binding SwitchDataBaseCommand}" CommandParameter="Reset" Margin="16" HorizontalAlignment="Left" Height="32" Content="重置" Width="120"/>
        </GroupBox>

        <GroupBox Grid.Row="2" Margin="0,0,0,32">
            <GroupBox.Header>
                <TextBlock FontSize="14" FontWeight="Bold" Text="数据库"/>
            </GroupBox.Header>
            <Grid Margin="16">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="32"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="64"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="16"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="16"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center">历史保留时间:</TextBlock>
                <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal">
                    <Inputs:NumberKeyboard Text="{Binding DatabaseCleaner.KeepRange, Mode=TwoWay}">
                        <Inputs:NumberKeyboard.DisplayContent>
                            <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  
                                Text="{Binding DatabaseCleaner.KeepRange, Mode=TwoWay}"/>
                        </Inputs:NumberKeyboard.DisplayContent>
                    </Inputs:NumberKeyboard>
                    <TextBlock Margin="4,0" VerticalAlignment="Center" HorizontalAlignment="Center">天</TextBlock>
                </StackPanel>

                <Button Grid.Row="0" Grid.Column="4" Height="32" Width="120" 
                      Style="{StaticResource FunctionButton}" 
                      Command="{Binding SwitchDataBaseCommand}" CommandParameter="Range" Content="{DynamicResource Save}"/>

                <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left">上次检查时间:</TextBlock>
                <TextBlock Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding DatabaseCleaner.LastCheckDate, StringFormat=yyyy/MM/dd HH:mm:ss}"/>
                <Button Grid.Row="2" Grid.Column="4" Height="32" Width="120" 
                            Style="{StaticResource FunctionButton}" 
                            Command="{Binding SwitchDataBaseCommand}" CommandParameter="Delete" Content="手动检查"/>
                <Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" VerticalAlignment="Center" HorizontalAlignment="Left" Height="32" Width="120"                             
                            Style="{StaticResource FunctionButton}" 
                            Background="{StaticResource WarningColor}"
                            Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Engineer}" 
                            Command="{Binding SwitchDataBaseCommand}" CommandParameter="SwitchDataBase" Content="切换至新数据库"/>
            </Grid>
        </GroupBox>

        <GroupBox Grid.Row="4"  Margin="0,0,0,32">
            <GroupBox.Header>
                <TextBlock FontSize="14" FontWeight="Bold" Text="{DynamicResource MonitorSelection}"/>
            </GroupBox.Header>

            <ItemsControl ItemsSource="{Binding Monitor.Monitors}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <RadioButton GroupName="1" Style="{StaticResource ThemeRadioButton}" Margin="8" VerticalAlignment="Top" HorizontalAlignment="Center"
                                     Command="{Binding RelativeSource={RelativeSource AncestorType=local:OtherSettings, Mode=FindAncestor}, Path=DataContext.DisplaySelectCommand}"
                                     CommandParameter="{Binding Key}" >
                            <Grid Width="{Binding Value.ResolutionHorizontal, Mode=OneWay, Converter={StaticResource Size}, ConverterParameter=16}" Height="{Binding Value.ResolutionVertical, Mode=OneWay, Converter={StaticResource Size}, ConverterParameter=16}">
                                <TextBlock Text="{Binding Value.ResolutionHorizontal, Mode=OneWay}" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="{StaticResource TextColor}"/>
                                <TextBlock Text="{Binding Value.ResolutionVertical, Mode=OneWay}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource TextColor}">
                                    <TextBlock.LayoutTransform>
                                        <RotateTransform Angle="270"></RotateTransform>
                                    </TextBlock.LayoutTransform>
                                </TextBlock>
                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16" Foreground="{StaticResource TextColor}">
                                <!--<Run>Display</Run>-->
                                <Run Text="{Binding Key, Mode=OneWay}"/>
                                </TextBlock>
                            </Grid>
                        </RadioButton>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

        </GroupBox>
    </Grid>

</UserControl>
