<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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:ForzaUI"
             mc:Ignorable="d"
             x:Class="ForzaUI.HUDRaceFinishCountdownControl"
             Margin="0,0,0,29"
             HorizontalAlignment="Center"
             VerticalAlignment="Bottom">

    <UserControl.Resources>
        <ResourceDictionary>
            <!-- Do not change key of A_Duration_Warning; it is referred to by key in code -->
            <Duration x:Key="PART_A_Duration_Warning">0:0:5.0</Duration>

            <Storyboard x:Key="A_Storyboard_Countdown">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                    <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_CountdownWarning">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                    <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(local:FZTextBlock.Color)" Storyboard.TargetName="Time">
                    <EasingColorKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Color_Tile_Selected}"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Transition_AnyToCountdown">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                    <EasingDoubleKeyFrame KeyTime="0:0:1.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Transition_AnyToCountdownWarning">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                    <EasingDoubleKeyFrame KeyTime="0:0:1.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(local:FZTextBlock.Color)" Storyboard.TargetName="Time">
                    <EasingColorKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Color_Tile_Selected}"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Transition_CountdownToCountdownWarning">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                    <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(local:FZTextBlock.Color)" Storyboard.TargetName="Time">
                    <EasingColorKeyFrame KeyTime="0:0:0.2" Value="{StaticResource A_Color_Tile_Selected}"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>

        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot"
          Opacity="0">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:1.0" To="PART_Countdown" Storyboard="{StaticResource A_Storyboard_Transition_AnyToCountdown}"/>
                    <VisualTransition GeneratedDuration="0:0:1.0" To="PART_CountdownWarning" Storyboard="{StaticResource A_Storyboard_Transition_AnyToCountdownWarning}"/>
                    <VisualTransition GeneratedDuration="0:0:0.2" From="PART_Countdown" To="PART_CountdownWarning" Storyboard="{StaticResource A_Storyboard_Transition_CountdownToCountdownWarning}"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="PART_Hidden"/>
                <VisualState x:Name="PART_Countdown" Storyboard="{StaticResource A_Storyboard_Countdown}"/>
                <VisualState x:Name="PART_CountdownWarning" Storyboard="{StaticResource A_Storyboard_CountdownWarning}"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel>
            <local:FZTextBlock Text="{Binding Text}" 
                               Style="{StaticResource A_Style_FZTextBlock_HudMedium}"
                               HorizontalAlignment="Center"
                               FontFamily="Horizon_A"
                               CapHeight="18"
                               RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                               Margin="0,0,0,8"/>
            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetGlass_HudItem}" Color="{StaticResource H_Color_Glass_Purple_20pc}">
                <Decorator RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" Margin="18,14,16,16">
                    <local:FZTextBlock x:Name="Time" Text="{Binding Time}" 
                                       Style="{StaticResource A_Style_FZTextBlock_HudLarge_Tight}" 
                                       Color="{StaticResource H_Color_Primary_Yellow}"
                                       CapHeight="38"
                                       FontFamily="Horizon_A_tf"
                                       HorizontalAlignment="Center"/>
                </Decorator>
            </local:FZMaterial>
        </StackPanel>
    </Grid>
</UserControl>
