<UserControl x:Class="NebulaAuth.View.ProxyManagerView"
             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:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:other="clr-namespace:NebulaAuth.ViewModel.Other"
             xmlns:nebulaAuth="clr-namespace:NebulaAuth"
             mc:Ignorable="d"
             d:DesignHeight="500" d:DesignWidth="400"
             d:DataContext="{d:DesignInstance other:ProxyManagerVM}"
             d:Background="#141119"
             d:Foreground="White"
             FontFamily="{md:MaterialDesignFont}"
             MinHeight="700"
             MinWidth="600"
             MaxHeight="700"
             MaxWidth="600"
             Background="Transparent"
             FontSize="16">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Margin="10,10,10,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal">
                <md:PackIcon Kind="Proxy" Width="20" Height="20" Margin="0,0,5,0" VerticalAlignment="Center"
                             Foreground="{DynamicResource PrimaryContentBrush}" />
                <TextBlock FontStyle="Normal" Foreground="{DynamicResource BaseContentBrush}"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center" FontSize="18" Text="{Tr ProxyManagerDialog.Title}" />
            </StackPanel>
            <Button Grid.Column="1" Width="30" Height="30" Style="{StaticResource MaterialDesignIconForegroundButton}"
                    HorizontalAlignment="Right" Command="{x:Static md:DialogHost.CloseDialogCommand}"
                    IsCancel="True">
                <md:PackIcon Kind="Close" Width="24" Height="24" Foreground="IndianRed" />
            </Button>
        </Grid>
        <Separator Grid.Row="1" />
        <Grid Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid Margin="15">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock HorizontalAlignment="Stretch">
                    <Run Text="{Tr ProxyManagerDialog.DefaultProxy, IsDynamic=False}" />
                    <Run Text="{Binding DefaultProxy.Key, StringFormat='&#x0a;0:', FallbackValue='-', Mode=OneWay}" />
                    <Run>
                        <Run.Text>
                            <MultiBinding Mode="OneWay"
                                          Converter="{StaticResource ProxyDataTextMultiConverter}">
                                <Binding Path="DefaultProxy.Value" />
                                <Binding Path="DataContext.DisplayProtocol"
                                         RelativeSource="{RelativeSource AncestorType=UserControl}" />
                                <Binding Path="DataContext.DisplayCredentials"
                                         RelativeSource="{RelativeSource AncestorType=UserControl}" />
                            </MultiBinding>
                        </Run.Text>
                    </Run>
                </TextBlock>

                <Button Grid.Column="1" Command="{Binding RemoveDefaultCommand}">
                    <md:PackIcon Kind="ClearBox" Width="20" Height="20" />
                </Button>

            </Grid>
            <StackPanel Grid.Row="1" Margin="15,0,15,15">
                <CheckBox Content="{Tr ProxyManagerDialog.DisplayProxyProtocol}" IsChecked="{Binding DisplayProtocol}" />
                <CheckBox Content="{Tr ProxyManagerDialog.DisplayProxyCredentials}"
                          IsChecked="{Binding DisplayCredentials}" />
            </StackPanel>
        </Grid>
        <md:Card Grid.Row="3" Margin="10">
            <ListBox VirtualizingStackPanel.VirtualizationMode="Recycling" FontSize="14"
                     SelectedValue="{Binding SelectedProxy}" ItemsSource="{Binding Proxies}">
                <ListBox.InputBindings>
                    <KeyBinding Key="Delete"
                                Command="{Binding DataContext.RemoveProxyCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
                </ListBox.InputBindings>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
                        <Setter Property="Tag"
                                Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext}" />
                        <Setter Property="ContextMenu">
                            <Setter.Value>
                                <ContextMenu>
                                    <MenuItem Header="{Tr MainWindow.ContextMenus.Proxy.Copy}"
                                              Command="{Binding PlacementTarget.Tag.CopyProxyCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                              CommandParameter="{Binding Value}" />
                                    <MenuItem Header="{Tr MainWindow.ContextMenus.Proxy.CopyAddress}"
                                              Command="{Binding PlacementTarget.Tag.CopyProxyAddressCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                              CommandParameter="{Binding Value}" />
                                    <MenuItem Header="{Tr Common.Delete}"
                                              Command="{Binding PlacementTarget.Tag.RemoveProxyCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                              CommandParameter="{Binding Value}" />
                                </ContextMenu>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />


                    </Style>
                </ListBox.ItemContainerStyle>

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock VerticalAlignment="Center">
                                <Run Text="{Binding Key, Mode=OneWay}" /><Run Text=": " />
                                <Run>
                                    <Run.Text>
                                        <MultiBinding Mode="OneWay"
                                                      Converter="{StaticResource ProxyDataTextMultiConverter}">
                                            <Binding Path="Value" />
                                            <Binding Path="DataContext.DisplayProtocol"
                                                     RelativeSource="{RelativeSource AncestorType=UserControl}" />
                                            <Binding Path="DataContext.DisplayCredentials"
                                                     RelativeSource="{RelativeSource AncestorType=UserControl}" />
                                        </MultiBinding>
                                    </Run.Text>
                                </Run>

                            </TextBlock>
                            <Button Style="{StaticResource MaterialDesignIconButton}" Padding="0" Width="24"
                                    Height="24" md:RippleAssist.IsDisabled="True" Grid.Column="1"
                                    HorizontalAlignment="Right"
                                    Command="{Binding DataContext.SetDefaultCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                    CommandParameter="{Binding}">
                                <md:PackIcon Height="16" Width="16" Kind="Heart" />
                            </Button>

                        </Grid>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </md:Card>
        <Grid Grid.Row="4" Margin="5,0,15,0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <nebulaAuth:HintBox
                Visibility="{Binding ErrorText, Converter={StaticResource NullableToVisibilityConverter}}"
                Margin="15,0,15,0"
                Grid.Row="0"
                Severity="Error"
                FontSize="14"
                Text="{Binding ErrorText}"
                CloseCommand="{Binding ClearErrorCommand}"
                ShowCloseButton="True" />

            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <TextBox Text="{Binding AddProxyField}"
                         KeyDown="ProxyInput_KeyDown"
                         FontSize="12"
                         md:TextFieldAssist.HasClearButton="True"
                         AcceptsReturn="True"
                         MaxHeight="100" Style="{StaticResource MaterialDesignOutlinedTextBox}"
                         Margin="15"
                         Height="90"
                         md:HintAssist.IsFloating="False"
                         md:HintAssist.Hint="IP:PORT&#x0a;IP:PORT:USER:PASS&#x0a;PROTOCOL://IP:PORT:USER:PASS&#x0a;IP:PORT:USER:PASS{ID}
                     " />
                <Button x:Name="AddProxyBtn" ToolTip="CTRL+ENTER" IsDefault="True" Grid.Column="1" Height="90"
                        Command="{Binding AddProxyCommand}">
                    <md:PackIcon Kind="Add" />
                </Button>
                <Button Grid.Column="2" Height="90" Command="{Binding RemoveProxyCommand}" CommandParameter="{x:Null}">
                    <md:PackIcon Kind="Trash" />
                </Button>
            </Grid>

        </Grid>


    </Grid>
</UserControl>