<UserControl x:Class="HistoryView.Views.Regions.SettingSubs.ConfigFile"
             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:controls="clr-namespace:HistoryView.Controls"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"   
             xmlns:Converter="clr-namespace:HistoryView.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources >
        <Converter:TempConfigSelectorToString x:Key="Selector"/>
        <Converter:DateTimeToString x:Key="Datetime"/>
        <Converter:AuthorityToVis x:Key="Authority"/>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="4"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="0" Margin="4,8">
            <Grid Margin="0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition/>
                    <RowDefinition Height="0"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="0"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="0"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" FontSize="14" FontWeight="Bold" Text="{DynamicResource CurrentConfigFile}" MaxWidth="200" HorizontalAlignment="Left" TextWrapping="WrapWithOverflow"/>

                <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                    <Button  Margin="8" Style="{StaticResource FunctionButton}" Background="Transparent" HorizontalAlignment="Left" TextElement.Foreground="Black" Command="{Binding SelectCurrentCommand}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="8"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="8"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock x:Name="fileType" Panel.ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="2" Foreground="{StaticResource TextColor}">.mc</TextBlock>
                                <Image Source="{StaticResource Icon_File}" VerticalAlignment="Center" Height="28"/>
                                <StackPanel Grid.Column="2" VerticalAlignment="Center">
                                    <TextBlock Text="{Binding TemperatureConfigs.CurrentConfigFile.ConfigFile.ConfigName}" VerticalAlignment="Center" FontSize="12"/>
                                    <TextBlock FontSize="10" VerticalAlignment="Center" Foreground="{StaticResource TextDarkColor}" Text="{Binding TemperatureConfigs.CurrentConfigFile.ConfigFile.EditTime, Converter={StaticResource Datetime}, ConverterParameter=default}">
                                    </TextBlock>
                                </StackPanel>
                            </Grid>

                            <Grid Grid.Row="2">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto"/>
                                    <RowDefinition Height="0"/>
                                    <RowDefinition Height="auto"/>
                                </Grid.RowDefinitions>
                                <!--<StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center">
                                    <Run Text="{DynamicResource ConfigSource}"/>
                                    <Run>：</Run>
                                </TextBlock>
                                <TextBlock FontSize="11" VerticalAlignment="Center" Foreground="{StaticResource TextDarkColor}" Text="{Binding TemperatureConfigs.CurrentConfigFile.Selector, Converter={StaticResource Selector}}"/>
                            </StackPanel>-->
                                <StackPanel Grid.Row="2" Orientation="Horizontal" TextElement.FontSize="10">
                                    <TextBlock  VerticalAlignment="Center">
                                    <Run Text="{DynamicResource ConfigSelectTime}"/>
                                    <Run>：</Run>
                                    </TextBlock>
                                    <TextBlock FontSize="11" VerticalAlignment="Center" Foreground="{StaticResource TextDarkColor}" Text="{Binding TemperatureConfigs.CurrentConfigFile.SelectedTime, StringFormat=yy/MM/dd HH:mm:ss}"/>
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </Button>
                </Border>

                <Button Grid.Row="4" Style="{StaticResource FunctionButton}" Command="{Binding ReadCurrentAndSaveCommand}" CommandParameter="None" Background="{StaticResource WarningColor}" Height="24" Content="{DynamicResource ChannelSave}"/>


                <TextBlock Grid.Row="6" FontSize="14" FontWeight="Bold" Text="{DynamicResource ConfigFileList}"/>
                <ListBox Grid.Row="8" ItemsSource="{Binding TemperatureConfigs.ConfigFiles}" Background="Transparent" SelectedItem="{Binding Selected, Mode=OneWayToSource}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="2,6">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="8"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock x:Name="fileType" Panel.ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="2" Foreground="{StaticResource TextColor}">.mc</TextBlock>
                                <Image Source="{StaticResource Icon_File}" VerticalAlignment="Center" Height="28"/>
                                <StackPanel Grid.Column="2" >
                                    <TextBlock Text="{Binding ConfigName}" VerticalAlignment="Center" FontSize="12"/>
                                    <TextBlock FontSize="10" VerticalAlignment="Center" Foreground="{StaticResource TextDarkColor}" Text="{Binding EditTime, Converter={StaticResource Datetime}, ConverterParameter=default}"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

                <Button Grid.Row="10"  Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Engineer}"
                        Style="{StaticResource FunctionButton}" Command="{Binding EditCommand}" Height="24" Margin="0,8,0,0" IsEnabled="{Binding IsEditable}" Content="{DynamicResource Edit}"/>
                <Button Grid.Row="12"  Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Operator}"
                        Style="{StaticResource FunctionButton}" Command="{Binding LoadCommand}" Height="24" Margin="0,12" Content="{DynamicResource LoadNewConfigFile}"/>
                <Button Grid.Row="14"  Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Engineer}"
                        Style="{StaticResource FunctionButton}" Command="{Binding RemoveCommand}" Background="{StaticResource EmergencyColor}" Height="24" Content="{DynamicResource DeleteConfigFile}"/>
            </Grid>
        </Border>

        <Border Grid.Column="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1" Margin="8">
            <Grid Margin="8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <Grid Grid.Row="0" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="22"/>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="16"/>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="16"/>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="16"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock FontSize="14" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{DynamicResource ConfigFilePreview}"/>

                    <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center">
                         <Run Text="{DynamicResource ConfigFileName}"/>
                         <Run>： </Run>
                         <Run Text="{Binding Selected.ConfigName}"/>
                    </TextBlock>
                    <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center">
                         <Run Text="{DynamicResource ConfigFileEditTime}"/>
                         <Run>： </Run>
                         <Run Text="{Binding Selected.EditTime, Converter={StaticResource Datetime}, ConverterParameter=default}"/>
                    </TextBlock>
                    <!--<TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center">
                          <Run Text="{DynamicResource ConfigFileAuther}"/>
                          <Run>： </Run>
                          <Run Text="{Binding Selected.Editor}"/>
                    </TextBlock>
                    <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Center">
                          <Run Text="{DynamicResource ConfigFileDescription}"/>
                          <Run>： </Run>
                          <Run Text="{Binding Selected.Description}"/>
                    </TextBlock>-->
                </Grid>

                <controls:FullConfig Grid.Row="2" Source="{Binding Selected}"/>

                <StackPanel Grid.Row="4" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
                    <Button Height="24" VerticalAlignment="Center" MinWidth="140" Style="{StaticResource FunctionButton}" Command="{Binding CompareCommand}" Content="{DynamicResource CompareConfigFile}"/>
                    <Button Height="24" VerticalAlignment="Center" MinWidth="140"  Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Operator}"
                            Style="{StaticResource FunctionButton}" Margin="16,0" Background="{StaticResource EmergencyColor}" Command="{Binding SetAsCurrentCommand}" Content="{DynamicResource SetAsCurrentConfigFile}"/>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>
