<UserControl x:Class="MainShell.Manual.View.DiePositionView"
             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="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="DiePositionStatLabelStyle" TargetType="TextBlock" BasedOn="{StaticResource ProcessReadOnlyValueTextStyle}">
                <Setter Property="Width" Value="118"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>

            <Style x:Key="DiePositionStatValueStyle" TargetType="TextBox" BasedOn="{StaticResource ProcessTextBoxStyle}">
                <Setter Property="Width" Value="88"/>
                <Setter Property="MinWidth" Value="88"/>
                <Setter Property="Margin" Value="8,0,0,0"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="FontSize" Value="15"/>
                <Setter Property="TextAlignment" Value="Center"/>
                <Setter Property="IsReadOnly" Value="True"/>
                <Setter Property="Foreground" Value="#00A651"/>
            </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}" />
        </Border>
        <ScrollViewer Grid.Column="1"
                      Margin="0,4,4,4"
                      VerticalScrollBarVisibility="Auto"
                      HorizontalScrollBarVisibility="Disabled"
                      CanContentScroll="False">
            <GroupBox Header="{DynamicResource DiePosition}" Style="{StaticResource ProcessWideCardGroupBoxStyle}">
                <Grid Margin="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Vertical">
                        <GroupBox Style="{StaticResource ProcessWideCardGroupBoxStyle}" MinHeight="120" Header="{DynamicResource DiePositionStatistics}">
                            <Grid Margin="0" VerticalAlignment="Center">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <Grid Grid.Row="0" Grid.Column="0" Margin="4,2,14,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionTotalDieCountLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.TotalDieCount, Mode=OneWay}" Style="{StaticResource DiePositionStatValueStyle}" HorizontalAlignment="Left"/>
                                </Grid>
                                <Grid Grid.Row="0" Grid.Column="1" Margin="4,2,0,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionPassRateLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.PassRate, StringFormat={}{0:F2}%, Mode=OneWay}" Style="{StaticResource DiePositionStatValueStyle}" HorizontalAlignment="Left"/>
                                </Grid>

                                <Grid Grid.Row="1" Grid.Column="0" Margin="4,2,14,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionOkDieCountLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.OkDieCount, Mode=OneWay}" Style="{StaticResource DiePositionStatValueStyle}" HorizontalAlignment="Left"/>
                                </Grid>
                                <Grid Grid.Row="1" Grid.Column="1" Margin="4,2,0,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionNgDieCountLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.NgDieCount, Mode=OneWay}" HorizontalAlignment="Left">
                                        <TextBox.Style>
                                            <Style TargetType="TextBox" BasedOn="{StaticResource DiePositionStatValueStyle}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Statistics.NgDieCount}" Value="0">
                                                        <Setter Property="Foreground" Value="#00A651"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Statistics.NgDieCount, Converter={StaticResource ObjectToBoolConverter}}" Value="True">
                                                        <Setter Property="Foreground" Value="Red"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBox.Style>
                                    </TextBox>
                                </Grid>

                                <Grid Grid.Row="2" Grid.Column="0" Margin="4,2,14,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionAverageSpacingXLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.AverageSpacingX, StringFormat={}{0:F3}, Mode=OneWay}" Style="{StaticResource DiePositionStatValueStyle}" HorizontalAlignment="Left"/>
                                </Grid>
                                <Grid Grid.Row="2" Grid.Column="1" Margin="4,2,0,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource DiePositionAverageSpacingYLabel}" Style="{StaticResource DiePositionStatLabelStyle}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Statistics.AverageSpacingY, StringFormat={}{0:F3}, Mode=OneWay}" Style="{StaticResource DiePositionStatValueStyle}" HorizontalAlignment="Left"/>
                                </Grid>
                            </Grid>
                        </GroupBox>
                        <GroupBox Style="{StaticResource ProcessWideCardGroupBoxStyle}" Header="{DynamicResource DiePositionMap}" Margin="0,0,0,0" Height="300">
                            <custom:DieMapPanelControl MapModel="{Binding DieMapModel}"
                                                       DieSize="20"
                                                       Spacing="2"
                                                       MapBackground="#E5E7EB"
                                                       MapMargin="8"
                                                       Caption=""/>
                        </GroupBox>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Margin="0,8,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>
            </GroupBox>
        </ScrollViewer>
    </Grid>
</UserControl>