<UserControl
    DataContext="{Binding (HUDData.Data), RelativeSource={RelativeSource Self}}" 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:ForzaUI"
    mc:Ignorable="d"
    x:Class="ForzaUI.HUDWarningToastControl"
    x:Name="UserControl"
    Margin="0,23,0,0"
    VerticalAlignment="Top"
    HorizontalAlignment="Center">

    <UserControl.Resources>
        <ExponentialEase x:Key="A_EasingFunction_EaseIn" EasingMode="EaseIn"/>
        <CircleEase x:Key="A_EasingFunction_EaseOut" EasingMode="EaseOut"/>
        <CircleEase x:Key="A_EasingFunction_EaseInOut" EasingMode="EaseInOut"/>

        <Color x:Key="H_Color_WarningCategory">#FFFCEC2B</Color>

        <local:MappingConverter x:Key="A_MappingConverter_ToastType_To_HeaderColor">
            <local:MappingConverterEntry Key="{x:Static local:XAMLToastType.Danger}" Value="{StaticResource H_Color_Secondary_Negative}" />
            <local:MappingConverterEntry Key="{x:Static local:XAMLToastType.Warning}" Value="{StaticResource H_Color_WarningCategory}" />
        </local:MappingConverter>

        <Style x:Key="A_Style_Material_ToastCategory_TopBackground" TargetType="local:FZMaterial">
            <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterTopOnly4px}" />
            <Setter Property="Height" Value="36" />
            <Setter Property="Color" Value="{Binding ToastType, Converter={StaticResource A_MappingConverter_ToastType_To_HeaderColor}}" />
        </Style>

        <Style x:Key="A_Style_Material_ToastCategory_BottomBackground" TargetType="local:FZMaterial">
            <Setter Property="Preset" Value="{StaticResource H_GlassRoundtangle_Medium_4px_BottomOnly}" />
            <Setter Property="Color" Value="{StaticResource H_Color_Glass_Purple_40pc}" />
        </Style>

        <Style x:Key="H_Style_Text_ToastCategory_Title"
                   TargetType="FZTextBlock">
            <Setter Property="CapHeight" Value="15" />
            <Setter Property="FontFamily" Value="Horizon_C" />
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Black}" />
        </Style>

        <Style x:Key="A_Style_FZRun_Markup_ToastItem_HIGHLIGHT" TargetType="local:FZRun">
            <Setter Property="Color"  Value="{StaticResource H_Color_Primary_Yellow}"/>
        </Style>

        <MappingConverter x:Key="A_MappingConverter_ToastItem_Markup" >
            <MappingConverterEntry Key="{NoCase HIGHLIGHT}" Value="{StaticResource A_Style_FZRun_Markup_ToastItem_HIGHLIGHT}" />
        </MappingConverter>

        <Style x:Key="H_Style_Text_ToastItem_Text"
                   TargetType="FZTextBlock">
            <Setter Property="CapHeight" Value="15" />
            <Setter Property="FontFamily" Value="Horizon_B" />
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
            <Setter Property="MarkupConverter" Value="{StaticResource A_MappingConverter_ToastItem_Markup}" />
        </Style>

        <DataTemplate x:Key="A_DataTemplate_ToastItem">
            <DockPanel>
                <local:FZMaterial Color="{StaticResource H_Color_Primary_White}"
                                  Width="4" Height="4"
                                  Margin="10,10,0,0" 
                                  VerticalAlignment="Top"
                                  Visibility="{Binding HasListMarker, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                <local:FZTextBlock Style="{StaticResource H_Style_Text_ToastItem_Text}"
                                   Text="{Binding Text}"
                                   Margin="10,4"
                                   LineAdjust="-0.50"
                                   TextWrapping="Wrap"
                                   Stretch="None"/>
            </DockPanel>
        </DataTemplate>

        <Style x:Key="A_StackPanel_ToastCategory_Container" TargetType="StackPanel">
          <Style.Triggers>
            <DataTrigger Binding="{Binding Items.Count, Converter={StaticResource A_CompareConverter}, ConverterParameter=1}"
                         Value="{x:Static local:CompareResult.LessThan}">
              <Setter Property="Visibility" Value="Collapsed" />
            </DataTrigger>
          </Style.Triggers>
        </Style>

        <DataTemplate x:Key="A_DataTemplate_ToastCategory">
            <StackPanel Style="{StaticResource A_StackPanel_ToastCategory_Container}" 
                        MinWidth="320"
                        MaxWidth="600"
                        Margin="8,0,0,0">
                <Grid>
                    <local:FZMaterial Style="{StaticResource A_Style_Material_ToastCategory_TopBackground}" />
                    <local:FZTextBlock Style="{StaticResource H_Style_Text_ToastCategory_Title}"
                                       Text="{Binding Title}"
                                       VerticalAlignment="Center"
                                       Margin="10,0"/>
                </Grid>
                <Grid>
                    <local:FZMaterial Style="{StaticResource A_Style_Material_ToastCategory_BottomBackground}" />
                    <ItemsControl ItemsSource="{Binding Items}"
                                  ItemTemplate="{StaticResource A_DataTemplate_ToastItem}"
                                  Margin="0,4">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" IsItemsHost="True"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <UIVisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="PART_Hidden">
                    <UIStoryboard>
                        <UIStoryboard.TriggerAnimation>
                            <RaiseFzEvent TriggerAnimation.KeyTime="0:0:0" EventName="HiddenAnimationComplete"/>
                        </UIStoryboard.TriggerAnimation>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PART_LayoutRoot">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </UIStoryboard>
                </VisualState>
                <VisualState x:Name="PART_Shown">
                    <UIStoryboard>
                        <UIStoryboard.TriggerAnimation>
                            <RaiseFzEvent TriggerAnimation.KeyTime="0:0:4.0" EventName="ShownAnimationComplete"/>
                        </UIStoryboard.TriggerAnimation>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="-100"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" EasingFunction="{StaticResource A_EasingFunction_EaseOut}"/>
                        </DoubleAnimationUsingKeyFrames>
                        <UIStoryboard.TriggerAnimation>
                            <RaiseFzEvent EventName="ShowComplete" TriggerAnimation.KeyTime="0:0:3.3"/>
                        </UIStoryboard.TriggerAnimation>
                    </UIStoryboard>
                </VisualState>
            </UIVisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid x:Name="DisplayPanel" RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform />
                    <TranslateTransform />
                </TransformGroup>
            </Grid.RenderTransform>
            <ItemsControl ItemsSource="{Binding Categories}"
                          ItemTemplate="{StaticResource A_DataTemplate_ToastCategory}"
                          Margin="-8,0,0,0"
                          HorizontalAlignment="Center">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" IsItemsHost="True"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </Grid>
    </Grid>
</UserControl>