<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="using:SourceGit.ViewModels"
             xmlns:v="using:SourceGit.Views"
             xmlns:c="using:SourceGit.Converters"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="SourceGit.Views.ExecuteCustomActionCommandPalette"
             x:DataType="vm:ExecuteCustomActionCommandPalette">
  <Grid RowDefinitions="Auto,Auto,Auto">
    <v:RepositoryCommandPaletteTextBox Grid.Row="0"
                                       x:Name="FilterTextBox"
                                       Height="24"
                                       Margin="4,8,4,0"
                                       BorderThickness="1"
                                       CornerRadius="12"
                                       Text="{Binding Filter, Mode=TwoWay}"
                                       BorderBrush="{DynamicResource Brush.Border2}"
                                       VerticalContentAlignment="Center">
      <TextBox.InnerLeftContent>
        <StackPanel Orientation="Horizontal">
          <Path Width="14" Height="14"
                Margin="6,0,0,0"
                Fill="{DynamicResource Brush.FG2}"
                Data="{StaticResource Icons.Search}"/>
          <Border BorderThickness="0"
                  Background="{DynamicResource Brush.Badge}"
                  Height="18"
                  CornerRadius="4"
                  Margin="4,0,0,0" Padding="4,0">
            <TextBlock Text="{DynamicResource Text.Repository.CustomActions}"
                       Foreground="Black"
                       FontWeight="Bold"/>
          </Border>
        </StackPanel>
      </TextBox.InnerLeftContent>

      <TextBox.InnerRightContent>
        <Button Classes="icon_button"
                Width="16"
                Margin="0,0,6,0"
                Command="{Binding ClearFilter}"
                IsVisible="{Binding Filter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
                HorizontalAlignment="Right">
          <Path Width="14" Height="14"
                Margin="0,1,0,0"
                Fill="{DynamicResource Brush.FG1}"
                Data="{StaticResource Icons.Clear}"/>
        </Button>
      </TextBox.InnerRightContent>
    </v:RepositoryCommandPaletteTextBox>

    <TextBlock Grid.Row="1"
               Margin="6,12,0,0"
               Text="{DynamicResource Text.CommandPalette.RepositoryActions}"
               FontWeight="Bold"
               Foreground="{DynamicResource Brush.FG2}"/>

    <ListBox Grid.Row="2"
             x:Name="ActionListBox"
             MaxHeight="360"
             Margin="4,8"
             BorderThickness="0"
             SelectionMode="Single"
             Background="Transparent"
             Focusable="True"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             ScrollViewer.VerticalScrollBarVisibility="Auto"
             ItemsSource="{Binding VisibleActions, Mode=OneWay}"
             SelectedItem="{Binding Selected, Mode=TwoWay}"
             IsVisible="{Binding VisibleActions, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
      <ListBox.Styles>
        <Style Selector="ListBoxItem">
          <Setter Property="Padding" Value="8,0"/>
          <Setter Property="MinHeight" Value="26"/>
          <Setter Property="CornerRadius" Value="4"/>
        </Style>

        <Style Selector="ListBox">
          <Setter Property="FocusAdorner">
            <FocusAdornerTemplate>
              <Grid/>
            </FocusAdornerTemplate>
          </Setter>
        </Style>
      </ListBox.Styles>

      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <VirtualizingStackPanel Orientation="Vertical"/>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>

      <ListBox.ItemTemplate>
        <DataTemplate DataType="vm:ExecuteCustomActionCommandPaletteCmd">
          <Grid ColumnDefinitions="Auto,*,Auto" Background="Transparent" Tapped="OnItemTapped">
            <Path Grid.Column="0"
                  Width="12" Height="12"
                  Data="{StaticResource Icons.Action}"
                  IsHitTestVisible="False"/>
            <TextBlock Grid.Column="1"
                       Margin="4,0,0,0"
                       VerticalAlignment="Center"
                       IsHitTestVisible="False"
                       Text="{Binding Name, Mode=OneWay}"/>
            <Border Grid.Column="2" Margin="4,0,0,0" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center" IsVisible="{Binding IsGlobal}">
              <TextBlock Text="GLOBAL" Margin="8,0" FontSize="10" Foreground="White"/>
            </Border>
          </Grid>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>

    <Path Grid.Row="2"
          Width="64" Height="64"
          Margin="0,16,0,0"
          HorizontalAlignment="Center"
          VerticalAlignment="Center"
          Fill="{DynamicResource Brush.FG2}"
          Data="{StaticResource Icons.Empty}"
          IsVisible="{Binding VisibleActions, Mode=OneWay, Converter={x:Static c:ListConverters.IsNullOrEmpty}}"/>
  </Grid>
</UserControl>
