<UserControl x:Class="_1RM.View.Editor.Forms.RdpAppFormView"
             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:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
             xmlns:forms="clr-namespace:_1RM.View.Editor.Forms"
             xmlns:controls1="clr-namespace:_1RM.Controls"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:protocol="clr-namespace:_1RM.Model.Protocol"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance forms:RdpAppFormViewModel}"
             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}">
            <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 Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Password}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <controls1:PasswordInput Height="28" Password="{Binding New.Password, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"></controls1:PasswordInput>
                </Grid>
                <CheckBox Margin="5 0 0 0" Content="{DynamicResource 'Ask for password when open connect'}" IsChecked="{Binding New.AskPasswordWhenConnect}"></CheckBox>
            </StackPanel>
        </Grid>

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

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_remote_app_name}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.RemoteApplicationName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                             Tag="{DynamicResource server_editor_remote_app_name_tag}"
                             ToolTip="{DynamicResource server_editor_remote_app_name_tag}"
                    ></TextBox>
                </Grid>
            </StackPanel>
        </Grid>

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_remote_app_fullname}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <TextBox Text="{Binding New.RemoteApplicationProgram, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                             Tag="{DynamicResource server_editor_remote_app_fullname_tag}"
                             ToolTip="{DynamicResource server_editor_remote_app_fullname_tag}"></TextBox>
                </Grid>
            </StackPanel>
        </Grid>

        <Grid Opacity="0.7" Margin="0 0 0 20">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource TextBlockBase}" TextWrapping="Wrap" Foreground="{DynamicResource BackgroundTextBrush}" Text="Note: You can not register a RemoteApp directly, you have to config it on the server side first, or you will get the error 'The following RemoteApp program is not in the list of authorized programs'."></TextBlock>
                        <TextBlock Style="{StaticResource TextBlockBase}">
                                <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/remoteapp/" TextDecorations="{x:Null}" controls:HyperlinkHelper.IsOpenExternal="True">
                                    check how to config.
                                </Hyperlink>
                        </TextBlock>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Grid>


        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_sounds}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <Grid.Resources>
                        <forms:ConverterEAudioRedirectionMode x:Key="ConverterEAudioRedirectionMode" />
                    </Grid.Resources>
                    <ComboBox SelectedIndex="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEAudioRedirectionMode}}">
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_on_local}" ToolTip="{DynamicResource server_editor_advantage_sounds_on_local}" />
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_on_remote}" ToolTip="{DynamicResource server_editor_advantage_sounds_on_remote}" />
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_disabled}" ToolTip="{DynamicResource server_editor_advantage_sounds_disabled}" />
                        <ComboBoxItem Visibility="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                    </ComboBox>
                </Grid>
            </StackPanel>
        </Grid>


        <Grid Style="{StaticResource EditorRowGrid}" Visibility="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static protocol:EAudioRedirectionMode.RedirectToLocal}}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_sound_quality}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <Grid.Resources>
                        <forms:ConverterEAudioQualityMode x:Key="ConverterEAudioQualityMode" />
                    </Grid.Resources>
                    <ComboBox SelectedIndex="{Binding New.AudioQualityMode, Converter={StaticResource ConverterEAudioQualityMode}}">
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_dynamic}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_dynamic}" />
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_medium}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_medium}" />
                        <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_high}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_high}" />
                        <ComboBoxItem Visibility="{Binding New.AudioQualityMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                    </ComboBox>
                </Grid>
            </StackPanel>
        </Grid>


        <Grid Visibility="{Binding New.MstscModeEnabled, Converter={StaticResource ConverterBool2Visible}}">
            <StackPanel>
                <Grid Style="{StaticResource EditorRowGrid}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" 
                                       Text="{DynamicResource 'Additional settings'}" VerticalAlignment="Top" 
                                       Margin="0 7 30 0"></TextBlock>
                        <Grid Style="{StaticResource EditorRowGridInput}">
                            <Border>
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="BorderThickness" Value="1" />
                                        <Setter Property="CornerRadius" Value="5" />
                                        <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorderBrush}"/>
                                        <Setter Property="Padding" Value="5 1" />
                                        <Setter Property="Opacity" Value="1" />
                                        <Style.Triggers>
                                            <MultiDataTrigger>
                                                <MultiDataTrigger.Conditions>
                                                    <Condition Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=IsMouseOver}" Value="True"></Condition>
                                                    <Condition Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=TextArea.IsFocused}" Value="False"></Condition>
                                                </MultiDataTrigger.Conditions>
                                                <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                                <Setter Property="Opacity" Value="0.6" />
                                            </MultiDataTrigger>
                                            <DataTrigger Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=TextArea.IsFocused}" Value="True">
                                                <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                            </Border>
                            <controls1:BindableAvalonEditor Margin="8 0 4 0"
                                                               Padding="0 5 0 5"
                                                               x:Name="TextBoxRdpFileAdditionalSettings"
                                                               WordWrap="False"
                                                               ShowLineNumbers="True"
                                                               Text="{Binding New.RdpFileAdditionalSettings}"
                                                               FontSize="{DynamicResource TextFontSize}">
                                <controls1:BindableAvalonEditor.Resources>
                                    <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
                                        <VisualBrush.Visual>
                                            <TextBlock Style="{StaticResource TextBlockBase}" FontStyle="Italic">tip e.g. usbdevicestoredirect:s:-USB\VID_XXXX\XXXX</TextBlock>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </controls1:BindableAvalonEditor.Resources>
                                <controls1:BindableAvalonEditor.Style>
                                    <Style TargetType="controls1:BindableAvalonEditor" BasedOn="{StaticResource ControlBase}">
                                        <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"/>
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Style.Triggers>
                                            <Trigger Property="Text" Value="{x:Null}">
                                                <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                            </Trigger>
                                            <Trigger Property="Text" Value="">
                                                <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </controls1:BindableAvalonEditor.Style>
                            </controls1:BindableAvalonEditor>
                        </Grid>

                        <TextBlock Style="{StaticResource TextBlockBase}" VerticalAlignment="Top" Margin="2 0">
                                <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/rdp-in-mstsc-mode/#additional-settings" TextDecorations="{x:Null}" 
                                           controls:HyperlinkHelper.IsOpenExternal="True">
                                    (?)
                                </Hyperlink>
                        </TextBlock>
                    </StackPanel>
                </Grid>
                <Grid Style="{StaticResource EditorRowGrid}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Helper'}"></TextBlock>
                        <Grid Style="{StaticResource EditorRowGridInput}">
                            <StackPanel Orientation="Horizontal">
                                <Button Click="ButtonPreviewRdpFile_OnClick" Margin="0 0 5 0" Content="{DynamicResource 'Preview rdp file'}"></Button>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Grid>
    </StackPanel>
</UserControl>