<UserControl x:Class="Txgy.EWS.Client.SysModule.Views.SystemSettingsView"
             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:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d"
             d:DesignHeight="760"
             d:DesignWidth="1100">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/BaseResources.xaml"/>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/ButtonStyles.xaml"/>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/TextBoxStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Style x:Key="SettingGroupStyle" TargetType="GroupBox">
                <Setter Property="Margin" Value="0,0,0,16"/>
                <Setter Property="Padding" Value="14"/>
                <Setter Property="BorderBrush" Value="#FFE6E8EC"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="FontSize" Value="14"/>
            </Style>
            <Style x:Key="SettingLabelStyle" TargetType="TextBlock">
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Foreground" Value="#666"/>
                <Setter Property="Margin" Value="24,5,0,5"/>
            </Style>
            <Style x:Key="SettingTextBoxStyle" TargetType="TextBox" BasedOn="{StaticResource NormalTextBoxStyle}">
                <Setter Property="Height" Value="32"/>
                <Setter Property="Margin" Value="0,5"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Style.Triggers>
                    <Trigger Property="IsReadOnly" Value="True">
                        <Setter Property="Background" Value="#FFF2F4F7"/>
                        <Setter Property="BorderBrush" Value="#FFD0D5DD"/>
                        <Setter Property="Foreground" Value="#FF7A8491"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style x:Key="SettingCheckBoxStyle" TargetType="CheckBox">
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Margin" Value="0,5"/>
            </Style>
            <Style x:Key="BrowseButtonStyle" TargetType="Button" BasedOn="{StaticResource NormalButtonStyle}">
                <Setter Property="Width" Value="58"/>
                <Setter Property="Height" Value="32"/>
                <Setter Property="Margin" Value="6,5,0,5"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="FontSize" Value="13"/>
                <Setter Property="Background" Value="#FFE9F7FD"/>
                <Setter Property="Foreground" Value="#FF0886B8"/>
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="#FFF2F4F7"/>
                        <Setter Property="Foreground" Value="#FF98A2B3"/>
                        <Setter Property="BorderBrush" Value="#FFD0D5DD"/>
                        <Setter Property="Opacity" Value="1"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Margin="24">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <DockPanel Margin="0,0,0,16">
            <StackPanel DockPanel.Dock="Left">
                <TextBlock Text="参数设置" FontSize="24" FontWeight="Bold" Foreground="#333"/>
                <TextBlock Text="{Binding ConfigPath}" Margin="0,6,0,0" Foreground="#888"/>
            </StackPanel>
            <TextBlock DockPanel.Dock="Right"
                       Text="{Binding StatusMessage}"
                       Foreground="{Binding StatusBrush}"
                       VerticalAlignment="Bottom"
                       TextWrapping="Wrap"
                       MaxWidth="420"/>
        </DockPanel>

        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <GroupBox Header="工区参数" Style="{StaticResource SettingGroupStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="工区名称" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="1" Text="{Binding WorkAreaName, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Column="2" Text="工区配置" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="WorkAreaFilePath" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding WorkAreaFilePath, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>

                        <TextBlock Grid.Row="1" Text="台站CSV" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="1" Grid.Column="1">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="StationsCsvFilePath" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding StationsCsvFilePath, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                        <TextBlock Grid.Row="1" Grid.Column="2" Text="CAD DWG" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="1" Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="CadDwgFilePath" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding CadDwgFilePath, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>

                        <TextBlock Grid.Row="2" Text="DWG图层设置" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="2" Grid.Column="1">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="DwgJsonSetting" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding DwgJsonSetting, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                        <TextBlock Grid.Row="2" Grid.Column="2" Text="BaseX" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="2" Grid.Column="3" Text="{Binding BaseX, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>

                        <TextBlock Grid.Row="3" Text="BaseY" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding BaseY, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="3" Grid.Column="2" Text="BaseZ" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="3" Grid.Column="3" Text="{Binding BaseZ, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>

                        <TextBlock Grid.Row="4" Text="平面图横向偏移" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding DailyReportPlanOffsetX, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="4" Grid.Column="2" Text="平面图纵向偏移" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="4" Grid.Column="3" Text="{Binding DailyReportPlanOffsetY, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>

                        <TextBlock Grid.Row="5" Text="刷新间隔(秒)" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding RefreshInterval, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="5" Grid.Column="2" Text="数据时长(小时)" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="5" Grid.Column="3" Text="{Binding DataLookbackHours, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                    </Grid>
                </GroupBox>

                <GroupBox Header="预警配置" Style="{StaticResource SettingGroupStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="报警配置" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Column="1">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="AlarmSetting" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding AlarmSetting, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                        <TextBlock Grid.Column="2" Text="报警等级配置" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="AlarmLevelConfig" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding AlarmLevelConfig, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                    </Grid>
                </GroupBox>

                <GroupBox Header="报表" Style="{StaticResource SettingGroupStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="日报起始时间" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="1" Text="{Binding DailyReportStartTime, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Column="2" Text="报表事件分级" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="ReportEventLevelSetting" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding ReportEventLevelSetting, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                    </Grid>
                </GroupBox>

                <GroupBox Header="高级设置" Style="{StaticResource SettingGroupStyle}" Visibility="{Binding AdvancedSettingsVisibility}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="API 域名" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="1" Text="{Binding ApiDomain, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Column="2" Text="本地 SQLite" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseLocalFileCommand}" CommandParameter="LocalSqLiteDb" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding LocalSqLiteDb, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>

                        <TextBlock Grid.Row="1" Text="设计模式" Style="{StaticResource SettingLabelStyle}"/>
                        <CheckBox Grid.Row="1" Grid.Column="1" IsChecked="{Binding IsDesign}" Style="{StaticResource SettingCheckBoxStyle}"/>
                        <TextBlock Grid.Row="1" Grid.Column="2" Text="实时模式" Style="{StaticResource SettingLabelStyle}"/>
                        <CheckBox Grid.Row="1" Grid.Column="3" IsChecked="{Binding IsRealtime}" Style="{StaticResource SettingCheckBoxStyle}"/>

                        <TextBlock Grid.Row="2" Text="DWG显示设置" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="2" Grid.Column="1">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="DwgSettings" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding DwgSettings, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                        <TextBlock Grid.Row="2" Grid.Column="2" Text="CAD设置文件" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="2" Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseResourceFileCommand}" CommandParameter="CadSettingsFileName" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding CadSettingsFileName, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                    </Grid>
                </GroupBox>

                <GroupBox Header="数据库" Style="{StaticResource SettingGroupStyle}" Visibility="{Binding AdvancedSettingsVisibility}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="腾讯 MySQL" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="1" Text="{Binding TencentMySql, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="1" Text="实时结果表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding RealtimeResultTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="2" Text="实时波形表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding RealtimeWaveDataTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="3" Text="实时震源机制表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding RealtimeFocalmechanismTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="4" Text="后处理结果表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding PostResultTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="5" Text="后处理波形表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding PostWaveDataTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="6" Text="后处理震源机制表" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding PostFocalmechanismTable, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SettingTextBoxStyle}"/>
                    </Grid>
                </GroupBox>

                <GroupBox Header="系统参数" Style="{StaticResource SettingGroupStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="170"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="公司名称" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="1" Text="{Binding CommpanyName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Column="2" Text="系统中文名" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Column="3" Text="{Binding SystemNameCn, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>

                        <TextBlock Grid.Row="1" Text="系统简称" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SystemShortName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>
                        <TextBlock Grid.Row="1" Grid.Column="2" Text="系统英文名" Style="{StaticResource SettingLabelStyle}"/>
                        <TextBox Grid.Row="1" Grid.Column="3" Text="{Binding SystemNameEn, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>

                        <TextBlock Grid.Row="2" Text="Mseed缓存目录" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="2" Grid.Column="1">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseFolderCommand}" CommandParameter="WavesMseedFilePath" IsEnabled="{Binding CanEditSystemSettings}" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding WavesMseedFilePath, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>
                        <TextBlock Grid.Row="2" Grid.Column="2" Text="Txt缓存目录" Style="{StaticResource SettingLabelStyle}"/>
                        <DockPanel Grid.Row="2" Grid.Column="3">
                            <Button Content="浏览" DockPanel.Dock="Right" Command="{Binding BrowseFolderCommand}" CommandParameter="WavesTxtFilePath" IsEnabled="{Binding CanEditSystemSettings}" Style="{StaticResource BrowseButtonStyle}"/>
                            <TextBox Text="{Binding WavesTxtFilePath, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}"/>
                        </DockPanel>

                        <TextBlock Grid.Row="3" Grid.Column="2" Text="数据缓存时长(分钟)" Style="{StaticResource SettingLabelStyle}" Visibility="Collapsed"/>
                        <TextBox Grid.Row="3" Grid.Column="3" Text="{Binding DataCacheTimeLenMins, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding SystemSettingsReadOnly}" Style="{StaticResource SettingTextBoxStyle}" Visibility="Collapsed"/>

                        <Button Grid.Row="4"
                                Grid.Column="0"
                                Content="{Binding SystemSettingsEditButtonText}"
                                Width="86"
                                Height="30"
                                Margin="24,10,0,0"
                                HorizontalAlignment="Left"
                                Style="{StaticResource NormalButtonStyle}"
                                Background="#FFE9F7FD"
                                Foreground="#FF0886B8"
                                Command="{Binding ToggleSystemSettingsEditCommand}"/>
                    </Grid>
                </GroupBox>

            </StackPanel>
        </ScrollViewer>

        <DockPanel Grid.Row="2" Margin="0,16,0,0">
            <Button Content="重新读取"
                    Width="100"
                    Height="34"
                    Margin="0,0,8,0"
                    Style="{StaticResource NormalButtonStyle}"
                    Background="#DDD"
                    Foreground="#666"
                    Command="{Binding ReloadCommand}"/>
            <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Content="应用"
                        Width="100"
                        Height="34"
                        Margin="8,0,0,0"
                        Style="{StaticResource NormalButtonStyle}"
                        Background="#FF0ABEFF"
                        Command="{Binding ApplyCommand}"/>
            </StackPanel>
        </DockPanel>
    </Grid>
</UserControl>
