<UserControl x:Class="_1RM.View.Editor.Forms.SftpFormView"
             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:controls="clr-namespace:_1RM.Controls"
             xmlns:forms="clr-namespace:_1RM.View.Editor.Forms"
             xmlns:s="https://github.com/canton7/Stylet"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance forms:SftpFormViewModel}"
             d:DesignHeight="1450" d:DesignWidth="800">
    <StackPanel>

        <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource 'Connection Info'}"></TextBlock>

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Hostname}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.Address, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                                 Tag="e.g. 192.168.0.101"></TextBox>
                </Grid>
                <TextBlock Style="{StaticResource EditorRowGridTitleFollowing}" Width="60" Text="{DynamicResource Port}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.Port, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                             MinWidth="50" HorizontalAlignment="Left"
                             InputMethod.IsInputMethodEnabled="False"
                             InputScope="Number"
                    ></TextBox>
                </Grid>
            </StackPanel>
        </Grid>

        <Grid Style="{StaticResource EditorRowGrid}" Name="GridUserName">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource User}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.UserName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"></TextBox>
                </Grid>
            </StackPanel>
        </Grid>

        <Grid Name="GridPwd">
            <Grid.Style>
                <Style TargetType="Grid" BasedOn="{StaticResource EditorRowGrid}">
                    <Setter Property="Margin" Value="0"></Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=CbUsePrivateKey,Path= IsChecked}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed"></Setter>
                            <Setter Property="IsEnabled" Value="False"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Password}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <controls:PasswordInput Height="28" Password="{Binding New.Password, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"/>
                </Grid>
                <CheckBox Name="CbUsePrivateKey"
                          Margin="5 0 0 0"
                          IsChecked="{Binding New.UsePrivateKeyForConnect}"
                          Content="{DynamicResource 'Use private key'}" 
                          Checked="CbUsePrivateKey_OnChecked"
                          Unchecked="CbUsePrivateKey_OnChecked"></CheckBox>
            </StackPanel>
        </Grid>

        <Grid Name="GridPrivateKey" Height="Auto">
            <Grid.Style>
                <Style TargetType="Grid" BasedOn="{StaticResource EditorRowGrid}">
                    <Setter Property="Margin" Value="0"></Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=CbUsePrivateKey,Path= IsChecked}" Value="False">
                            <Setter Property="Visibility" Value="Collapsed"></Setter>
                            <Setter Property="IsEnabled" Value="False"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Private key'}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <TextBox Name="TbPrivateKey" Text="{Binding New.PrivateKey}"></TextBox>
                        <Button Grid.Column="1"
                                Content="{DynamicResource Select}" 
                                Click="ButtonOpenPrivateKey_OnClick" 
                                Style="{StaticResource ButtonPrimaryStyle}"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Stretch">
                        </Button>
                    </Grid>
                    <CheckBox Margin="5 0 0 0"
                              Content="{DynamicResource 'Use private key'}" 
                              IsChecked="{Binding ElementName=CbUsePrivateKey, Path=IsChecked}"
                              Checked="CbUsePrivateKey_OnChecked"
                              Unchecked="CbUsePrivateKey_OnChecked"></CheckBox>
                </StackPanel>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text=""></TextBlock>
                    <TextBlock Style="{StaticResource TextBlockBase}" Text="{DynamicResource 'Supports the OpenSSH format key only with the internal SFTP client.'}" Opacity="0.7"></TextBlock>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text=""></TextBlock>
                    <TextBlock Style="{StaticResource TextBlockBase}" Text="{DynamicResource 'Supports the OpenSSH format key and Putty-key with WinSCP.'}" Opacity="0.7"></TextBlock>
                </StackPanel>
            </StackPanel>
        </Grid>

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text=""></TextBlock>
                <CheckBox Content="{DynamicResource 'Ask for password when open connect'}" IsChecked="{Binding New.AskPasswordWhenConnect}"></CheckBox>
            </StackPanel>
        </Grid>

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_sftp_startup_path}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.StartupPath, UpdateSourceTrigger=PropertyChanged}"
                             Tag="e.g. /home/user/Desktop"></TextBox>
                </Grid>
            </StackPanel>
        </Grid>

        <ContentControl s:View.Model="{Binding AlternativeCredentialListViewModel}"></ContentControl>

    </StackPanel>
</UserControl>