<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:NoesisGUIExtensions">

    <!-- PLACEHOLDER TEXT STYLE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <Style x:Key="Style.TextBox.PlaceholderText" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{DynamicResource Color.TextPlaceholder}"/>

        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource Color.TextDisable}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- TEXT BOX TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <!-- This is the base TextBox template -->
    <ControlTemplate x:Key="Template.TextBox" TargetType="TextBox">
        <Grid>
            <!-- The TextBox.Base defines the TextBox container over which we render its content -->
            <Border
                x:Name="TextBox.Base"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="2"
                CornerRadius="4"/>

            <Grid>
                <!-- The Placeholder renders any placeholder text set via the Placeholder property -->
                <!-- It's collapsed by default and only displayed if a placeholder text is set and the player hasn't typed anything in the TextBox -->
                <Border
                    x:Name="Placeholder"
                    Padding="{TemplateBinding Padding}"
                    Margin="2,0"
                    Visibility="Collapsed">

                    <TextBlock
                        Text="{Binding (local:Text.Placeholder), RelativeSource={RelativeSource TemplatedParent}}"
                        Style="{StaticResource Style.TextBox.PlaceholderText}"
                        VerticalAlignment="Center"/>
                </Border>

                <!-- The ScrollViewer renders the typed text content in the TextBox -->
                <!-- We use a ScrollViewer and not a ContentPresenter so that we can ensure the text is scrollable if it's too long to fit in the TextBox -->
                <ScrollViewer
                    x:Name="PART_ContentHost"
                    Focusable="False"
                    Padding="{TemplateBinding Padding}"
                    Foreground="{TemplateBinding Foreground}"/>
            </Grid>
        </Grid>

        <ControlTemplate.Triggers>
            <!-- This trigger displays the Placeholder text when there is typed text in the TextBox -->
            <Trigger Property="Text" Value="">
                <Setter Property="Visibility" Value="Visible" TargetName="Placeholder"/>
            </Trigger>

            <!-- These triggers define the property changes that happen in the different interactive states of the TextBox -->
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Hover}"/>
            </Trigger>

            <Trigger Property="IsFocusEngaged" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Active}"/>
            </Trigger>

            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Disable}"/>
                <Setter Property="Foreground" Value="{DynamicResource Color.TextDisable}"/>
                <Setter Property="Background" Value="{DynamicResource Color.Background.Control.Disable}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- TEXT BOX STYLE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <Style x:Key="Style.TextBox" TargetType="TextBox" BasedOn="{StaticResource {x:Type Control}}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="{DynamicResource Color.Background.Control}"/>
        <Setter Property="Foreground" Value="{DynamicResource Color.Text}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control}"/>
        <Setter Property="CaretBrush" Value="{DynamicResource Brush.Foreground.Normal}"/>
        <Setter Property="SelectionBrush" Value="{DynamicResource Color.Background.Control.TextSelection}"/>
        <Setter Property="SelectionOpacity" Value="0.5"/>
        <Setter Property="Padding" Value="12,0,12,0"/>
        <Setter Property="Height" Value="42"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="FocusVisualStyle" Value="{DynamicResource Style.Focus}"/>
        <Setter Property="IsFocusEngagementEnabled" Value="True"/>
        <Setter Property="FontFamily" Value="{DynamicResource Font.CoreSans}"/>
        <Setter Property="FontSize" Value="{DynamicResource Font.Size.Default}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource Template.TextBox}"/>

        <!-- This trigger renders the Caret cursor when the TextBox is enabled -->
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Cursor" Value="IBeam"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- TEXT BOX SEARCH TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <!-- This template defines a unique variant of the TextBox as a search field -->
    <ControlTemplate x:Key="Template.TextBox.Search" TargetType="TextBox">
        <Grid>
            <!-- The TextBox.Base defines the TextBox container over which we render its content -->
            <Border
                x:Name="TextBox.Base"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="2"
                CornerRadius="4"/>

            <Grid>
                <!-- The Placeholder renders any placeholder text set via the Placeholder property -->
                <!-- It's collapsed by default and only displayed if a placeholder text is set and the player hasn't typed anything in the TextBox -->
                <Border
                    x:Name="Placeholder"
                    Padding="{TemplateBinding Padding}"
                    Margin="2,0"
                    Visibility="Collapsed">

                    <TextBlock
                        Text="{Binding (local:Text.Placeholder), RelativeSource={RelativeSource TemplatedParent}}"
                        Style="{StaticResource Style.TextBox.PlaceholderText}"
                        VerticalAlignment="Center"/>
                </Border>

                <!-- The ScrollViewer renders the typed text content in the TextBox -->
                <!-- We use a ScrollViewer and not a ContentPresenter so that we can ensure the text is scrollable if it's too long to fit in the TextBox -->
                <ScrollViewer
                    x:Name="PART_ContentHost"
                    Focusable="False"
                    Padding="{TemplateBinding Padding}"
                    Foreground="{TemplateBinding Foreground}"/>
            </Grid>

            <!-- The Icon displays a magnifying glass icon in the TextBox to communicate the players it acts as a search field -->
            <Image
                x:Name="Icon"
                Source="../Textures/Icons/IconSearch.png"
                Width="16"
                Height="16"
                HorizontalAlignment="Right"
                VerticalAlignment="Center"
                Margin="0,0,16,0"/>
        </Grid>

        <ControlTemplate.Triggers>
            <!-- This trigger displays the Placeholder text when there is typed text in the TextBox -->
            <Trigger Property="Text" Value="">
                <Setter Property="Visibility" Value="Visible" TargetName="Placeholder"/>
            </Trigger>

            <!-- These triggers define the property changes that happen in the different interactive states of the TextBox -->
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Hover}"/>
            </Trigger>

            <Trigger Property="IsFocusEngaged" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Active}"/>
            </Trigger>

            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control.Disable}"/>
                <Setter Property="Foreground" Value="{DynamicResource Color.TextDisable}"/>
                <Setter Property="Background" Value="{DynamicResource Color.Background.Control.Disable}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- TEXT BOX SEARCH STYLE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <Style x:Key="Style.TextBox.Search" TargetType="TextBox" BasedOn="{StaticResource {x:Type Control}}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="{DynamicResource Color.Background.Control}"/>
        <Setter Property="Foreground" Value="{DynamicResource Color.Text}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource Color.Border.Control}"/>
        <Setter Property="CaretBrush" Value="{DynamicResource Brush.Foreground.Normal}"/>
        <Setter Property="SelectionBrush" Value="{DynamicResource Color.Background.Control.TextSelection}"/>
        <Setter Property="SelectionOpacity" Value="0.5"/>
        <Setter Property="Padding" Value="12,0,40,0"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="FocusVisualStyle" Value="{DynamicResource Style.Focus}"/>
        <Setter Property="IsFocusEngagementEnabled" Value="True"/>
        <Setter Property="FontFamily" Value="{DynamicResource Font.CoreSans}"/>
        <Setter Property="FontSize" Value="{DynamicResource Font.Size.Default}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource Template.TextBox.Search}"/>

        <!-- This trigger renders the Caret cursor when the TextBox is enabled -->
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Cursor" Value="IBeam"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>
