<UserControl x:Class="PixiEditor.Views.UserControls.CommandSearch.CommandSearchControl"
             x:ClassModifier="internal"
             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:PixiEditor.Views.UserControls.CommandSearch"
             xmlns:behaves="clr-namespace:PixiEditor.Helpers.Behaviours"
             xmlns:cmdssearch="clr-namespace:PixiEditor.Models.Commands.Search"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             mc:Ignorable="d"
             Foreground="White"
             d:DesignHeight="450" d:DesignWidth="600"
             Width="600"
             x:Name="uc">
    <Grid x:Name="mainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBox Text="{Binding SearchTerm, Mode=TwoWay, ElementName=uc, UpdateSourceTrigger=PropertyChanged}" FontSize="17"
                 Padding="5"
                 x:Name="textBox">
            <i:Interaction.Behaviors>
                <behaves:TextBoxFocusBehavior SelectOnMouseClick="{Binding SelectAll, ElementName=uc, Mode=OneWay}" />
                <behaves:GlobalShortcutFocusBehavior />
            </i:Interaction.Behaviors>
            <TextBox.Style>
                <Style TargetType="TextBox" BasedOn="{StaticResource DarkTextBoxStyle}">
                    <Style.Resources>
                        <Style TargetType="Border">
                            <Setter Property="CornerRadius" Value="5,5,0,0" />
                        </Style>
                    </Style.Resources>
                </Style>
            </TextBox.Style>
        </TextBox>
        <Border Grid.Row="1" BorderThickness="1,0,1,0" BorderBrush="{StaticResource BrighterAccentColor}"
                Background="{StaticResource AccentColor}">
            <Grid>
                <TextBlock Text="{Binding Warnings, ElementName=uc}" TextAlignment="Center" Foreground="Gray" Margin="0,5,0,0"
                           Visibility="{Binding HasWarnings, Converter={BoolToVisibilityConverter}, ElementName=uc}"/>
                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                    <ItemsControl ItemsSource="{Binding Results, ElementName=uc}" x:Name="itemscontrol">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="cmdssearch:SearchResult">
                                <Button Padding="5" Height="40" BorderThickness="0" Background="Transparent"
                                        Command="{Binding ButtonClickedCommand, ElementName=uc}"
                                        CommandParameter="{Binding}"
                                        MouseMove="Button_MouseMove">
                                    <Button.Style>
                                        <Style TargetType="Button">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="Button">
                                                        <Border>
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Style.Triggers>
                                                                        <DataTrigger
                                                                            Binding="{Binding IsSelected, Mode=TwoWay}"
                                                                            Value="False">
                                                                            <Setter Property="Background"
                                                                                Value="Transparent" />
                                                                        </DataTrigger>
                                                                        <DataTrigger
                                                                            Binding="{Binding IsMouseSelected, Mode=TwoWay}"
                                                                            Value="False">
                                                                            <Setter Property="Background"
                                                                                Value="Transparent" />
                                                                        </DataTrigger>
                                                                        <DataTrigger
                                                                            Binding="{Binding IsMouseSelected, Mode=TwoWay}"
                                                                            Value="True">
                                                                            <Setter Property="Background"
                                                                                Value="{StaticResource BrighterAccentColor}" />
                                                                        </DataTrigger>
                                                                        <DataTrigger
                                                                            Binding="{Binding IsSelected, Mode=TwoWay}"
                                                                            Value="True">
                                                                            <Setter Property="Background"
                                                                                Value="{StaticResource AlmostLightModeAccentColor}" />
                                                                        </DataTrigger>
                                                                        <DataTrigger Binding="{Binding CanExecute}"
                                                                            Value="False">
                                                                            <Setter Property="Background"
                                                                                Value="Transparent" />
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                            <ContentPresenter />
                                                        </Border>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </Button.Style>
                                    <Button.Resources>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="FontSize" Value="16" />
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding CanExecute}" Value="True">
                                                    <Setter Property="Foreground" Value="White" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding CanExecute}" Value="False">
                                                    <Setter Property="Foreground" Value="Gray" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Resources>
                                    <Grid VerticalAlignment="Center" x:Name="dp" Margin="5,0,10,0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <StackPanel Orientation="Horizontal">
                                            <Border Width="25" Margin="0,0,5,0" Padding="1">
                                                <Image HorizontalAlignment="Center" Source="{Binding Icon}" />
                                            </Border>
                                            <TextBlock VerticalAlignment="Center"
                                                       behaves:TextBlockExtensions.BindableInlines="{Binding TextBlockContent}" />
                                        </StackPanel>
                                        <TextBlock Grid.Column="1" VerticalAlignment="Center"
                                                   HorizontalAlignment="Right" Text="{Binding Shortcut}" />
                                    </Grid>
                                </Button>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </Grid>
        </Border>
        <Border Grid.Row="2" BorderThickness="1" BorderBrush="{StaticResource BrighterAccentColor}"
                CornerRadius="0,0,5,5" Background="{StaticResource AccentColor}" Padding="3">
            <ContentPresenter Content="{Binding SelectedResult.Description, Mode=OneWay, ElementName=uc}"/>
        </Border>
    </Grid>
</UserControl>
