<reactiveui:ReactiveUserControl
    x:Class="v2rayN.Views.ClashProxiesView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:v2rayN.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:reactiveui="http://reactiveui.net"
    xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
    xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
    d:DesignHeight="450"
    d:DesignWidth="800"
    x:TypeArguments="vms:ClashProxiesViewModel"
    KeyDown="ProxiesView_KeyDown"
    Style="{StaticResource ViewGlobal}"
    mc:Ignorable="d">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
        <converters:DelayColorConverter x:Key="DelayColorConverter" />
    </UserControl.Resources>

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

            <TextBlock
                Margin="{StaticResource MarginLeftRight8}"
                VerticalAlignment="Center"
                Style="{StaticResource ToolbarTextBlock}"
                Text="{x:Static resx:ResUI.menuRulemode}" />
            <ComboBox
                x:Name="cmbRulemode"
                Width="100"
                Margin="{StaticResource MarginLeftRight8}"
                Style="{StaticResource DefComboBox}">
                <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 MarginLeftRight8}"
                VerticalAlignment="Center"
                Style="{StaticResource ToolbarTextBlock}"
                Text="{x:Static resx:ResUI.TbSorting}" />
            <ComboBox
                x:Name="cmbSorting"
                Width="100"
                Margin="{StaticResource MarginLeftRight8}"
                Style="{StaticResource DefComboBox}">
                <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="24"
                Height="24"
                Margin="{StaticResource MarginLeftRight8}"
                Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}"
                ToolTip="{x:Static resx:ResUI.menuProxiesReload}">
                <materialDesign:PackIcon VerticalAlignment="Center" Kind="Reload" />
            </Button>

            <Button
                x:Name="menuProxiesDelaytest"
                Width="24"
                Height="24"
                Margin="{StaticResource MarginLeftRight8}"
                Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}"
                ToolTip="{x:Static resx:ResUI.menuProxiesDelaytest}">
                <materialDesign:PackIcon VerticalAlignment="Center" Kind="LightningBolt" />
            </Button>

            <TextBlock
                Margin="{StaticResource MarginLeftRight8}"
                VerticalAlignment="Center"
                Style="{StaticResource ToolbarTextBlock}"
                Text="{x:Static resx:ResUI.TbAutoRefresh}" />
            <ToggleButton
                x:Name="togAutoRefresh"
                Margin="{StaticResource MarginLeftRight8}"
                HorizontalAlignment="Left" />
        </WrapPanel>
        <DockPanel>
            <ListView
                x:Name="lstProxyGroups"
                Margin="{StaticResource MarginRight8}"
                BorderThickness="0"
                DockPanel.Dock="Left"
                ItemContainerStyle="{StaticResource lvItemSelected}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Visible"
                Style="{StaticResource MaterialDesignListView}">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Border
                            Width="160"
                            Margin="{StaticResource MarginLeftRight4}"
                            Padding="0">
                            <DockPanel>
                                <Grid Grid.Column="0" Margin="{StaticResource Margin4}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <DockPanel Grid.Row="0">
                                        <TextBlock
                                            DockPanel.Dock="Right"
                                            Style="{StaticResource ListItemSubTitle}"
                                            Text="{Binding Type}" />
                                        <TextBlock Style="{StaticResource ListItemTitle}" Text="{Binding Name}" />
                                    </DockPanel>
                                    <TextBlock
                                        Grid.Row="1"
                                        Style="{StaticResource ListItemSubTitle}"
                                        Text="{Binding Now}" />
                                </Grid>
                            </DockPanel>
                        </Border>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

            <ListView
                x:Name="lstProxyDetails"
                BorderThickness="0"
                ItemContainerStyle="{StaticResource lvItemSelected}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Visible"
                Style="{StaticResource MaterialDesignListView}">
                <ListView.ContextMenu>
                    <ContextMenu Style="{StaticResource DefContextMenu}">
                        <MenuItem x:Name="menuProxiesDelaytestPart" Header="{x:Static resx:ResUI.menuProxiesDelaytestPart}" />
                        <MenuItem
                            x:Name="menuProxiesSelectActivity"
                            Header="{x:Static resx:ResUI.menuProxiesSelectActivity}"
                            InputGestureText="Enter" />
                    </ContextMenu>
                </ListView.ContextMenu>
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Border Width="160" Padding="0">
                            <DockPanel>
                                <Border
                                    Width="5"
                                    Height="auto"
                                    Margin="0,1"
                                    Background="{DynamicResource MaterialDesign.Brush.Primary.Light}"
                                    CornerRadius="4"
                                    DockPanel.Dock="Left"
                                    Visibility="{Binding Path=IsActive, Converter={StaticResource BoolToVisConverter}}" />
                                <Grid Margin="{StaticResource Margin4}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="2*" />
                                        <RowDefinition Height="1*" />
                                    </Grid.RowDefinitions>
                                    <TextBlock
                                        Grid.Row="0"
                                        Style="{StaticResource ListItemSubTitle}"
                                        Text="{Binding Name}"
                                        TextWrapping="WrapWithOverflow" />
                                    <DockPanel Grid.Row="1">
                                        <TextBlock
                                            DockPanel.Dock="Right"
                                            Foreground="{Binding Path=Delay, Converter={StaticResource DelayColorConverter}}"
                                            Style="{StaticResource ListItemSubTitle2}"
                                            Text="{Binding DelayName}" />
                                        <TextBlock Style="{StaticResource ListItemSubTitle2}" Text="{Binding Type}" />
                                    </DockPanel>
                                </Grid>
                            </DockPanel>
                        </Border>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </DockPanel>
    </DockPanel>
</reactiveui:ReactiveUserControl>
