<Page x:Class="FLY.Thick.Base.UI.PgScanCorr"
      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" 
      mc:Ignorable="d" 
      xmlns:local ="clr-namespace:FLY.Thick.Base.UI"
      xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
      d:DesignHeight="1500" d:DesignWidth="1280"
      Background="WhiteSmoke"
	Title="Page_ScanCorr">
    <Page.Resources>
        <ResourceDictionary>
            <local:PgScanCorrVmUt x:Key="viewModel" Enable="True"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid Background="{StaticResource Brushes.Card.Background}" d:DataContext="{StaticResource viewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Background="{StaticResource Brushes.TitleBar.Background}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" >
                <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"  >
                    <iconPacks:PackIconMaterial Kind="ArrowLeftThick" />
                </Button>
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}" Text="{StaticResource str.PgScanCorr.Title}"/>
            </StackPanel>
            <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
        </Grid>
        <ScrollViewer Grid.Row="1"
                      CanContentScroll="False" PanningMode="Both" >
            <StackPanel Margin="{StaticResource ControlMargin}">
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="{StaticResource str.PgScanCorr.State}"/>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel>
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="{StaticResource str.PgScanCorr.Enable}"/>
                                <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding Enable}"/>
                            </StackPanel>
                        </StackPanel>
                        
                        
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock >
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldHeader}">
                                            <Setter Property="Text" Value="{StaticResource str.PgScanCorr.DataIsFull}"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsDataOK}" Value="false">
                                                    <Setter Property="Text" Value="{StaticResource str.PgScanCorr.InconsistencyOfData}"/>
                                                    <Setter Property="Foreground" Value="{StaticResource Brushes.Validation}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button  Content="{StaticResource str.PgScanCorr.Record}" 
                                        Command="{Binding StartCmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsRunning}" Value="True">
                                                    <Setter Property="IsEnabled" Value="False"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                                <Button Content="{StaticResource str.PgScanCorr.Stop}" Background="{StaticResource Brushes.Validation}" 
                                        Command="{Binding StopCmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">
                                            <Setter Property="IsEnabled" Value="False"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsRunning}" Value="True">
                                                    <Setter Property="IsEnabled" Value="True"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                        <Run Text="{StaticResource str.PgScanCorr.Group}"/> <Run Text="{Binding CurrGroupIndex}"/>
                                    </TextBlock>
                                    <Grid Width="100"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent}" 
                                                           Text="{Binding Progress}"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" 
                                                           Text="%"/>
                                </StackPanel>

                            </StackPanel>

                        </Grid>

                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="{StaticResource str.PgScanCorr.ScanChart}"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button  
                                        Command="{Binding SelectedGroup0Cmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding SelectedGroupIndex}" Value="0">
                                                    <Setter Property="Background" Value="{StaticResource Brushes.Activity}"/>
                                                    <Setter Property="Foreground" Value="White"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                    <TextBlock>
                                        <Run Text="{StaticResource str.PgScanCorr.Group}"/>0
                                    </TextBlock>
                                    
                                </Button>
                                <Button Command="{Binding SelectedGroup1Cmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding SelectedGroupIndex}" Value="1">
                                                    <Setter Property="Background" Value="{StaticResource Brushes.Activity}"/>
                                                    <Setter Property="Foreground" Value="White"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                    <TextBlock>
                                        <Run Text="{StaticResource str.PgScanCorr.Group}"/>1
                                    </TextBlock>
                                </Button>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" Grid.Column="1">
                                <Button  Content="{StaticResource str.PgScanCorr.Delete}" Style="{StaticResource Styles.Button.Square2}"
                                        Command="{Binding ClearCmd}"/>

                            </StackPanel>
                        </Grid>
                        

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                    <Run Text="{StaticResource str.PgScanCorr.Average}"/>:
                                </TextBlock>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}" 
                                                           Text="{Binding AvgAd}"/>
                            </StackPanel>
                        </Grid>
                        
                        
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="2" Margin="{StaticResource ControlMargin}">
                                <lvc:CartesianChart x:Name="chart1"  Height="350" 
                                            DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}"
                                            MouseMove="UIElement_OnMouseMove" MouseDown="UIElement_MouseDown" MouseUp="UIElement_MouseUp"
                                            Series="{Binding Series}" LegendLocation="Top"
                                                    
                                            >
                                    <lvc:CartesianChart.AxisX>
                                        <lvc:Axis LabelFormatter="{Binding XFormatter}" 
                                                  Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
                                                  MaxValue="{Binding XMax}" MinValue="{Binding XMin}" >
                                            <lvc:Axis.Separator>
                                                <lvc:Separator Stroke="LightGray"/>
                                            </lvc:Axis.Separator>
                                        </lvc:Axis>
                                    </lvc:CartesianChart.AxisX>
                                    <lvc:CartesianChart.AxisY>
                                        <lvc:Axis Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
                                                  LabelFormatter="{Binding YFormatter}" 
                                                  MaxValue="{Binding YMax}" MinValue="{Binding YMin}">
                                            <lvc:Axis.Separator>
                                                <lvc:Separator Stroke="LightGray"/>
                                            </lvc:Axis.Separator>
                                        </lvc:Axis>
                                    </lvc:CartesianChart.AxisY>
                                </lvc:CartesianChart>

                            </Grid>
                            <Controls:RangeSlider Grid.Row="2" Grid.Column="1"
                                                  Margin="{StaticResource ControlMargin}"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="MouseHover"
                                                  AutoToolTipPlacement="TopLeft"
                                                  Orientation="Vertical"
                                                  LargeChange="10"
                                                  SmallChange="1"
                                                  Maximum="{Binding YRangeSliderMax}"
                                                  Minimum="{Binding YRangeSliderMin}"
                                                  
                                                  LowerValue="{Binding YMin}"
                                                  UpperValue="{Binding YMax}" />

                        </Grid>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="{StaticResource str.PgScanCorr.Amend}"/>
                        <TabControl 
                                    Margin="{StaticResource ControlMargin}"
                            MinHeight="150"
                            Controls:TabControlHelper.Underlined="TabPanel"
                            Controls:TabControlHelper.UnderlinePlacement="Bottom"
                            Controls:HeaderedControlHelper.HeaderFontSize="18">
                            <TabItem Header="{StaticResource str.PgScanCorr.SmoothFilterMode}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal">
                                            <StackPanel Margin="{StaticResource ControlMargin}">
                                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgScanCorr.Smooth}" />
                                                <StackPanel Orientation="Horizontal" >
                                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}"
                                                        Text="{Binding SmoothFactor}" />
                                                </StackPanel>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <Button Content="{StaticResource str.PgScanCorr.Make}" Command="{Binding CreateCorrBySmoothCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">

                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>

                                    
                                </Grid>
                            </TabItem>
                            <TabItem Header="{StaticResource str.PgScanCorr.KeyPointMode}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal">
                                            <StackPanel Orientation="Horizontal">
                                                <Button Content="{StaticResource str.PgScanCorr.AddPoint}" Command="{Binding AddKeyPointModeCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding KpSelectMode}" Value="{x:Static local:KeyPointsSelectMode.Add}" >
                                                                    <Setter Property="IsEnabled" Value="False"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                                <Button Content="{StaticResource str.PgScanCorr.DelPoint}" Command="{Binding RemoveKeyPointModeCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding KpSelectMode}" Value="{x:Static local:KeyPointsSelectMode.Remove}" >
                                                                    <Setter Property="IsEnabled" Value="False"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                                <Button Style="{StaticResource Styles.Button.Square.Accent2}" 
                                                        Content="{StaticResource str.PgScanCorr.Make}" Command="{Binding CreateCorrByKeyPointCmd}" />

                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>
                                </Grid>
                            </TabItem>
                        </TabControl>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="{StaticResource str.PgScanCorr.Apply}" 
                                        Command="{Binding SetCorrDataCmd}"/>
                            </StackPanel>
                            
                            <StackPanel Grid.Column="1"
                                        Orientation="Horizontal">
                                <Button Style="{StaticResource Styles.Button.Square2}" Content="{StaticResource str.PgScanCorr.SaveXlsx}" 
                                        Command="{Binding SaveXlsxCmd}"/>
                                <Button Style="{StaticResource Styles.Button.Square2}" Content="{StaticResource str.PgScanCorr.LoadXlsx}" 
                                        Command="{Binding LoadXlsxCmd}"/>
                            </StackPanel>
                        </Grid>
                        
                    </StackPanel>
                </Border>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>
