<UserControl
    x:Class="v2rayN.Desktop.Views.ClashProxiesView"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="using:v2rayN.Desktop.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
    xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
    d:DesignHeight="450"
    d:DesignWidth="800"
    x:DataType="vms:ClashProxiesViewModel"
    mc:Ignorable="d">
    <UserControl.Resources>
        <conv:DelayColorConverter x:Key="DelayColorConverter" />
    </UserControl.Resources>

    <DockPanel Margin="2">
        <WrapPanel
            Margin="{StaticResource Margin4}"
            VerticalAlignment="Center"
            DockPanel.Dock="Top"
            Orientation="Horizontal">

            <TextBlock
                Margin="{StaticResource MarginLr8}"
                VerticalAlignment="Center"
                Text="{x:Static resx:ResUI.menuRulemode}" />
            <ComboBox
                x:Name="cmbRulemode"
                Width="100"
                Margin="{StaticResource MarginLr8}">
                <ComboBoxItem Content="{x:Static resx:ResUI.menuModeRule}" />
                <ComboBoxItem Content="{x:Static resx:ResUI.menuModeGlobal}" />
                <ComboBoxItem Content="{x:Static resx:ResUI.menuModeDirect}" />
            </ComboBox>

            <TextBlock
                Margin="{StaticResource MarginLr8}"
                VerticalAlignment="Center"
                Text="{x:Static resx:ResUI.TbSorting}" />
            <ComboBox
                x:Name="cmbSorting"
                Width="100"
                Margin="{StaticResource MarginLr8}">
                <ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDelay}" />
                <ComboBoxItem Content="{x:Static resx:ResUI.TbSortingName}" />
                <ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDefault}" />
            </ComboBox>

            <Button
                x:Name="menuProxiesReload"
                Width="{StaticResource IconButtonWidth}"
                Height="{StaticResource IconButtonHeight}"
                Margin="{StaticResource MarginLr8}"
                Classes="Success"
                Theme="{DynamicResource BorderlessButton}"
                ToolTip.Tip="{x:Static resx:ResUI.menuProxiesReload}">
                <Button.Content>
                    <PathIcon Data="{StaticResource building_refresh}" Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
                </Button.Content>
            </Button>

            <Button
                x:Name="menuProxiesDelaytest"
                Width="{StaticResource IconButtonWidth}"
                Height="{StaticResource IconButtonHeight}"
                Margin="{StaticResource MarginLr8}"
                Classes="Success"
                Theme="{DynamicResource BorderlessButton}"
                ToolTip.Tip="{x:Static resx:ResUI.menuProxiesDelaytest}">
                <Button.Content>
                    <PathIcon Data="{StaticResource building_ping}" Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
                </Button.Content>
            </Button>

            <TextBlock
                Margin="{StaticResource MarginLr8}"
                VerticalAlignment="Center"
                Text="{x:Static resx:ResUI.TbAutoRefresh}" />
            <ToggleSwitch
                x:Name="togAutoRefresh"
                Margin="{StaticResource MarginLr8}"
                HorizontalAlignment="Left" />
        </WrapPanel>
        <DockPanel>
            <ListBox
                x:Name="lstProxyGroups"
                DockPanel.Dock="Left"
                ItemsSource="{Binding ProxyGroups}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Label
                            Width="160"
                            Margin="-4,-6"
                            Padding="0"
                            Theme="{DynamicResource TagLabel}">
                            <Grid Margin="{StaticResource Margin4}" RowDefinitions="1*,8,1*">
                                <DockPanel Grid.Row="0">
                                    <TextBlock DockPanel.Dock="Right" Text="{Binding Type}" />
                                    <TextBlock Text="{Binding Name}" />
                                </DockPanel>
                                <TextBlock Grid.Row="2" Text="{Binding Now}" />
                            </Grid>
                        </Label>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>

            <ListBox x:Name="lstProxyDetails" ItemsSource="{Binding ProxyDetails}">
                <ItemsControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem x:Name="menuProxiesDelaytestPart" Header="{x:Static resx:ResUI.menuProxiesDelaytestPart}" />
                        <MenuItem x:Name="menuProxiesSelectActivity" Header="{x:Static resx:ResUI.menuProxiesSelectActivity}" />
                    </ContextMenu>
                </ItemsControl.ContextMenu>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Label
                            Width="160"
                            Margin="-10,-6"
                            Padding="0"
                            Theme="{DynamicResource TagLabel}">
                            <DockPanel>
                                <Border
                                    Width="5"
                                    Margin="0,1"
                                    Background="YellowGreen"
                                    CornerRadius="4"
                                    DockPanel.Dock="Left"
                                    IsVisible="{Binding IsActive}" />
                                <Grid Margin="{StaticResource Margin4}" RowDefinitions="1*,8,1*">
                                    <TextBlock Grid.Row="0" Text="{Binding Name}" />
                                    <DockPanel Grid.Row="2">
                                        <TextBlock
                                            DockPanel.Dock="Right"
                                            Foreground="{Binding Path=Delay, Converter={StaticResource DelayColorConverter}}"
                                            Text="{Binding DelayName}" />
                                        <TextBlock Text="{Binding Type}" />
                                    </DockPanel>
                                </Grid>
                            </DockPanel>
                        </Label>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>
        </DockPanel>
    </DockPanel>
</UserControl>
