<UserControl x:Class="ProximaAnalizer.Views.DBInfoTrace"
             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:ProximaAnalizer.Views"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary Source="/UICommon;component/Resources.xaml"/>
    </UserControl.Resources>
    <Grid Margin="8">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="2"/>
            <RowDefinition Height="200"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Expander ExpandDirection="Right"  IsExpanded="True" Margin="0,6" Padding="0,-2" TextElement.FontSize="14">
                <Expander.Header>
                    <TextBlock Text="数据编辑" HorizontalAlignment="Center" Margin="4">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="-90"/>
                        </TextBlock.LayoutTransform>
                    </TextBlock>
                </Expander.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <GroupBox Header="时间范围" Margin="4,0" MinWidth="240" BorderBrush="{StaticResource DarkBorderColor}">
                        <ScrollViewer >
                            <ItemsControl ItemsSource="{Binding RecipeSteps}" Margin="4">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox Margin="0,1" VerticalAlignment="Center" Style="{StaticResource StepCheckBox}" IsChecked="{Binding Value.IsSelected, Mode=TwoWay}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Checked">
                                                    <prism:InvokeCommandAction  Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DBInfoTrace}, 
                                                                                        Path=DataContext.SelectedCommand}" 
                                                                            CommandParameter="{Binding Value}"/>
                                                </i:EventTrigger>
                                                <i:EventTrigger EventName="Unchecked">
                                                    <prism:InvokeCommandAction  Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DBInfoTrace}, 
                                                                                        Path=DataContext.UnSelectedCommand}" 
                                                                            CommandParameter="{Binding Value}"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                            <Grid HorizontalAlignment="Left" Margin="8,0,0,0" VerticalAlignment="Center">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="auto"/>
                                                    <ColumnDefinition Width="8"/>
                                                    <ColumnDefinition Width="0"/>
                                                    <ColumnDefinition Width="0"/>
                                                    <ColumnDefinition Width="auto"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Key, StringFormat=MM-dd  HH:mm:ss.f}"/>
                                                <!--<TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value.Step_Number}"/>-->
                                                <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value.Step_Name}"/>
                                            </Grid>
                                        </CheckBox>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </ScrollViewer>
                    </GroupBox>

                    <GroupBox Grid.Column="2" Margin="4,0" Header="数据选择" MinWidth="240" BorderBrush="{StaticResource DarkBorderColor}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="4"/>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="4"/>
                                <RowDefinition Height="auto"/>

                            </Grid.RowDefinitions>
                            <Button Grid.Row="0" Style="{StaticResource FunctionButton}" Command="{Binding ReturnCommand}" Margin="4">返回上级</Button>
                            <ScrollViewer Grid.Row="2">
                                <ItemsControl ItemsSource="{Binding Hierachy}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Button Content="{Binding Key}" VerticalContentAlignment="Center" HorizontalContentAlignment="Left"
                                            Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DBInfoTrace}, Path=DataContext.SelectHierachyCommand}"
                                            CommandParameter="{Binding}" Margin="4" Padding="8,2" Background="Transparent"></Button>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                            <Grid Grid.Row="4" TextElement.FontSize="12">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="4"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Button Grid.Column="0" Height="24" Style="{StaticResource FunctionButton}" Command="{Binding SaveLoadCommand}" CommandParameter="Save">保存预设</Button>
                                <Button Grid.Column="2" Height="24" Style="{StaticResource FunctionButton}" Command="{Binding SaveLoadCommand}" CommandParameter="Load">读取预设</Button>
                            </Grid>
                        </Grid>
                    </GroupBox>
                </Grid>
            </Expander>

            <GroupBox Grid.Column="2" Header="数据图表" Margin="6"  BorderBrush="{StaticResource DarkBorderColor}">

                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="8"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="0"/>
                    </Grid.RowDefinitions>
                    <ContentControl Content="{Binding PlotControl, Mode=OneTime}" />

                    <WrapPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" >
                        <StackPanel Orientation="Horizontal" Margin="12,0">
                            <Button Width="120" Height="24"  Style="{StaticResource FunctionButton}" Command="{Binding GeneratePlotCommand}">绘制图标</Button>
                            <Button Width="120" Height="24" Margin="4" Style="{StaticResource FunctionButton}" Command="{Binding ViewTraceDataCommand}">查看数据</Button>
                        </StackPanel>

                        <StackPanel Orientation="Horizontal" Margin="12,0">
                            <Button Width="120" Height="24"  Style="{StaticResource FunctionButton}" Command="{Binding ReScaleCommand}" CommandParameter="+">横坐标 放大</Button>
                            <Button Width="120" Height="24" Margin="4" Style="{StaticResource FunctionButton}" Command="{Binding ReScaleCommand}" CommandParameter="-">横坐标 缩小</Button>
                        </StackPanel>

                        <StackPanel Orientation="Horizontal" Margin="12,0">
                            <Button Width="120" Height="24"  Style="{StaticResource FunctionButton}" Command="{Binding ReScaleCommand}" CommandParameter="add">纵坐标 放大</Button>
                            <Button Width="120" Height="24" Margin="4" Style="{StaticResource FunctionButton}" Command="{Binding ReScaleCommand}" CommandParameter="minus">纵坐标 缩小</Button>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="12,0">
                            <Button Width="120" Height="24" Style="{StaticResource FunctionButton}" Command="{Binding ReScaleCommand}" CommandParameter="">重置缩放</Button>
                            <Button Width="120" Height="24" Margin="4" Style="{StaticResource FunctionButton}" Command="{Binding ReturnPageCommand}" Background="{StaticResource WarningColor}">返回主页</Button>
                        </StackPanel>
                    </WrapPanel>

                </Grid>
            </GroupBox>
        </Grid>

        <Grid Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="3" Margin="2,0,6,2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="16"/>
                <ColumnDefinition/>
                <ColumnDefinition Width="16"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="24"/>
                    <RowDefinition Height="4"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock VerticalAlignment="Center">报警信息</TextBlock>

                <Grid Grid.Row="0" HorizontalAlignment="Right">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="12"/>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="12"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBox Width="40" HorizontalContentAlignment="Center" Margin="4,0" Text="{Binding AlarmInverval}"/>
                        <TextBlock VerticalAlignment="Center">秒内重复不显示</TextBlock>
                    </StackPanel>
                    <CheckBox Grid.Column="2"  IsChecked="{Binding DisplayAlarm, Mode=TwoWay}" VerticalAlignment="Center">显示Alarm</CheckBox>
                    <CheckBox Grid.Column="4" IsChecked="{Binding DisplayWarning, Mode=TwoWay}" VerticalAlignment="Center">显示Warning</CheckBox>
                </Grid>

                <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                    <ScrollViewer HorizontalScrollBarVisibility="Auto">
                        <ItemsControl ItemsSource="{Binding Alarms}" Margin="2">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto"/>
                                            <ColumnDefinition Width="8"/>
                                            <ColumnDefinition Width="48"/>
                                            <ColumnDefinition Width="8"/>
                                            <ColumnDefinition Width="48"/>
                                            <ColumnDefinition Width="8"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left"  Text="{Binding Occur_Time, StringFormat=HH:mm:ss.f}"/>
                                        <!--<TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Source}" ToolTip="{Binding Source}"/>-->
                                        <Button Grid.Column="2" Background="Transparent" BorderBrush="{StaticResource ThemeColor}" Foreground="{StaticResource ThemeColor}"
                                                Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DBInfoTrace}, Path=DataContext.AlarmDetailCommand}" CommandParameter="{Binding}">Details</Button>
                                        <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Level}" ToolTip="{Binding Level}"/>
                                        <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Description}" ToolTip="{Binding Description}"/>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Border>
            </Grid>

            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="24"/>
                    <RowDefinition Height="4"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock VerticalAlignment="Center">左侧坐标轴</TextBlock>
                <Button HorizontalAlignment="Right" Width="80" Style="{StaticResource FunctionButton}" Command="{Binding ClearCommand}" CommandParameter="L">清除</Button>
                <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                    <ScrollViewer  HorizontalScrollBarVisibility="Auto">
                        <ItemsControl ItemsSource="{Binding Left}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="4,2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="24"/>
                                            <ColumnDefinition Width="180"/>
                                            <ColumnDefinition Width="24"/>
                                            <ColumnDefinition Width="64"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Key}" VerticalAlignment="Center"/>
                                        <Button  Grid.Column="2" Background="Transparent" HorizontalContentAlignment="Left" BorderThickness="0"
                                      Command="{Binding RelativeSource={RelativeSource AncestorType=local:DBInfoTrace, Mode=FindAncestor}, Path=DataContext.EditLineCommand}"
                                      CommandParameter="{Binding}">
                                            <Line X1="0" Y1="0" X2="100" Y2="0" Stretch="Fill" Stroke="{Binding Value.Brush}" StrokeDashArray="{Binding Value.DashArray}" StrokeThickness="3"/>
                                        </Button>
                                        <Button Grid.Column="4" Style="{StaticResource FunctionButton}"
                                     Command="{Binding RelativeSource={RelativeSource AncestorType=local:DBInfoTrace, Mode=FindAncestor}, 
                                             Path=DataContext.RemoveLeftCommand}"
                                     CommandParameter="{Binding Key}">移除</Button>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Border>
            </Grid>

            <Grid Grid.Column="4" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="24"/>
                    <RowDefinition Height="4"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock VerticalAlignment="Center">右侧坐标轴</TextBlock>
                <Button HorizontalAlignment="Right" Width="80" Style="{StaticResource FunctionButton}" Command="{Binding ClearCommand}" CommandParameter="R">清除</Button>
                <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                    <ScrollViewer  HorizontalScrollBarVisibility="Auto">
                        <ItemsControl ItemsSource="{Binding Right}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="4,2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="24"/>
                                            <ColumnDefinition Width="180"/>
                                            <ColumnDefinition Width="24"/>
                                            <ColumnDefinition Width="64"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Key}" VerticalAlignment="Center"/>
                                        <Button  Grid.Column="2" Background="Transparent" HorizontalContentAlignment="Left" BorderThickness="0"
                                             Command="{Binding RelativeSource={RelativeSource AncestorType=local:DBInfoTrace, Mode=FindAncestor}, Path=DataContext.EditLineCommand}"
                                             CommandParameter="{Binding}">
                                            <Line X1="0" Y1="0" X2="100" Y2="0" Stretch="Fill" Stroke="{Binding Value.Brush}" StrokeDashArray="{Binding Value.DashArray}" StrokeThickness="3"/>
                                        </Button>
                                        <Button Grid.Column="4" Style="{StaticResource FunctionButton}"
                                   Command="{Binding RelativeSource={RelativeSource AncestorType=local:DBInfoTrace, Mode=FindAncestor}, 
                                           Path=DataContext.RemoveRightCommand}"
                                   CommandParameter="{Binding Key}">移除</Button>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Border>
            </Grid>
        </Grid>

    </Grid>
</UserControl>
