<UserControl x:Class="SlnMesnac.WPF.Page.IndexControl"
             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:local="clr-namespace:SlnMesnac.WPF.Page"
             xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             xmlns:cvt="clr-namespace:SlnMesnac.WPF.Converter.Index"
             mc:Ignorable="d"
            d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent" Opacity="1">
    <UserControl.Resources>
        <cvt:WcsTaskStatusConvert x:Key="WcsTaskStatusConvert" />
    </UserControl.Resources>

    <Grid Margin="1,1">
        <Grid.RowDefinitions>
            <RowDefinition Height="1.2*" />
            <RowDefinition Height="1.5*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Grid.Column="0" BorderBrush="#1edaf2"  CornerRadius="5" Background="Transparent" Margin="1,1,5,0">
            <Grid>
                <ItemsControl ItemsSource="{Binding AgvList}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="3" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="#1edaf2" BorderThickness="0" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" CornerRadius="10" Width="500">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Image Source="{Binding ImageSource}" Width="150" Height="150" Margin="0,5,0,0" Grid.Column="0" />
                                    <StackPanel Grid.Column="1" Orientation="Vertical" Margin="5,15,0,0">
                                        <TextBlock Foreground="#e4d374" Text="{Binding Name, StringFormat='名称：{0}'}" FontSize="18" Margin="0,15,0,0" />
                                        <TextBlock Foreground="#e4d374" Text="{Binding Battery, StringFormat='电量：{0}'}" FontSize="18" Margin="0,15,0,0" />
                                        <TextBlock Foreground="#e4d374" Text="{Binding IsOnline, StringFormat='是否在线：{0}'}" FontSize="18" Margin="0,15,0,0" />
                                        <TextBlock Foreground="#e4d374" Text="{Binding Status, StringFormat='状态：{0}'}" FontSize="18" Margin="0,15,0,0" />
                                    </StackPanel>
                                </Grid>
                            </Border>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </Border>

        <Border Grid.Row="1" BorderThickness="0" BorderBrush="#18adc8" Grid.Column="0"   CornerRadius="15" Background="Transparent" Margin="1,1,5,5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1.2*" />
                    <RowDefinition Height="9*" />
                </Grid.RowDefinitions>

                <Border Grid.Row="0" BorderBrush="#1edaf2" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5">
                    <TextBlock Text="实时任务" FontSize="20" FontWeight="Bold" Foreground="#1edaf2" VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Border>
                <Border IsEnabled="True" Grid.Row="1" BorderBrush="#1edaf2" BorderThickness="0.5" CornerRadius="12" Background="Transparent">
                    <DataGrid x:Name="datagrid" Grid.Row="0" ItemsSource="{Binding WcsTaskItems}" Background="Transparent"
    FontSize="16" FontFamily="四圆黑" ColumnHeaderHeight="40" RowHeight="40"
    ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"
    AutoGenerateColumns="False"  CanUserAddRows="False"
    GridLinesVisibility="None"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <DataGrid.Resources>
                            <Style TargetType="DataGridColumnHeader">
                                <Setter Property="Background" Value="Transparent" />
                                <Setter Property="Foreground" Value="#1edaf2" />
                                <Setter Property="FontWeight" Value="Bold" />
                                <Setter Property="HorizontalContentAlignment" Value="Center" />
                                <Setter Property="VerticalContentAlignment" Value="Center" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="DataGridColumnHeader">
                                            <Grid>
                                                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                </Border>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <Style TargetType="DataGridRow">
                                <Setter Property="Background" Value="Transparent" />
                                <Setter Property="Foreground" Value="#1edaf2" />
                                <!-- 默认边框颜色为透明 -->
                                <Setter Property="BorderThickness" Value="2" />
                                <!-- 边框厚度 -->
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <!--<Setter Property="BorderBrush" Value="Red" />-->
                                        <Setter Property="Background" Value="Gray" />
                                        <!-- 选中时边框颜色设置为红色，可按需修改 -->
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.Resources>
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Id}" Header="任务Id" Width="*" IsReadOnly="True" Visibility="Collapsed" />
                            <DataGridTextColumn Binding="{Binding NextPointNo}" Header="Agv名称" Width="*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding TaskName}" Header="任务名称" Width="3*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding CurrPointNo}" Header="起点库位" Width="1.5*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding EndPointNo}" Header="终点库位" Width="1.5*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding PalletInfoCode}" Header="托盘编号" Width="1.5*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding CreatedTime,StringFormat=\{0:yyyy-MM-dd  HH:mm:ss\}}" Header="创建时间" Width="2*" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding .,Converter={StaticResource WcsTaskStatusConvert}}" Header="计划状态" Width="3*" IsReadOnly="True" />
                            <DataGridTemplateColumn Header="操作" Width="2*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                            <Button Content="删除" CommandParameter="{Binding Id}" Command="{Binding DataContext.DeleteTaskCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid  }}" Background="Red" BorderBrush="Red" ToolTip="MaterialDesignFlatMidButton" Margin="10,0,10,0" Foreground="White" FontSize="16" Width="80" Height="30" />
                                        </StackPanel>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Border>
            </Grid>
        </Border>

        <Border Grid.Row="2" Grid.Column="0" BorderBrush="#1edaf2" BorderThickness="0,0,0,0" CornerRadius="5" Background="Transparent">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="9*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Border Grid.Row="0" Grid.Column="0" BorderBrush="#1edaf2" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5">
                    <TextBlock Text="任务统计" FontSize="20" FontWeight="Bold" Foreground="#1edaf2" VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="1" BorderBrush="#1edaf2" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5">
                    <TextBlock Text="系统日志" FontSize="20" FontWeight="Bold" Foreground="#1edaf2" VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="0" BorderBrush="#1edaf2" BorderThickness="0.5" CornerRadius="12" Background="Transparent" Margin="1,6,5,5">
                    <lvc:CartesianChart Series="{Binding Achievement, UpdateSourceTrigger=PropertyChanged}"   LegendLocation="Top" Foreground="#1edaf2" DisableAnimations="True">
                        <lvc:CartesianChart.DataTooltip>
                            <lvc:DefaultTooltip SelectionMode="OnlySender"  BulletSize="10" Foreground="Black"></lvc:DefaultTooltip>
                        </lvc:CartesianChart.DataTooltip>
                        <lvc:CartesianChart.AxisX>
                            <lvc:Axis Labels="{Binding ProductionHourList}" FontSize="18" Foreground="#1edaf2" LabelsRotation="0"  DisableAnimations="True" Position="LeftBottom">
                                <lvc:Axis.Separator>
                                    <lvc:Separator Visibility="Hidden" Step="1" StrokeThickness="1.5" StrokeDashArray="0" Stroke="#404F56">
                                    </lvc:Separator>
                                </lvc:Axis.Separator>
                            </lvc:Axis>
                        </lvc:CartesianChart.AxisX>
                        <lvc:CartesianChart.AxisY>
                            <lvc:Axis FontSize="18" Foreground="#1edaf2" MinValue="0">
                                <lvc:Axis.Separator>
                                    <lvc:Separator Step="10" Visibility="Hidden" StrokeThickness="0" StrokeDashArray="3"  Stroke="#404F56">
                                    </lvc:Separator>
                                </lvc:Axis.Separator>
                            </lvc:Axis>
                        </lvc:CartesianChart.AxisY>
                    </lvc:CartesianChart>
                </Border>

                <Border Grid.Row="1" Grid.Column="1" BorderBrush="#1edaf2" BorderThickness="0.5" CornerRadius="12" Background="Transparent" Margin="1,6,5,5">
                    <ListBox Margin="20 0 0 0" x:Name="listBox" ItemsSource="{Binding LogInfoListBox}" FontSize="15" Foreground="#1edaf2" Background="Transparent" BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" />
                </Border>
            </Grid>
        </Border>
    </Grid>
</UserControl>