<UserControl
    x:Class="PowerLauncher.LauncherControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:PowerLauncher"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:p="clr-namespace:PowerLauncher.Properties"
    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
    d:DesignHeight="300"
    d:DesignWidth="720"
    mc:Ignorable="d">
    <UserControl.Resources>
        <Style
            x:Key="QueryTextBoxStyle"
            BasedOn="{StaticResource DefaultTextBoxStyle}"
            TargetType="{x:Type TextBox}">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
            <Setter Property="CaretBrush" Value="{DynamicResource TextFillColorPrimaryBrush}" />
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="AllowDrop" Value="true" />
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
            <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
            <Setter Property="Padding" Value="5,0,0,0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Grid>
                            <TextBlock
                                Margin="6,0,0,0"
                                VerticalAlignment="Center"
                                FontSize="{DynamicResource TitleFontSize}"
                                Text="{TemplateBinding Tag}">
                                <TextBlock.Style>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="Foreground" Value="Transparent" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=Text, RelativeSource={RelativeSource TemplatedParent}}" Value="">
                                                <Setter Property="Foreground" Value="{DynamicResource TextPlaceholderColorBrush}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                            <Border
                                x:Name="border"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="True">
                                <ScrollViewer
                                    x:Name="PART_ContentHost"
                                    Background="{TemplateBinding Background}"
                                    Focusable="false"
                                    HorizontalScrollBarVisibility="Hidden"
                                    VerticalScrollBarVisibility="Hidden">
                                    <ScrollViewer.ContentTemplate>
                                        <DataTemplate>
                                            <Grid Background="{Binding Background, ElementName=PART_ContentHost}">
                                                <ContentPresenter Content="{Binding Path=Content, ElementName=PART_ContentHost}" />
                                            </Grid>
                                        </DataTemplate>
                                    </ScrollViewer.ContentTemplate>
                                </ScrollViewer>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true" />
                        <Condition Property="IsSelectionActive" Value="false" />
                    </MultiTrigger.Conditions>
                    <Setter Property="SelectionBrush" Value="{DynamicResource TextOnAccentFillColorSelectedTextBrush}" />
                </MultiTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid
        MinHeight="32"
        Margin="8,12,8,12"
        VerticalAlignment="Top">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="38" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!--
            for adding on placeholder, look at the style with 90 votes
            https://stackoverflow.com/questions/11873378/adding-placeholder-text-to-textbox
        -->
        <local:CustomSearchBox
            x:Name="QueryTextBox"
            Grid.Column="1"
            MinHeight="0"
            Margin="0"
            VerticalAlignment="Center"
            x:FieldModifier="public"
            AutomationProperties.Name="{x:Static p:Resources.Query}"
            Canvas.ZIndex="0"
            FontSize="{DynamicResource TitleFontSize}"
            Style="{StaticResource QueryTextBoxStyle}"
            Tag="{x:Static p:Resources.startTyping}" />
        <TextBlock
            x:Name="AutoCompleteTextBlock"
            Grid.Column="1"
            Margin="7,0,7,0"
            VerticalAlignment="Center"
            x:FieldModifier="public"
            Canvas.ZIndex="-1"
            FontSize="{DynamicResource TitleFontSize}"
            Foreground="{DynamicResource TextPlaceholderColorBrush}" />
        <ui:SymbolIcon
            AutomationProperties.Name="{x:Static p:Resources.SearchIcon}"
            FontSize="20"
            Foreground="{DynamicResource TextPlaceholderColorBrush}"
            Symbol="Search12" />
    </Grid>
</UserControl>
