<UserControl x:Class="_1RM.View.Editor.Forms.AlternativeCredential.AlternativeCredentialListView"
             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:base="clr-namespace:_1RM.Model.Protocol.Base"
             xmlns:editor="clr-namespace:_1RM.View.Editor"
             xmlns:forms="clr-namespace:_1RM.View.Editor.Forms"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance forms:ProtocolBaseWithAddressPortFormViewModel}"
             d:DesignHeight="450" d:DesignWidth="800">
    <StackPanel>

        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Availability detection'}"></TextBlock>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <CheckBox Content="{DynamicResource 'Check if address is available before connect'}" 
                              IsChecked="{Binding New.IsPingBeforeConnect}"
                              Margin="0 5 0 0"></CheckBox>
                </Grid>
            </StackPanel>
        </Grid>
        
        <Grid Style="{StaticResource EditorRowGrid}">
            <StackPanel Orientation="Horizontal">
                <StackPanel>
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Alternative}"
                               VerticalAlignment="Top"></TextBlock>
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" 
                           TextWrapping="Wrap" Height="Auto" Opacity="0.6"
                           Text="{DynamicResource 'support multi-address multi-account'}">
                    </TextBlock>
                </StackPanel>
                <Grid Style="{StaticResource EditorRowGridInput}">
                    <Grid.Resources>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource DataGridColumnHeaderBaseStyle}">
                            <Setter Property="Visibility" Value="Collapsed"></Setter>
                        </Style>
                    </Grid.Resources>

                    <StackPanel>
                        <ItemsControl HorizontalAlignment="Stretch" 
                                      HorizontalContentAlignment="Stretch"
                                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                      ItemsSource="{Binding New.AlternateCredentials}" >
                            <ItemsControl.ItemTemplate>
                                <DataTemplate DataType="base:Credential">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Name}" 
                                                   Style="{StaticResource TextBlockBase}"
                                                   VerticalAlignment="Center"
                                                   TextTrimming="CharacterEllipsis"></TextBlock>
                                        <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
                                            <Button Content="{DynamicResource Edit}"
                                                    Margin="5"
                                                    Command="{Binding Path=DataContext.CmdEditCredential, RelativeSource={RelativeSource AncestorType={x:Type editor:ServerEditorPageView}}}" 
                                                    CommandParameter="{Binding}">
                                                <Button.Style>
                                                    <Style TargetType="Button" BasedOn="{StaticResource ButtonAccentStyle}">
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding IsEditable}" Value="False">
                                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Button.Style>
                                            </Button>
                                            <Button Content="{DynamicResource Delete}" 
                                                    Margin="5"
                                                    Command="{Binding Path=DataContext.CmdDeleteCredential, RelativeSource={RelativeSource AncestorType={x:Type editor:ServerEditorPageView}}}" 
                                                    CommandParameter="{Binding}">
                                            </Button>
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <Button Command="{Binding Path=DataContext.CmdEditCredential, RelativeSource={RelativeSource AncestorType={x:Type editor:ServerEditorPageView}}}"
                                Style="{StaticResource ButtonBarTransparentStyle}"
                                Margin="0 0 5 0">
                            <!--ADD BUTTON-->
                            <Grid Height="15" Width="15">
                                <Path Data="M 41.888 18.304 L 41.888 23.584 L 23.584 23.584 L 23.584 41.888 L 18.304 41.888 L 18.304 23.584 L 0 23.584 L 0 18.304 L 18.304 18.304 L 18.304 0 L 23.584 0 L 23.584 18.304 Z"
                                      Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      StrokeThickness="2" Stretch="Uniform" />
                            </Grid>
                        </Button>

                        <StackPanel>
                            <StackPanel.Style>
                                <Style TargetType="StackPanel">
                                    <Setter Property="IsEnabled" Value="True"></Setter>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding New.AlternateCredentials}" Value="{x:Null}">
                                            <Setter Property="IsEnabled" Value="False"></Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding New.AlternateCredentials.Count}" Value="0">
                                            <Setter Property="IsEnabled" Value="False"></Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </StackPanel.Style>
                            <CheckBox Content="{DynamicResource 'Automatic address switching'}" 
                                      IsChecked="{Binding New.IsAutoAlternateAddressSwitching}"
                                      Margin="0 5 0 0"></CheckBox>
                            <TextBlock TextWrapping="Wrap" Margin="0 0 0 5" Height="Auto" Opacity="0.7"
                                       Style="{StaticResource TextBlockBase}"
                                       Text="{DynamicResource 'When the default host or port is unavailable the alternate addresses will be tried in sequence'}">
                            </TextBlock>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Grid>
    </StackPanel>
</UserControl>
