<UserControl x:Class="MinicsUI.Views.Dialogs.ChannelMultiEdit"
             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:MinicsUI.Views.Dialogs"
             xmlns:convert="clr-namespace:HistoryView.Converters"             
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <convert:ActiveTuneSetToVis x:Key="ActiveTuneSet"/>
    </UserControl.Resources>
    <Grid Margin="8" MinHeight="480">
        <Grid Panel.ZIndex="1" Background="#70FFFFFF" Visibility="{Binding HintVis}">
            <Border Background="{StaticResource BackgroundColor}" VerticalAlignment="Center" HorizontalAlignment="Center">
                <TextBlock FontSize="32" Margin="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Hint}"/>
            </Border>
        </Grid>
        <Grid Width="auto" Height="auto">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="8"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <GroupBox Header="Channel Selector">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="1"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>

                    <Grid Margin="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="160"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="60"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="80"/>
                            <ColumnDefinition Width="42"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="42"/>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="42"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Channel"  HorizontalAlignment="Center"/>
                        <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Inhibit" ></TextBlock>
                        <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="AT" ></TextBlock>
                        <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Mode" ></TextBlock>
                        <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Center" Text="TC" ></TextBlock>
                        <TextBlock Grid.Column="10" VerticalAlignment="Center" HorizontalAlignment="Center" Text="P" ></TextBlock>
                        <TextBlock Grid.Column="12" VerticalAlignment="Center" HorizontalAlignment="Center" Text="I" ></TextBlock>
                        <TextBlock Grid.Column="14" VerticalAlignment="Center" HorizontalAlignment="Center" Text="D" ></TextBlock>
                    </Grid>

                    <Border Grid.Row="1" BorderThickness="0,0,0,1" Margin="8,0" BorderBrush="{StaticResource DarkBorderColor}" VerticalAlignment="Center"/>

                    <ItemsControl Grid.Row="2" ItemsSource="{Binding Selecters}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="4,3">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="4"/>
                                        <ColumnDefinition Width="48"/>
                                        <ColumnDefinition Width="4"/>
                                        <ColumnDefinition Width="60"/>
                                        <ColumnDefinition Width="4"/>
                                        <ColumnDefinition Width="48"/>
                                        <ColumnDefinition Width="4"/>
                                        <ColumnDefinition Width="58"/>
                                        <ColumnDefinition Width="4"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <CheckBox Style="{StaticResource FunctionCheckBox}" IsChecked="{Binding IsSelected}" Height="28">
                                        <Grid VerticalAlignment="Center" HorizontalAlignment="Left" Width="152" Margin="4,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="13"/>
                                                <ColumnDefinition Width="6"/>
                                                <ColumnDefinition/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding Channel.ChannelIndex}" Foreground="White"  HorizontalAlignment="Center"/>
                                            <TextBlock Grid.Column="2" Text="{Binding Channel.Name}" Foreground="White" HorizontalAlignment="Center"/>
                                        </Grid>
                                    </CheckBox>
                                    <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.Inhibit}"/>
                                    <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.AutoTuneStatus}"/>
                                    <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.ChannelMode}"/>
                                    <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.SensorBreakAlarm}"/>
                                    <Grid Grid.Column="10">
                                        <StackPanel>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="72"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                </Grid.ColumnDefinitions>
                                                <Border  BorderThickness="1" Grid.ColumnSpan="7" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=AutoTune}" Background="{StaticResource LightWarningColor}" BorderBrush="{StaticResource WarningColor}"/>
                                                <TextBlock Grid.Column="0"  VerticalAlignment="Center" HorizontalAlignment="Center" Text="AutoTune:"/>
                                                <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.AutoTune_P, StringFormat=0.0}"/>
                                                <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.AutoTune_I, StringFormat=0.0}"/>
                                                <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.AutoTune_D, StringFormat=0.0}"/>
                                            </Grid>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="72"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                    <ColumnDefinition Width="4"/>
                                                    <ColumnDefinition Width="42"/>
                                                </Grid.ColumnDefinitions>
                                                <Border  BorderThickness="1"  Grid.ColumnSpan="7" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=Running}" Background="{StaticResource LightNormalColor}" BorderBrush="{StaticResource NormalColor}"/>
                                                <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Running  :"/>
                                                <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.Running_P, StringFormat=0.0}"/>
                                                <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.Running_I, StringFormat=0.0}"/>
                                                <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Channel.Running_D, StringFormat=0.0}"/>
                                            </Grid>
                                        </StackPanel>
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="1"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>

            </GroupBox>

            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="32"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="16"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="16"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="8"/>
                </Grid.RowDefinitions>
                <GroupBox Grid.Row="0" Header="Selector">
                    <Grid Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="8"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding SelectCommand}" CommandParameter="All" Content="{DynamicResource SelectAll}"></Button>
                        <Button Grid.Column="2" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding SelectCommand}" CommandParameter="None" Background="{StaticResource EmergencyColor}" Content="{DynamicResource SelectNone}" Height="32"/>
                    </Grid>
                </GroupBox>


                <GroupBox Grid.Row="2" Header="Auto Tune">
                    <Grid Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="8"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="16"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Button Grid.Column="0" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding AutoTuneCommand}">Start AutoTune</Button>
                        <Button Grid.Column="2" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding AbortAutoTuneCommand}" Background="{StaticResource WarningColor}" Height="32">Abort AutoTune</Button>
                        <Button Grid.Row="2" Grid.ColumnSpan="3" Height="32" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding ApplyATPIDCommand}" CommandParameter="Apply">Apply AutoTune PID</Button>
                    </Grid>
                </GroupBox>
                <GroupBox Grid.Row="4" Header="Channel Enable">
                    <Grid Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="8"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding ControlModeCommand}" CommandParameter="Enable">Enable Channel</Button>
                        <Button Grid.Column="2" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding ControlModeCommand}" CommandParameter="Disable" Background="{StaticResource EmergencyColor}" Height="32">Disable Channel</Button>
                    </Grid>
                </GroupBox>

                <GroupBox Grid.Row="6" Header="Channel Mode">
                    <Grid Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="8"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding ChannelModeSwitchCommand}" CommandParameter="Control">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{StaticResource Icon_Setting}" Height="18"></Image>
                                <TextBlock VerticalAlignment="Center" Margin="4,0,0,0">Control</TextBlock>
                            </StackPanel>
                        </Button>
                        <Button Grid.Column="2" Style="{StaticResource FunctionButton}" MinWidth="120" Command="{Binding ChannelModeSwitchCommand}" CommandParameter="Monitor" Background="{StaticResource NiceGreen}" Height="32">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{StaticResource Monitorable}" Height="18"></Image>
                                <TextBlock VerticalAlignment="Center" Margin="4,0,0,0">Monitor</TextBlock>
                            </StackPanel>
                        </Button>
                    </Grid>
                </GroupBox>

                <Button Grid.Row="8" Style="{StaticResource FunctionButton}" Background="{StaticResource DisableColor}" Content="{DynamicResource Exit}" Command="{Binding ExitCommand}" MinWidth="120"  Height="32"/>
            </Grid>

        </Grid>
    </Grid>
</UserControl>
