<UserControl x:Class="MainShell.Manual.View.SubstratePositionView"
             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:custom="clr-namespace:MainShell.Resources.CustomControl"
             mc:Ignorable="d" 
             d:DesignHeight="650" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="SubstratePositionPageTitleStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="17"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="Foreground" Value="{StaticResource ProcessTitleForegroundBrush}"/>
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="Margin" Value="0,0,0,12"/>
            </Style>

            <Style x:Key="SubstratePositionSectionGroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource ProcessWideCardGroupBoxStyle}">
                <Setter Property="Margin" Value="0,0,0,14"/>
                <Setter Property="Padding" Value="18,12,18,14"/>
            </Style>

            <Style x:Key="SubstratePositionHeaderStretchGroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
                <Setter Property="Background" Value="{StaticResource ProcessCardBackgroundBrush}"/>
                <Setter Property="BorderBrush" Value="{StaticResource ProcessCardBorderBrush}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Foreground" Value="{StaticResource ProcessTitleForegroundBrush}"/>
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="Margin" Value="0,0,0,14"/>
                <Setter Property="Padding" Value="18,12,18,14"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="GroupBox">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="38"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <Border Grid.Row="0" Background="{StaticResource ProcessHeaderBackgroundBrush}" BorderBrush="{StaticResource ProcessCardBorderBrush}" BorderThickness="0,0,0,1" CornerRadius="3,3,0,0" Padding="12,0">
                                        <ContentPresenter ContentSource="Header" HorizontalAlignment="Stretch" VerticalAlignment="Center" RecognizesAccessKey="True"/>
                                    </Border>
                                    <Border Grid.Row="1" Background="{StaticResource ProcessCardBackgroundBrush}" Padding="{TemplateBinding Padding}" CornerRadius="0,0,3,3">
                                        <ContentPresenter/>
                                    </Border>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="SubstratePositionEditorTextStyle" TargetType="TextBlock" BasedOn="{StaticResource ProcessReadOnlyValueTextStyle}">
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Margin" Value="0,0,10,0"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
            </Style>

            <Style x:Key="SubstratePositionAngleValueStyle" TargetType="mw:NumberBox" BasedOn="{StaticResource ProcessLargeNumberBoxStyle}">
                <Setter Property="Width" Value="154"/>
                <Setter Property="Margin" Value="0"/>
            </Style>

            <Style x:Key="SubstratePositionEditorNumberBoxStyle" TargetType="mw:IntNumberBox" BasedOn="{StaticResource ProcessIntNumberBoxStyle}">
                <Setter Property="Width" Value="78"/>
                <Setter Property="Margin" Value="0"/>
            </Style>

            <Style x:Key="SubstratePositionHeaderCheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
                <Setter Property="Foreground" Value="{StaticResource ProcessBodyForegroundBrush}"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>

            <Style x:Key="SubstratePositionMapHostStyle" TargetType="Border">
                <Setter Property="Background" Value="#EEF3F8"/>
                <Setter Property="BorderBrush" Value="{StaticResource ProcessCardBorderBrush}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="2"/>
                <Setter Property="Padding" Value="16"/>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid Background="{StaticResource ProcessPageBackgroundBrush}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Style="{StaticResource ProcessCameraHostBorderStyle}">
            <ContentControl Content="{Binding CameraAxisViewModel}" IsEnabled="{Binding Runner.IsRunning,Converter={StaticResource boolToInversionConverter}}"/>
        </Border>
        <ScrollViewer Grid.Column="1"
                      Margin="10,8,14,10"
                      VerticalScrollBarVisibility="Auto"
                      HorizontalScrollBarVisibility="Disabled"
                     Style="{StaticResource ProcessScrollViewerStyle}"
                      CanContentScroll="False">
            <Grid MinWidth="520">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0">
                    <TextBlock Style="{StaticResource SubstratePositionPageTitleStyle}" Text="{DynamicResource SubstratePosition}"/>
                    <Border Height="1" Background="{StaticResource ProcessCardBorderBrush}" Margin="0,0,0,12"/>
                </StackPanel>

                <GroupBox Grid.Row="1" Header="{DynamicResource MarkResult}" Style="{StaticResource SubstratePositionSectionGroupBoxStyle}">
                    <DataGrid Style="{StaticResource ProcessDataGridStyle}" AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding MarkResults}" MinHeight="86">
                        <DataGrid.Columns>
                            <DataGridTextColumn Width="*" Header="{DynamicResource ID}" Binding="{Binding Id}"/>
                            <DataGridTextColumn Width="1.75*" Header="{DynamicResource BaseX}" Binding="{Binding BasePose.X}"/>
                            <DataGridTextColumn Width="1.75*" Header="{DynamicResource BaseY}" Binding="{Binding BasePose.Y}"/>
                            <DataGridTextColumn Width="1.75*" Header="{DynamicResource ResultX}" Binding="{Binding ResultPose.X}"/>
                            <DataGridTextColumn Width="1.75*" Header="{DynamicResource ResultY}" Binding="{Binding ResultPose.Y}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </GroupBox>

                <GroupBox Grid.Row="2" Header="{DynamicResource SubstrateAngle}" Style="{StaticResource SubstratePositionSectionGroupBoxStyle}">
                    <Grid>
                        <mw:NumberBox Style="{StaticResource SubstratePositionAngleValueStyle}" IsReadOnly="True" Value="{Binding SubstrateAngle}" HorizontalAlignment="Center"/>
                    </Grid>
                </GroupBox>

                <GroupBox Grid.Row="3" Header="{DynamicResource VerifiyResult}" Style="{StaticResource SubstratePositionSectionGroupBoxStyle}"
                          IsEnabled="{Binding Runner.IsRunning, Converter={StaticResource boolToInversionConverter}}">
                    <Grid HorizontalAlignment="Center">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Style="{StaticResource SubstratePositionEditorTextStyle}" Text="{DynamicResource SubstrateRow}"/>
                        <mw:IntNumberBox Grid.Column="1" Style="{StaticResource SubstratePositionEditorNumberBoxStyle}" Minimum="1" Maximum="{Binding RowMax}" Value="{Binding RowIndex}" mw:NumericKeypadAttach.IsEnabled="True"/>
                        <TextBlock Grid.Column="2" Style="{StaticResource SubstratePositionEditorTextStyle}" Text="{DynamicResource SubstrateCol}" Margin="26,0,10,0"/>
                        <mw:IntNumberBox Grid.Column="3" Style="{StaticResource SubstratePositionEditorNumberBoxStyle}" Minimum="1" Maximum="{Binding ColMax}" Value="{Binding ColumnIndex}" mw:NumericKeypadAttach.IsEnabled="True"/>
                        <Button Grid.Column="4" Style="{StaticResource AxisMoveButtonStyle}" Click="{mw:Action MoveToSelectPad}" Content="{DynamicResource Move}" Margin="26,0,0,0"/>
                    </Grid>
                </GroupBox>

                <GroupBox Grid.Row="4" Style="{StaticResource SubstratePositionHeaderStretchGroupBoxStyle}">
                    <GroupBox.Header>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="1" Text="{DynamicResource SubstrateMap}" VerticalAlignment="Center" Foreground="{StaticResource ProcessTitleForegroundBrush}" FontWeight="SemiBold"/>
                            <CheckBox Grid.Column="2" Style="{StaticResource SubstratePositionHeaderCheckBoxStyle}" Content="{DynamicResource AllowClickSelection}" IsChecked="{Binding IsClickEnabled}" HorizontalAlignment="Right"/>
                        </Grid>
                    </GroupBox.Header>
                    <custom:DieMapPanelControl MinHeight="286"
                                               MaxHeight="560"
                                               HorizontalAlignment="Stretch"
                                               VerticalAlignment="Stretch"
                                               MapModel="{Binding SubstrateMapModel}"
                                               DieSize="15"
                                               Spacing="2"
                                               MapBackground="#EEF3F8"
                                               MapMargin="16"
                                               Caption=""
                                               DieClickedCommand="{Binding DieClickedCommand}"/>
                </GroupBox>

                <StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,4,0,0">
                    <Button Content="{DynamicResource Start}" Click="{mw:Action StartProcess}" Style="{StaticResource StartButtonStyle}" Margin="5"
                            IsEnabled="{Binding Runner.IsRunning, Converter={StaticResource boolToInversionConverter}}" />
                    <Button Content="{DynamicResource Stop}" Click="{mw:Action StopProcess}" Style="{StaticResource StopButtonStyle }" Margin="5"
                            IsEnabled="{Binding Runner.IsRunning}" />
                </StackPanel>
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>
