<UserControl x:Class="MainShell.Recipe.View.SubstrateHeightMeasureView"
             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:mw="http://www.maxwell-gp.com/"
             xmlns:behavior="clr-namespace:MainShell.Common.ControlAttribute"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="900">
    <UserControl.Resources>
        <Style x:Key="NumericOnlyEditingTextBoxStyle" TargetType="TextBox">
            <Setter Property="behavior:ControlBehavior.IsNumericOnly" Value="True"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="6,2"/>
        </Style>
        <Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
            <Setter Property="Background" Value="White"/>
            <Style.Triggers>
                <Trigger Property="AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#F7FBFF"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <GroupBox Grid.Row="0"
                  Margin="8,8,8,4"
                  Header="测高模式"
                  Style="{StaticResource GroupBoxSecondary}">
            <Border Margin="10"
                    Padding="12"
                    Background="#F7FBFF"
                    BorderBrush="#D7E6F5"
                    BorderThickness="1"
                    CornerRadius="6">
                <StackPanel>
                    <TextBlock Text="支持标准示教位置与行列偏移两种测高点配置方式"
                               Foreground="#4A6178"
                               Margin="0,0,0,12"/>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <RadioButton Content="标准示教位置"
                                     IsChecked="{Binding Mode, Mode=TwoWay, Converter={StaticResource SubstrateHeightMeasureModeToBoolConverter}, ConverterParameter=0}"
                                     VerticalAlignment="Center"
                                     FontWeight="SemiBold"
                                     Margin="0,0,24,0"/>
                        <RadioButton Content="行列坐标 + 偏移补偿"
                                     IsChecked="{Binding Mode, Mode=TwoWay, Converter={StaticResource SubstrateHeightMeasureModeToBoolConverter}, ConverterParameter=1}"
                                     VerticalAlignment="Center"
                                     FontWeight="SemiBold"/>
                    </StackPanel>
                </StackPanel>
            </Border>
        </GroupBox>

        <GroupBox Grid.Row="1"
                  Margin="8,4,8,8"
                  Header="测高点设置"
                  Style="{StaticResource GroupBoxSecondary}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <DockPanel Grid.Row="0" Margin="8,8,8,4" LastChildFill="False">
                    <StackPanel DockPanel.Dock="Left">
                        <TextBlock Text="测高点列表"
                                   FontSize="16"
                                   FontWeight="Bold"
                                   Foreground="#24415C"/>
                        <TextBlock Text="当前模式下可维护测高点并编辑对应参数"
                                   Margin="0,4,0,0"
                                   Foreground="#6B7F92"/>
                    </StackPanel>
                    <WrapPanel DockPanel.Dock="Right" Orientation="Horizontal" Margin="12,0,0,0">
                        <Button Content="添加测高点"
                                Style="{StaticResource StartButtonStyle}"
                                Command="{Binding AddPointCmd}"
                                Margin="4"/>
                        <Button Content="删除测高点"
                                Style="{StaticResource CloseButtonStyle}"
                                Command="{Binding DeletePointCmd}"
                                Margin="4"/>
                        <Button Content="示教当前位置"
                                Style="{StaticResource TeachButtonStyle}"
                                Command="{Binding TeachPointCmd}"
                                IsEnabled="{Binding IsTeachMode}"
                                Margin="4"/>
                    </WrapPanel>
                </DockPanel>

                <Border Grid.Row="1"
                        Margin="8,4,8,4"
                        Padding="10,8"
                        Background="#F7FBFF"
                        BorderBrush="#D7E6F5"
                        BorderThickness="1"
                        CornerRadius="6"
                        Visibility="{Binding IsRowColumnMode, Converter={StaticResource BoolToVisibleConverter}}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0"
                                   Text="统一偏移补偿："
                                   VerticalAlignment="Center"
                                   Margin="0,0,8,0"
                                   Foreground="#4A6178"/>
                        <TextBlock Grid.Column="1"
                                   Text="X"
                                   VerticalAlignment="Center"
                                   Margin="0,0,4,0"/>
                        <mw:NumberBox Grid.Column="2"
                                 Width="100"
                                 Margin="0,0,10,0"
                                 VerticalContentAlignment="Center"
                                 Value="{Binding CommonOffsetCompensation.X, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock Grid.Column="3"
                                   Text="Y"
                                   VerticalAlignment="Center"
                                   Margin="0,0,4,0"/>
                        <mw:NumberBox Grid.Column="4"
                                 Width="100"
                                 Margin="0,0,10,0"
                                 VerticalContentAlignment="Center"
                                 Value="{Binding CommonOffsetCompensation.Y, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock Grid.Column="5"
                                   Text="可先统一写入，再对个别点单独修正"
                                   VerticalAlignment="Center"
                                   Margin="0,0,12,0"
                               TextWrapping="Wrap"
                                   Foreground="#6B7F92"/>
                        <Button Grid.Column="6"
                                Content="一键写入全部点位"
                                Width="120"
                                Style="{StaticResource VisionButtonStyle}"
                                Command="{Binding ApplyOffsetToAllCmd}"
                                Margin="12,0,0,0"/>
                    </Grid>
                </Border>

                <Grid Grid.Row="2" Margin="8,4,8,8">
                    <Grid Visibility="{Binding IsTeachMode, Converter={StaticResource BoolToVisibleConverter}}">
                        <DataGrid ItemsSource="{Binding Points}"
                                  SelectedItem="{Binding SelectedPoint}"
                                  AutoGenerateColumns="False"
                                  CanUserAddRows="False"
                                  MinHeight="140"
                                  AlternationCount="2"
                                  RowStyle="{StaticResource DataGridRowStyle}">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="点位名称" Width="1.4*" Binding="{Binding PointName, UpdateSourceTrigger=PropertyChanged}"/>
                                <DataGridTextColumn Header="标准位置 X" Width="*" Binding="{Binding TeachPosition.X, UpdateSourceTrigger=PropertyChanged, StringFormat=F4}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                                <DataGridTextColumn Header="标准位置 Y" Width="*" Binding="{Binding TeachPosition.Y, UpdateSourceTrigger=PropertyChanged, StringFormat=F4}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>

                    <Grid Visibility="{Binding IsRowColumnMode, Converter={StaticResource BoolToVisibleConverter}}">
                        <DataGrid ItemsSource="{Binding Points}"
                                  SelectedItem="{Binding SelectedPoint}"
                                  AutoGenerateColumns="False"
                                  CanUserAddRows="False"
                                  MinHeight="140"
                                  AlternationCount="2"
                                  RowStyle="{StaticResource DataGridRowStyle}">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="点位名称" Width="1.4*" Binding="{Binding PointName, UpdateSourceTrigger=PropertyChanged}"/>
                                <DataGridTextColumn Header="行坐标" Width="*" Binding="{Binding RowIndex, UpdateSourceTrigger=PropertyChanged}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                                <DataGridTextColumn Header="列坐标" Width="*" Binding="{Binding ColumnIndex, UpdateSourceTrigger=PropertyChanged}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                                <DataGridTextColumn Header="偏移补偿 X" Width="*" Binding="{Binding OffsetCompensation.X, UpdateSourceTrigger=PropertyChanged, StringFormat=F4}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                                <DataGridTextColumn Header="偏移补偿 Y" Width="*" Binding="{Binding OffsetCompensation.Y, UpdateSourceTrigger=PropertyChanged, StringFormat=F4}" EditingElementStyle="{StaticResource NumericOnlyEditingTextBoxStyle}"/>
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </Grid>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
