<UserControl
    x:Class="BPA.SingleDevice.View.RecipeManagementView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:BPA.SingleDevice.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

    <!--<UserControl.DataContext>
        <vm:RecipeManagementViewModel />
    </UserControl.DataContext>-->

    <bpa:DialogContainer>
        <Grid Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--#region 功能按钮-->
            <StackPanel
                Grid.Row="0"
                Margin="5"
                HorizontalAlignment="Right"
                bpa:PanelHelper.Spacing="15"
                Orientation="Horizontal">
                <Button
                    Width="300"
                    HorizontalAlignment="Right"
                    Command="{Binding AddCommand}"
                    Content="添加配方"
                    Style="{DynamicResource DarkButton}" />
            </StackPanel>

            <!--#endregion-->

            <!--#region 列表-->
            <bpa:ControlDisplay Grid.Row="1">
                <DataGrid
                    bpa:HeaderHelper.HorizontalAlignment="Center"
                    Style="{StaticResource DataGridLargeScrollStyle}"
                    Grid.Row="1"
                    AutoGenerateColumns="False"
                    BorderBrush="Gray"
                    BorderThickness="1"
                    CanUserAddRows="False"
                    CanUserDeleteRows="False"
                    CanUserReorderColumns="False"
                    CanUserResizeColumns="False"
                    CanUserResizeRows="False"
                    CanUserSortColumns="False"
                    GridLinesVisibility="All"
                    IsReadOnly="False"
                    ItemsSource="{Binding RecipeInfos}"
                    RowHeight="80"
                    SelectionMode="Single">
                    <DataGrid.Columns>
                        <DataGridTextColumn
                            Width="*"
                            Binding="{Binding Name}"
                            Header="配方名称" />
                        <DataGridCheckBoxColumn
                            Width="100"
                            Binding="{Binding IsEnable, UpdateSourceTrigger=PropertyChanged}"
                            Header="启用" />
                        <DataGridTextColumn
                            Width="420"
                            Binding="{Binding LastModified}"
                            Header="最后修改时间" />
                        <DataGridTemplateColumn Width="500" Header="操作">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Button
                                            Width="300"
                                            Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}"
                                            CommandParameter="{Binding Id}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="Edit2Fill" />
                                        </Button>
                                        <!--<Button
                                            Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}"
                                            CommandParameter="{Binding Id}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="CopyleftFill" />
                                        </Button>-->
                                        <Button
                                            Width="150"
                                            Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}"
                                            CommandParameter="{Binding Id}"
                                            Style="{StaticResource TextErrorButton}">
                                            <bpa:Icon Type="DeleteBinFill" />
                                        </Button>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </bpa:ControlDisplay>
            <bpa:MessageContainer Grid.Row="1" Identifier="RecipeManagementView" />
            <!--#endregion-->
        </Grid>
    </bpa:DialogContainer>
</UserControl>