<UserControl x:Class="NETworkManager.Views.PuTTYSessionConnectDialog"
             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:Validator="clr-namespace:NETworkManager.Validators"
             xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:Converter="clr-namespace:NETworkManager.Converters"
             mc:Ignorable="d" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
        <Converter:BooleanReverseToVisibilityConverter x:Key="BooleanReverseToVisibilityConverter" />
        <Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>
    <Grid Margin="0,20">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="10" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.Resources>
                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
                <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}" />
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Mode}" />
            <Grid Grid.Column="2" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <RadioButton Grid.Column="0" Content="{DynamicResource String_SSH}" IsChecked="{Binding UseSSH}" />
                <RadioButton Grid.Column="2" Content="{DynamicResource String_Telnet}" IsChecked="{Binding UseTelnet}" />
                <RadioButton Grid.Column="4" Content="{DynamicResource String_Serial}" IsChecked="{Binding UseSerial}" />
                <RadioButton Grid.Column="6" Content="{DynamicResource String_Rlogin}" IsChecked="{Binding UseRlogin}" />
                <RadioButton Grid.Column="8" Content="{DynamicResource String_RAW}" IsChecked="{Binding UseRAW}" />
            </Grid>
            <TextBlock Grid.Column="0" Grid.Row="2">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}">
                        <Setter Property="Text" Value="{StaticResource String_Host}" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding UseSerial}" Value="True">
                                <Setter Property="Text" Value="{StaticResource String_SerialLine}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
            <ComboBox x:Name="cbHost" Grid.Column="2" Grid.Row="2" ItemsSource="{Binding HostHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}" Visibility="{Binding UseSerial, Converter={StaticResource BooleanReverseToVisibilityConverter}}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="Host" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                            <Validator:NoSpacesValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <ComboBox x:Name="cbSerialLine" Grid.Column="2" Grid.Row="2" ItemsSource="{Binding SerialLineHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleSerialLine}" Visibility="{Binding UseSerial, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="SerialLine" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                            <Validator:NoSpacesValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <TextBlock Grid.Column="0" Grid.Row="4">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}">
                        <Setter Property="Text" Value="{DynamicResource String_Port}" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding UseSerial}" Value="True">
                                <Setter Property="Text" Value="{DynamicResource String_Baud}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
            <ComboBox x:Name="cbPort" Grid.Column="2" Grid.Row="4" ItemsSource="{Binding PortHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExamplePort22}" Visibility="{Binding UseSerial, Converter={StaticResource BooleanReverseToVisibilityConverter}}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="Port" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                            <Validator:PortValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <ComboBox x:Name="cbBaud" Grid.Column="2" Grid.Row="4" ItemsSource="{Binding BaudHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleBaud9600}" Visibility="{Binding UseSerial, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="Baud" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                            <Validator:BaudValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <TextBlock Grid.Column="0" Grid.Row="6" Text="{DynamicResource String_Username}" />
            <ComboBox x:Name="cbUsername" Grid.Column="2" Grid.Row="6" ItemsSource="{Binding UsernameHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleUsername}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="Username" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:NoSpacesValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <TextBlock Grid.Column="0" Grid.Row="8" Text="{DynamicResource String_Profile}" />
            <ComboBox x:Name="cbProfile" Grid.Column="2" Grid.Row="8" ItemsSource="{Binding ProfileHistoryView}" Style="{StaticResource EditableComboBox}">
                <ComboBox.Text>
                    <Binding Path="Profile" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:NoSpacesValidator ValidatesOnTargetUpdated="True" />
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>
            <TextBlock Grid.Column="0" Grid.Row="10" Text="{DynamicResource String_AdditionalCommandLine}" />
            <TextBox x:Name="txtAdditionalCommandLine" Grid.Column="2" Grid.Row="10" Text="{Binding AdditionalCommandLine}" Style="{StaticResource DefaultTextBox}" />
        </Grid>
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="{DynamicResource String_Button_Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
            <Button Content="{DynamicResource String_Button_Connect}" Command="{Binding ConnectCommand}" IsDefault="True" Margin="10,0,0,0">
                <Button.Style>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
                        <Setter Property="IsEnabled" Value="False" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding UseSerial}" Value="True" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=cbSerialLine}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=cbBaud}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="IsEnabled" Value="True" />
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding UseSerial}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=cbHost}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=cbPort}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="IsEnabled" Value="True" />
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>
