<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:local="clr-namespace:NebulaAuth.View"
             xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:other="clr-namespace:NebulaAuth.ViewModel.Other"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800"
             Foreground="WhiteSmoke"
             FontFamily="{md:MaterialDesignFont}"
             MinHeight="500"
             MinWidth="400"
             MaxHeight="550"
             d:DataContext="{d:DesignInstance other:ProxyManagerVM}"
             Background="{DynamicResource WindowBackground}">
    <d:DesignerProperties.DesignStyle>
        <Style TargetType="UserControl">
            <Setter Property="Background" Value="{DynamicResource WindowBackground}" />
        </Style>
    </d:DesignerProperties.DesignStyle>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="10" FontStyle="Normal" Foreground="DarkGray" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="18" Text="{Tr ProxyManagerDialog.Title}"/>
            <Button Margin="0,0,10,0" IsCancel="True" Grid.Column="1" Width="30" Height="30" Style="{StaticResource MaterialDesignIconForegroundButton}" HorizontalAlignment="Right" Command="{x:Static md:DialogHost.CloseDialogCommand}">
                <md:PackIcon Kind="Close" Width="24" Height="24" Foreground="IndianRed"></md:PackIcon>
            </Button>

        </Grid>
        <Separator Grid.Row="1"></Separator>
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock HorizontalAlignment="Stretch" 
                       Margin="15" FontSize="16">
                <Run  Text="{Tr ProxyManagerDialog.DefaultProxy, IsDynamic=False}"/>
                <Run Text="{Binding DefaultProxy.Key, StringFormat='&#x0a;0:', FallbackValue='-', Mode=OneWay}"/>
                <Run Text="{Binding DefaultProxy.Value, Converter='{StaticResource ProxyDataTextConverter}', Mode=OneWay, FallbackValue=''}"/>
            </TextBlock>

            <Button Grid.Column="1" Command="{Binding RemoveDefaultCommand}" Cursor="Hand">
                <md:PackIcon Kind="ClearBox" Width="20" Height="20"></md:PackIcon>
            </Button>
        </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}"/>
                                </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 Text="{Binding Value, Mode=OneWay, Converter={StaticResource ProxyDataTextConverter}}"/>

                            </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"></md:PackIcon>
                            </Button>
                           
                        </Grid>
                      
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </md:Card>
        <Grid Grid.Row="4" Margin="5,0,15,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBox Text="{Binding AddProxyField}" FontSize="12"  md:TextFieldAssist.HasClearButton="True" AcceptsReturn="True" MaxHeight="100" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="15" md:HintAssist.Hint="IP:PORT:USER:PASS{ID}"></TextBox>
            <Button IsDefault="True" Grid.Column="1"  Command="{Binding AddProxyCommand}">
                <md:PackIcon Kind="Add"></md:PackIcon>
            </Button>
            <Button Grid.Column="2" Command="{Binding RemoveProxyCommand}">
                <md:PackIcon Kind="Trash"></md:PackIcon>
            </Button>
        </Grid>


    </Grid>
</UserControl>
