<UserControl x:Class="HistoryView.Views.Dialogs.ConfigEditor"
             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:HistoryView.Views.Dialogs"
             xmlns:converter="clr-namespace:HistoryView.Converters"
             xmlns:Inputs="clr-namespace:HistoryView.Controls.Input"
             xmlns:resource="clr-namespace:HistoryView.Resources"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:data="clr-namespace:HistoryView.Data"
             xmlns:general="clr-namespace:GeneralData;assembly=GeneralData"
             mc:Ignorable="d">
    <UserControl.Resources>
        <converter:DateTimeToString x:Key="DatetimeConvert"/>
        <ObjectDataProvider
            x:Key="ChannelModeEnum"
            MethodName="GetValues"
            ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="general:ChannelMode"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider
      x:Key="InhibitEnum"
      MethodName="GetValues"
      ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="general:Inhibit"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <!--Inhibit-->
    </UserControl.Resources>
    <Grid Width="960" Height="640" >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="4"/>
            <RowDefinition/>
            <RowDefinition Height="8"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="8"/>
        </Grid.RowDefinitions>
        <GroupBox Header="File Info" Margin="6,0">
            <Grid Margin="4,2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="16"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock VerticalAlignment="Center">
                        <Run>Name</Run>
                        <Run>:</Run>
                </TextBlock>

                <Inputs:TextboxKeyboard Grid.Column="2" Text="{Binding File.ConfigName, Mode=TwoWay}">
                    <Inputs:TextboxKeyboard.DisplayContent>
                        <TextBox  Padding="4" MinWidth="120" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Text="{Binding File.ConfigName, Mode=TwoWay}" Background="#f8f8f8" BorderThickness="0"/>
                    </Inputs:TextboxKeyboard.DisplayContent>
                </Inputs:TextboxKeyboard>

                <TextBlock Grid.Column="4" VerticalAlignment="Center">
                        <Run Text="Description"/>
                        <Run>:</Run>
                </TextBlock>

                <Inputs:TextboxKeyboard Grid.Column="6" Text="{Binding File.Description, Mode=TwoWay}" VerticalAlignment="Center" DirectInput="True">
                    <Inputs:TextboxKeyboard.DisplayContent>
                        <TextBox  Padding="4" TextWrapping="Wrap" VerticalAlignment="Center" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" Text="{Binding File.Description, Mode=TwoWay}" Background="#f8f8f8" BorderThickness="0"/>
                    </Inputs:TextboxKeyboard.DisplayContent>
                </Inputs:TextboxKeyboard>
            </Grid>
        </GroupBox>

        <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1" Margin="6,0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="4"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackPanel Grid.RowSpan="3" Panel.ZIndex="1" Visibility="{Binding Loading}" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Image Source="{StaticResource Icon_Search}" Width="50"/>
                    <TextBlock FontSize="28" VerticalAlignment="Center" HorizontalAlignment="Center">Loading File...</TextBlock>
                </StackPanel>
                <Grid Margin="0,0,20,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="4"/>
                        <ColumnDefinition Width="80"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="Index"/>
                    <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="SetPoint"/>
                    <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="Caps"/>
                    <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="CapsW"/>
                    <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="FloorW"/>
                    <TextBlock Grid.Column="10" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="Floor"/>
                    <TextBlock Grid.Column="12" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="P"/>
                    <TextBlock Grid.Column="14" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="I"/>
                    <TextBlock Grid.Column="16" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="D"/>
                    <TextBlock Grid.Column="18" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="UpRate"/>
                    <TextBlock Grid.Column="20" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="DownRate"/>
                    <TextBlock Grid.Column="22" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="Mode"/>
                    <TextBlock Grid.Column="24" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" Text="Inhibit"/>
                </Grid>
                <resource:TouchableScrollViewer  Grid.Row="2" >
                    <ItemsControl ItemsSource="{Binding File.Mini8sConfig}" Grid.Row="2">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border  BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="0,0,0,0">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="40"/>
                                            <ColumnDefinition Width="0"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Border  BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="0,0.5,1,0.5">
                                            <TextBlock Text="{Binding Value.Index}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                        </Border>
                                        <Grid Grid.Column="2">
                                            <ItemsControl ItemsSource="{Binding Value.ChannelConfig}" Grid.Row="2">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Border Background="Transparent" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="0,0.5">
                                                            <Grid Margin="2,1">
                                                                <Grid.ColumnDefinitions>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="80"/>
                                                                    <ColumnDefinition Width="4"/>
                                                                    <ColumnDefinition Width="80"/>
                                                                </Grid.ColumnDefinitions>
                                                                <Inputs:NumberKeyboard Grid.Column="0" Text="{Binding Value.SetPoint, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox   Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.SetPoint, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="2" Text="{Binding Value.Caps, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.Caps, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="4" Text="{Binding Value.CapsWarning, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox  Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.CapsWarning, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="6" Text="{Binding Value.FloorWarning, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.FloorWarning, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="8" Text="{Binding Value.Floor, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.Floor, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="10" Text="{Binding Value.Running_P, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.Running_P,StringFormat=0.00 ,Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="12" Text="{Binding Value.Running_I, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.Running_I,StringFormat=0.00, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="14" Text="{Binding Value.Running_D, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.Running_D,StringFormat=0.00, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="16" Text="{Binding Value.SetpointUpRate, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.SetpointUpRate, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <Inputs:NumberKeyboard Grid.Column="18" Text="{Binding Value.SetpointDownRate, Mode=TwoWay}">
                                                                    <Inputs:NumberKeyboard.DisplayContent>
                                                                        <TextBox Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22"  Text="{Binding Value.SetpointDownRate, Mode=TwoWay}"/>
                                                                    </Inputs:NumberKeyboard.DisplayContent>
                                                                </Inputs:NumberKeyboard>

                                                                <ComboBox Grid.Column="20"  Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22" ItemsSource="{Binding Source={StaticResource ChannelModeEnum}}" SelectedItem="{Binding Value.ChannelMode, Mode=TwoWay}"/>
                                                                <ComboBox Grid.Column="22"  Margin="0,3" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="22" ItemsSource="{Binding Source={StaticResource InhibitEnum}}" SelectedItem="{Binding Value.Inhibit, Mode=TwoWay}"/>
                                                            </Grid>
                                                        </Border>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </Grid>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </resource:TouchableScrollViewer>
            </Grid>
        </Border>


        <Grid Grid.Row="4" Margin="16,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="8"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Button Grid.Column="0" MinWidth="120" Height="24" Style="{StaticResource FunctionButton}" Command="{Binding SaveCommand}" CommandParameter="save" Content="{DynamicResource Save}"/>

            <Button Grid.Column="2" MinWidth="120" Height="24" Style="{StaticResource FunctionButton}" Command="{Binding SaveCommand}" CommandParameter="saveas" Content="{DynamicResource SaveAs}"/>

            <Button Grid.Column="4" MinWidth="120" Height="24" Style="{StaticResource FunctionButton}" Background="{StaticResource DisableColor}" Command="{Binding ExitCommand}" Content="{DynamicResource Retrun}"/>

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