<UserControl x:Class="MegaRobo.C00225155App.MenuViews.HomeView"
             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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:navi="clr-namespace:Telerik.Windows.Controls.Navigation;assembly=Telerik.Windows.Controls.Navigation"
             xmlns:mat="clr-namespace:Telerik.Windows.Controls.MaterialControls;assembly=Telerik.Windows.Controls"
             xmlns:animation="clr-namespace:Telerik.Windows.Controls.Animation;assembly=Telerik.Windows.Controls"
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:mega="clr-namespace:MegaRobo.WpfComponents.MegaControls;assembly=MegaRobo.WpfComponents"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:converter="clr-namespace:MegaRobo.C00225155App.Converters"
             xmlns:bb="clr-namespace:MegaRobo.C00225155App.MenuViews"
             xmlns:devices="clr-namespace:MegaRobo.C00225155App.DevicesViews"
             xmlns:common="clr-namespace:Common;assembly=Common" 
             xmlns:c00225155app="clr-namespace:MegaRobo.C00225155App"
             mc:Ignorable="d" DataContext="{Binding HomeViewModel,Source={StaticResource vmLocator}}"
             d:DesignHeight="935" d:DesignWidth="1350">
    <UserControl.Resources>
        <ContextMenu x:Key="BottleGroupContextMenu">
            <MenuItem Header="按照瓶1更新工装配方" 
       Command="{Binding PlacementTarget.Tag.UpdateSampleBoxPropertyCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}" 
       CommandParameter="{Binding PlacementTarget.DataContext.BoxId_inDoseUpload, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>

            <!--<MenuItem Header="清空工装配方" 
       Command="{Binding PlacementTarget.Tag.ClearSampleBoxPropertyCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"  
       CommandParameter="{Binding PlacementTarget.DataContext.BoxId_inDosingStation, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
            <Separator/>
            <MenuItem Header="全置为空瓶" 
       Command="{Binding PlacementTarget.Tag.ResetAllSampleBottlesCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}" 
       CommandParameter="{Binding PlacementTarget.DataContext.BoxId_inDosingStation, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
            <MenuItem Header="全置为满瓶" 
       Command="{Binding PlacementTarget.Tag.FillAllSampleBottlesCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"  
       CommandParameter="{Binding PlacementTarget.DataContext.BoxId_inDosingStation, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>-->
            <MenuItem Header="清空" 
       Command="{Binding PlacementTarget.Tag.ResetSampleBottlesCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"  
       CommandParameter="{Binding PlacementTarget.DataContext.BoxId_inDoseUpload, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
        </ContextMenu>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Grid  Grid.Row="0"  Grid.Column="0" Grid.ColumnSpan="2" >
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" IsEnabled="{Binding ProjectPro.bNoUseBS}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="525"/>
                </Grid.RowDefinitions>

                <!--Visibility="{Binding ProjectPro.bNoUseBS,Converter={StaticResource BooleanToVisibilityConverter}}"-->
                <GroupBox>
                    <GroupBox.Header>
                        <TextBlock Text="手动上料" FontSize="15"/>
                    </GroupBox.Header>
                    <StackPanel Orientation="Horizontal" Margin="10">
                        <TextBlock Text="设置工装类型：" FontWeight="Bold" VerticalAlignment="Center" Margin="20,0,0,4"/>
                        <ComboBox  Width="170" Height="25"  ItemsSource="{x:Static common:EnumHelper.BoxTypeEnums}"  SelectedItem="{Binding SelectedBoxType, Mode=TwoWay}" />
                        <TextBlock Text="选择传送工装位置：" FontWeight="Bold" VerticalAlignment="Center"/>
                        <ComboBox ItemsSource="{Binding BoxIndexList}"  SelectedItem="{Binding SelectedBoxIndex,Mode=TwoWay}"  Width="80" Height="25"/>
                        <Button Style="{StaticResource btnMenu }" Content="设置" Command="{Binding LoadBoxCommand}"/>
                        <Button Style="{StaticResource btnMenu }" Content="上工装" Command="{Binding UploadBoxCommand}"/>
                        <Button Style="{StaticResource btnMenu }" Width="100" Content="传送平台到舱外" Command="{Binding TransferOutCommand}"/>
                        <Button Style="{StaticResource btnMenu }" Width="100" Content="传送平台到舱内" Command="{Binding TransferInCommand}"/>
                        <Button Style="{StaticResource btnMenu }" Width="100" Content="清空传送平台" Command="{Binding ClearTransferCommand}"/> 
                        <Button Style="{StaticResource btnMenu }" Width="100" Content="开始下料" Command="{Binding StartUnloadCommand}"/>
                    </StackPanel>
                </GroupBox>

                <!-- 8个工装位置（2行4列排列） -->
                <!--<ItemsControl  x:Name="transferItemsControl" Grid.Row="1"  Margin="5" ItemsSource="{Binding ProjectPro.TransferArea}"  ItemTemplateSelector="{StaticResource BoxTemplateSelector_Upload}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Rows="2" Columns="4"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Tag" Value="{Binding DataContext, ElementName=transferItemsControl}"/>
                            <Setter Property="ContextMenu" Value="{StaticResource BottleGroupContextMenu}"/>
                            <Setter Property="IsEnabled" Value="True"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                </ItemsControl>-->
                <ItemsControl x:Name="transferItemsControl1" Grid.Row="1" Margin="5" Visibility="Visible"
                      ItemsSource="{Binding ProjectPro.TransferArea}" 
                      ItemTemplateSelector="{StaticResource BoxTemplateSelector_Upload}"
                      AlternationCount="7">
                    <!-- 关键：设置交替索引数量为项的总数（7） -->
                    <!-- 1. 保留3列3行的Grid面板 -->
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                            </Grid>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <!-- 保留原有配置 -->
                            <Setter Property="Tag" Value="{Binding DataContext, ElementName=transferItemsControl1}"/>
                            <Setter Property="ContextMenu" Value="{StaticResource BottleGroupContextMenu}"/>
                            <Setter Property="IsEnabled" Value="True"/>

                            <!-- 核心：按索引（AlternationIndex）硬编码行列 -->
                            <!-- 索引0 → 第3列（Grid.Column=2）、第1行（Grid.Row=0） -->
                            <Style.Triggers>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                                    <Setter Property="Grid.Column" Value="2"/>
                                    <Setter Property="Grid.Row" Value="0"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                    <Setter Property="Grid.Column" Value="2"/>
                                    <Setter Property="Grid.Row" Value="1"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="2">
                                    <Setter Property="Grid.Column" Value="2"/>
                                    <Setter Property="Grid.Row" Value="2"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="3">
                                    <Setter Property="Grid.Column" Value="1"/>
                                    <Setter Property="Grid.Row" Value="0"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="4">
                                    <Setter Property="Grid.Column" Value="1"/>
                                    <Setter Property="Grid.Row" Value="1"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="5">
                                    <Setter Property="Grid.Column" Value="0"/>
                                    <Setter Property="Grid.Row" Value="0"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.AlternationIndex" Value="6">
                                    <Setter Property="Grid.Column" Value="0"/>
                                    <Setter Property="Grid.Row" Value="1"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                </ItemsControl>
            </Grid>
        </Grid>
       
        <c00225155app:DataResultView Grid.Row="1" Grid.Column="0"/>
        <DockPanel Grid.Row="1" Grid.Column="1">
            <GroupBox DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="1" Margin="5,0" FontSize="15">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal" Height="30" VerticalAlignment="Center">
                        <TextBlock Text="投料站" Style="{StaticResource txtBlockBaseStyle}"  Foreground="Black" />
                        <ContentControl  Margin="15,0,0,0" Style="{StaticResource ModeStatusLabelStyle}" Tag="{Binding DoseRunState,Mode=TwoWay}" />
                    </StackPanel>
                </GroupBox.Header>
                <StackPanel>
                    <ToolBar Style="{StaticResource toolbarstyle}" Height="45" Margin="0,5">
                        <telerik:RadButton Margin="10,0" Width="32" Style="{StaticResource StartButtonStyle}" IsEnabled="{Binding BtnEnableState}" ToolTip="启动" Command="{Binding Path=RunCommand}" CommandParameter="Start" />

                        <telerik:RadToggleButton Margin="10,0" Width="28" Height="25"  Style="{StaticResource PauseToggleButtonStyle}"  ToolTip="{Binding PauseContinueTipText,Mode=OneWay}"  Command="{Binding Path=RunCommand}" CommandParameter="Pause"/>

                        <telerik:RadButton Margin="10,0" Width="32" Style="{StaticResource StopButtonStyle}" ToolTip="停止" Command="{Binding Path=RunCommand}" CommandParameter="Stop"/>

                        <telerik:RadButton Margin="10,0" Width="34" Style="{StaticResource ResetButtonStyle}" IsEnabled="{Binding BtnEnableState}" ToolTip="复位" Command="{Binding Path=RunCommand}" CommandParameter="Reset"/>
                        <telerik:RadButton Margin="10,0" Width="34" Style="{StaticResource InitButtonStyle}" IsEnabled="{Binding BtnEnableState}" ToolTip="初始化" Command="{Binding Path=RunCommand}" CommandParameter="Init"/>
                    </ToolBar>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="10,2">
                            <Label Content="CT：" Foreground="#FF0966B9" Margin="0" />
                            <Border BorderBrush="#FF117EDF" BorderThickness="1" CornerRadius="2" Width="130" Margin="0">
                                <TextBlock   x:Name="configCtTxtBlock" Text="{Binding ProjectPro.Dose_CT}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black"/>
                            </Border>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="0,2">
                            <!--<telerik:RadButton Width="115" Command="{Binding OpenPipetteManageWindowCommand}" CommandParameter="5ml"  Content="5ml管理" Style="{StaticResource 5mlManageButtonStyle}" />-->
                            <telerik:RadButton Width="115" Command="{Binding OpenPipetteManageWindowCommand}"  CommandParameter="1ml" Content="1ml管理" Style="{StaticResource 1mlManageButtonStyle}" />
                            <CheckBox Content="不启用BS" VerticalAlignment="Center" Margin="10,0"  IsChecked="{Binding ProjectPro.bNoUseBS,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
                        </StackPanel>
                        <StackPanel Margin="5" Orientation="Horizontal" Visibility="{Binding ProjectPro.bNoUseBS,Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Button Margin="5,0,0,0" Content="导入方案" Style="{StaticResource btnMenu}"  HorizontalAlignment="Left" Width="80" Height="28"  FontSize="15" FontWeight="Bold"  Command="{Binding ProjectCommand}" CommandParameter="OpenProject"/>
                            <Border BorderBrush="#FF117EDF" BorderThickness="1" CornerRadius="2" Width="140" Margin="5,0">
                                <TextBlock Text="{Binding ProjectPro.NowOpenProjectFile,Mode=TwoWay}" TextWrapping="Wrap" Foreground="Black" />
                            </Border>
                        </StackPanel>
                    </StackPanel>
                    <Border Background="#FFF5F7F9">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="120"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <telerik:RadButton Grid.Row="0" Grid.Column="0" Width="115"  Style="{StaticResource 1mlTipResetClearButtonStyle}"  Command="{Binding TipFeedCommand}"  CommandParameter="1ml" Content="1mlTip重置" />
                            <telerik:RadButton  Grid.Row="0" Grid.Column="1" Width="115"  Style="{StaticResource 50ulTipResetClearButtonStyle}"   Command="{Binding TipFeedCommand}" CommandParameter="50ul" Content="50ulTip重置"/>
                            <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"  HorizontalAlignment="Left"  Margin="0" >
                                <telerik:RadButton Margin="6,0" Width="120"  Style="{StaticResource 300ulTipResetClearButtonStyle}"  Command="{Binding TipFeedCommand}"  CommandParameter="300ul" Content="300ulTip重置" />
                            </StackPanel>
                            <telerik:RadButton Grid.Row="1" Grid.Column="2" Width="100" Margin="4,0,0,0" Style="{StaticResource ClearButtonStyle}"   Command="{Binding TipFeedCommand}"  CommandParameter="TipLitter_Clear" Content="废料清空"/>
                        </Grid>
                    </Border>
                    <ScrollViewer MaxHeight="100">
                        <ListBox Name="BaselocalInfoListBox" ItemsSource="{Binding BaselocalInfo}" HorizontalContentAlignment="Stretch">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding}" Margin="1" FontSize="12" Foreground="MediumVioletRed" Background="#F0F0F0"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </ScrollViewer>
                </StackPanel>
            </GroupBox>

            <!--<GroupBox  DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="1" Margin="5,5" FontSize="15">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal" Height="30" VerticalAlignment="Center">
                        <TextBlock Text="反应站" Style="{StaticResource txtBlockBaseStyle}" Foreground="Black"/>
                        <ContentControl   Margin="15,0,0,0" Style="{StaticResource ModeStatusLabelStyle}" Tag="{Binding ReactRunState,Mode=TwoWay}" />
                    </StackPanel>
                </GroupBox.Header>
                <StackPanel>
                    <ToolBar Style="{StaticResource toolbarstyle}" Height="45" Margin="0,5">
                        <telerik:RadButton Margin="10,0" Width="32" Style="{StaticResource StartButtonStyle}" IsEnabled="{Binding BtnEnableState1}" ToolTip="启动" Command="{Binding Path=RunCommand}" CommandParameter="Start_React" />
                        -->
            <!--<Image Source="/DataBox/start.png" Width="28" Height="28"/>-->
            <!--

                        <telerik:RadToggleButton Margin="10,0" Width="28" Height="25" Style="{StaticResource PauseToggleButtonStyle}" ToolTip="{Binding PauseContinueTipText1,Mode=OneWay}"  Command="{Binding Path=RunCommand}" CommandParameter="Pause_React"/>
                        -->
            <!--<Image Source="{Binding PauseContinueImagePath1,Mode=OneWay}" Width="30" Height="30"/>-->
            <!--

                        <telerik:RadButton Margin="10,0" Width="32" Style="{StaticResource StopButtonStyle}" ToolTip="停止" Command="{Binding Path=RunCommand}" CommandParameter="Stop_React"/>
                        -->
            <!--<Image Source="/DataBox/stop.png" Width="28" Height="28"/>-->
            <!--

                        <telerik:RadButton Margin="10,0" Width="34" Style="{StaticResource ResetButtonStyle}" IsEnabled="{Binding BtnEnableState1}" ToolTip="复位" Command="{Binding Path=RunCommand}" CommandParameter="Reset_React"/>
                        <Image Source="/DataBox/reset.png" Width="24" Height="24"/>

                    </ToolBar>
                    -->
            <!--<StackPanel Orientation="Horizontal" Margin="5,0,0,5">
     <Label Content="CT：" Foreground="#FF0966B9" Margin="0" />
     <Border BorderBrush="#FF85BBEB" BorderThickness="1" CornerRadius="2" Width="120" Margin="0">
         -->
            <!--<TextBlock   x:Name="detectCtTxtBlock" Text="{Binding Detect_CT}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center"/>-->
            <!--
         <TextBlock   x:Name="detectCtTxtBlock" Text="{Binding ProjectPro.Detect_CT}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center"/>
     </Border>
 </StackPanel>-->
            <!--
                    <Border Background="#FFF5F7F9">
                        <Grid>
                            <Border  Margin="0,2,0,2">
                                <StackPanel  Margin="0,2"  Orientation="Horizontal">
                                    <telerik:RadButton Width="115"  Style="{StaticResource 1mlTipResetClearButtonStyle}"   Command="{Binding TipFeedCommand}"  CommandParameter="1ml_React" Content="1mlTip重置"/>
                                    <telerik:RadButton Width="115"  Style="{StaticResource ClearButtonStyle}"   Command="{Binding TipFeedCommand}"  CommandParameter="1ml_React_Clear" Content="废料清空"/>
                                </StackPanel>
                            </Border>
                        </Grid>
                    </Border>
                </StackPanel>
            </GroupBox>-->
        </DockPanel>
    </Grid>

</UserControl>
