<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">

    <!-- RECIPE MATERIAL ITEM TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <ControlTemplate x:Key="Template.MaterialItem" TargetType="{x:Type ListBoxItem}">
        <Grid Background="{DynamicResource Color.Background.RecipeMaterialItem}" Margin="0,0,0,4">

            <!-- The ContentPresenter renders content inside of the item -->
            <ContentPresenter
                Width="472"
                HorizontalAlignment="Center"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        </Grid>
    </ControlTemplate>

    <!-- RECIPE MATERIAL ITEM DATA TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <DataTemplate x:Key="Content.MaterialItem">
        <!-- This part displays the content of the Material Item - the item icon, amount owned and amount required -->
        <Grid Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <!-- This displays the default background  -->
            <Border x:Name="SlotItemBase" Style="{DynamicResource SlotBaseStyle}" Grid.Column="0">

                <!-- This displays the internal slot border -->
                <Border x:Name="SlotItemBorder" Style="{DynamicResource SlotBorderStyle}">
                    <Grid>
                        <Image
                            x:Name="Material.Icon"
                            Style="{DynamicResource SlotItemIconStyle}"
                            Source="{Binding Icon}"/>

                        <TextBlock
                            x:Name="Material.Amount"
                            Style="{DynamicResource SlotItemAmountStyle}"
                            Text="{Binding AmountOwned}"/>
                    </Grid>
                </Border>
            </Border>

            <TextBlock
                x:Name="Material.Name"
                Grid.Column="1"
                Text="{Binding Name}"
                FontFamily="{DynamicResource Font.CoreSans}"
                FontSize="{DynamicResource Font.Size.Body}"
                Foreground="{DynamicResource Color.Text}"
                TextAlignment="Left"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Margin="12,0,0,0"/>

            <TextBlock
                Grid.Column="2"
                FontFamily="{DynamicResource Font.CoreSans}"
                FontSize="{DynamicResource Font.Size.Body}"
                Foreground="{DynamicResource Color.Text}"
                TextAlignment="Right"
                HorizontalAlignment="Right"
                VerticalAlignment="Center">

                <Run x:Name="Material.AmountOwned" Text="{Binding AmountOwned}"/>
                <Run Text="/"/>
                <Run x:Name="Material.DisplayAmountRequired" Text="{Binding DisplayAmountRequired}"/>
            </TextBlock>

        </Grid>

        <!-- This trigger changes the color of Material.AmountOwned to red when the player doesn't have enough of this material to craft the recipe -->
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding HasEnough}" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource Color.TextError}" TargetName="Material.AmountOwned"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding HasEnough}" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource Color.TextAdd}" TargetName="Material.AmountOwned"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!-- RECIPE MATERIAL ITEM STYLE -->
    <!--////////////////////////////////////////////////////////////////////-->
    <Style x:Key="Style.MaterialItem" TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ContentControl}}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Height" Value="80" />
        <Setter Property="Template" Value="{StaticResource Template.MaterialItem}" />
    </Style>
</ResourceDictionary>
