<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:system="clr-namespace:System;assembly=mscorlib">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Tooltip.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!-- REQUIREMENT SLOT TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <ControlTemplate x:Key="Template.SlotRequirement" TargetType="{x:Type ListBoxItem}">

        <!-- This is the Requirement Slot parent container -->
        <Grid x:Name="SlotRequirement.Layout"
              Style="{DynamicResource Style.SlotInput.Layout}">

            <!-- STATE MANAGER -->
            <!-- This part defines the slot states and the animations they trigger -->
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup Name="CommonStates">

                    <!-- NORMAL STATE -->
                    <VisualState Name="Normal"/>

                    <!-- HOVERED STATE -->
                    <VisualState Name="MouseOver">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames
                                    Storyboard.TargetName="SlotRequirement.Hover"
                                    Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>

                            <DoubleAnimation
                                    Storyboard.TargetName="SlotRequirement.Hover"
                                    Storyboard.TargetProperty="Opacity"
                                    To="1"
                                    Duration="0:0:0.2">
                                <DoubleAnimation.EasingFunction>
                                    <QuarticEase EasingMode="EaseOut"/>
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>

                            <DoubleAnimation
                                    Storyboard.TargetName="BorderHoveredScale"
                                    Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
                                    To="1"
                                    Duration="0:0:0.2">
                                <DoubleAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut" Power="4"/>
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>

                            <DoubleAnimation
                                    Storyboard.TargetName="BorderHoveredScale"
                                    Storyboard.TargetProperty="(ScaleTransform.ScaleY)"
                                    To="1"
                                    Duration="0:0:0.2">
                                <DoubleAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut" Power="4"/>
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>
                        </Storyboard>
                    </VisualState>

                    <!-- PRESSED STATE -->
                    <VisualState Name="Pressed"/>

                    <!-- DISABLED STATE -->
                    <VisualState Name="Disabled">
                        <Storyboard>
                            <DoubleAnimation
                                    Storyboard.TargetName="SlotRequirement.Layout"
                                    Storyboard.TargetProperty="Opacity"
                                    To="0.6"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <!-- This part displays the border and glow we show on hover over the slot -->
            <Border
                x:Name="SlotRequirement.Hover"
                Style="{DynamicResource SlotHoveredStyle}"
                Visibility="Hidden"
                Opacity="0"
                RenderTransformOrigin="0.5,0.5">

                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform x:Name="BorderHoveredScale" ScaleX="0.9" ScaleY="0.9"/>
                    </TransformGroup>
                </Border.RenderTransform>
            </Border>

            <!-- This displays the default background  -->
            <Border
                x:Name="SlotRequirement.Base"
                Style="{DynamicResource Style.SlotInput.Base}">

                <!-- This displays the internal slot border -->
                <Border
                    x:Name="SlotRequirement.Border"
                    Style="{DynamicResource SlotBorderStyle}">


                    <!-- The ContentPresenter renders content inside of the item -->
                    <ContentPresenter
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Border>
            </Border>

            <!-- This displays a tooltip when the player hovers over the slot -->
            <ToolTipService.ToolTip>
                <ToolTip Style="{StaticResource Style.Tooltip.Default}" Content="{StaticResource Content.Tooltip.Material}"/>
            </ToolTipService.ToolTip>
        </Grid>
    </ControlTemplate>

    <!-- REQUIREMENT SLOT DATA TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <DataTemplate x:Key="Content.SlotRequirement">
        <!-- This part displays the content of the Requirement Slot -->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="20"/>
            </Grid.RowDefinitions>

            <!-- Displays the requirement icon -->
            <Image
                x:Name="Requirement.Icon"
                Style="{DynamicResource SlotItemIconStyle}"
                Source="{Binding Icon}"/>

            <!-- The Requirement.Check grid displays a checkmark or a cross based on whether the player meets the requirement or not -->
            <Grid
                x:Name="Requirement.Check"
                Background="{DynamicResource Color.BorderSlot}"
                Grid.Row="1"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">

                <Image
                    x:Name="SlotRequirement.Pass"
                    Source="../Textures/Icons/IconCheckmark.png"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Visibility="Hidden"/>

                <Image
                    x:Name="SlotRequirement.Fail"
                    Source="../Textures/Icons/IconCross.png"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Visibility="Hidden"/>
            </Grid>
        </Grid>

        <!-- These triggers toggle the visibility of the checkmark and cross icons in Requirement.Check -->
        <!-- If the player meets the requirement than SlotRequirement.Pass is set to Visible -->
        <!-- If the player does not meet the requirement than SlotRequirement.Fail is set to Visible -->
        <!-- Currently, the triggers are using the HasEnough binding which is meant for the Input Materials check -->
        <!-- Once Sandbox implements the Requirements functionality in Crafting we will update this with a new binding -->
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding HasEnough}" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="SlotRequirement.Pass"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding HasEnough}" Value="False">
                <Setter Property="Visibility" Value="Visible" TargetName="SlotRequirement.Fail"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!-- REQUIREMENT SLOT STYLE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <Style x:Key="Style.SlotRequirement" TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ContentControl}}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="FocusVisualStyle" Value="{DynamicResource Style.Focus}" />
        <Setter Property="Template" Value="{StaticResource Template.SlotRequirement}" />
    </Style>
</ResourceDictionary>
