<UserControl
    x:Class="SicUI.Controls.WaferAssociationUnit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="http://OpenSEMI.Ctrlib.com/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:micro="clr-namespace:Caliburn.Micro;assembly=MECF.Framework.UI.Client"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <UserControl.Resources>
        <Style TargetType="ToolTip">
            <Style.Triggers>
                <Trigger Property="Content" Value="{x:Static sys:String.Empty}">
                    <Setter Property="Visibility" Value="Collapsed" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="24" />
                <RowDefinition Height="24" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="24" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Orientation="Horizontal">
                <Border
                    Width="90"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Title}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="1">
                    <TextBlock
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="Lot ID"
                        TextWrapping="Wrap" />
                </Border>
                <Border
                    Width="235"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Content}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="0,1,1,1">
                    <StackPanel Orientation="Horizontal">
                        <controls:TextBoxEx
                            Width="138"
                            Text="{Binding WAInfo.LotId, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                            TextSaved="{Binding WAInfo.LotIdSaved, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" />

                    </StackPanel>
                </Border>
            </StackPanel>

            <StackPanel Grid.Row="1" Orientation="Horizontal">
                <Border
                    Width="90"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Title}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="1,0,1,1">
                    <TextBlock
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="Sequence"
                        TextWrapping="Wrap" />
                </Border>
                <Border
                    Width="235"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Content}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="0,0,1,1">
                    <StackPanel Orientation="Horizontal">
                        <TextBox
                            Width="138"
                            IsReadOnly="True"
                            Text="{Binding WAInfo.SequenceName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                        <Button
                            Width="80"
                            Margin="5,0,0,0"
                            Padding="0"
                            Content="Select"
                            IsEnabled="{Binding WAInfo.IsEnableSelect, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <micro:ActionMessage MethodName="SelectSequence">
                                        <micro:Parameter Value="{Binding WAInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                                    </micro:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </StackPanel>
                </Border>
            </StackPanel>

            <StackPanel
                Grid.Row="2"
                Margin="0,2"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Orientation="Horizontal">
                <Button
                    Width="160"
                    Height="25"
                    Content="Set All"
                    IsEnabled="{Binding WAInfo.IsEnableSelect, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="SetAll">
                                <micro:Parameter Value="{Binding WAInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button
                    Width="160"
                    Height="25"
                    Margin="5,0,0,0"
                    Content="Deselect All"
                    IsEnabled="{Binding WAInfo.IsEnableSelect, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="DeselectAll">
                                <micro:Parameter Value="{Binding WAInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
            </StackPanel>
            <StackPanel Grid.Row="3" Orientation="Horizontal">
                <Border
                    Width="60"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Title}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="1">
                    <TextBlock
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="Name"
                        TextWrapping="Wrap" />
                </Border>
                <Border
                    Width="103"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Content}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="0,1,1,1">
                    <TextBlock
                        x:Name="txtJobID"
                        Width="Auto"
                        Height="20"
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="{Binding WAInfo.JobID, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                </Border>
                <Border
                    Width="60"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Title}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="0,1,1,1">
                    <TextBlock
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="Status"
                        TextWrapping="Wrap" />
                </Border>
                <Border
                    Width="102"
                    Padding="5,1"
                    Background="{DynamicResource Table_BG_Content}"
                    BorderBrush="{DynamicResource Table_BD}"
                    BorderThickness="0,1,1,1">
                    <TextBlock
                        Width="Auto"
                        Height="20"
                        VerticalAlignment="Center"
                        FontFamily="Arial"
                        FontSize="12"
                        Foreground="{DynamicResource FG_Black}"
                        Text="{Binding WAInfo.JobStatus, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                </Border>
            </StackPanel>
            <StackPanel
                Grid.Row="4"
                Margin="0,2"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Orientation="Horizontal">
                <Button
                    Width="160"
                    Height="25"
                    Content="Create Job"
                    IsEnabled="{Binding WAInfo.IsEnableCreate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="CreateJob">
                                <micro:Parameter Value="{Binding WAInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button
                    Width="160"
                    Height="25"
                    Margin="5,0,0,0"
                    Content="Abort Job"
                    IsEnabled="{Binding WAInfo.IsEnableAbort, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="AbortJob">
                                <micro:Parameter Value="{Binding ElementName=txtJobID, Path=Text}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
            </StackPanel>
            <StackPanel
                Grid.Row="5"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Orientation="Horizontal">
                <Button
                    Width="78"
                    Height="25"
                    Content="Start">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="Start">
                                <micro:Parameter Value="{Binding ElementName=txtJobID, Path=Text}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button
                    Width="78"
                    Height="25"
                    Margin="5,0,0,0"
                    Content="Pause"
                    IsEnabled="{Binding WAInfo.IsEnablePause, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="Pause">
                                <micro:Parameter Value="{Binding ElementName=txtJobID, Path=Text}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button
                    Width="78"
                    Height="25"
                    Margin="5,0,0,0"
                    Content="Resume"
                    IsEnabled="{Binding WAInfo.IsEnableResume, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="Resume">
                                <micro:Parameter Value="{Binding ElementName=txtJobID, Path=Text}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button
                    Width="77"
                    Height="25"
                    Margin="5,0,0,0"
                    Content="Stop"
                    IsEnabled="{Binding WAInfo.IsEnableStop, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <micro:ActionMessage MethodName="Stop">
                                <micro:Parameter Value="{Binding ElementName=txtJobID, Path=Text}" />
                            </micro:ActionMessage>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
            </StackPanel>
        </Grid>

        <ListBox
            Grid.Row="1"
            Margin="0,0"
            Focusable="False"
            ItemsSource="{Binding WAInfo.ModuleData.WaferManager.Wafers, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
            <ListBox.Resources>
                <Style BasedOn="{StaticResource ResourceKey={x:Type ListBoxItem}}" TargetType="ListBoxItem">
                    <Setter Property="Rectangle.StrokeThickness" Value="0" />
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Height="20">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border
                            Width="40"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content_Highlight}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="1">
                            <TextBlock
                                Name="txtSlotIndex"
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{Binding SlotIndex}" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Width="50"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Title}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,1,1,1">
                            <TextBlock
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{Binding WaferID}"
                                ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Width="190"
                            Padding="5,1"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,1,1,1">
                            <Border.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding WaferStatus}" Value="0">
                                            <Setter Property="Border.Background" Value="{DynamicResource Table_BG_Content_Highlight}" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding WaferStatus}" Value="1">
                                            <Setter Property="Border.Background" Value="SkyBlue" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                            <TextBlock
                                Name="txtSeqName"
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{Binding SequenceName}"
                                ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}" />
                        </Border>
                        <Border
                            Grid.Column="2"
                            Width="95"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content_Highlight}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,1,1,1">
                            <Button
                                Width="80"
                                Height="8"
                                Margin="0,-4"
                                FontSize="11"
                                IsEnabled="{Binding WAInfo.IsEnableCreate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <micro:ActionMessage MethodName="SetSequence">
                                            <micro:Parameter Value="{Binding WAInfo, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                                            <micro:Parameter Value="{Binding SlotIndex}" />
                                            <micro:Parameter Value="{Binding SequenceName}" />
                                        </micro:ActionMessage>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                                <Button.Style>
                                    <Style BasedOn="{StaticResource ResourceKey={x:Type Button}}" TargetType="{x:Type Button}">
                                        <Setter Property="Button.Content" Value="Remove" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ElementName=txtSeqName, Path=Text}" Value="{x:Static sys:String.Empty}">
                                                <Setter Property="Button.Content" Value="Set" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding WaferStatus}" Value="0">
                                                <Setter Property="Button.IsEnabled" Value="False" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Button.Style>
                            </Button>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Grid>
            <Grid.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding WAInfo.ModuleData.IsInstalled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Value="false">
                            <Setter Property="Grid.Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
        </Grid>
    </Grid>
</UserControl>
