<UserControl 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,0"
             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="A_Duration_Warning">0:0:5.0</Duration>

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

            <Storyboard x:Key="A_Storyboard_CountdownWarning">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="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="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="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="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="LayoutRoot"
          Opacity="0">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:1.0" To="Countdown" Storyboard="{StaticResource A_Storyboard_Transition_AnyToCountdown}"/>
                    <VisualTransition GeneratedDuration="0:0:1.0" To="CountdownWarning" Storyboard="{StaticResource A_Storyboard_Transition_AnyToCountdownWarning}"/>
                    <VisualTransition GeneratedDuration="0:0:0.2" From="Countdown" To="CountdownWarning" Storyboard="{StaticResource A_Storyboard_Transition_CountdownToCountdownWarning}"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Hidden"/>
                <VisualState x:Name="Countdown" Storyboard="{StaticResource A_Storyboard_Countdown}"/>
                <VisualState x:Name="CountdownWarning" Storyboard="{StaticResource A_Storyboard_CountdownWarning}"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel>
            <local:FZTextBlock Text="{Binding Text}" 
                               Style="{StaticResource A_Style_FZTextBlock_HudMedium}"
                               HorizontalAlignment="Center"
                               Margin="0,0,0,8"/>
            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetGlass_HudItem}" Color="{StaticResource A_Color_GlassPanel_NonInteractive}">
                <local:FZTextBlock x:Name="Time" Text="{Binding Time}" 
                                   Style="{StaticResource A_Style_FZTextBlock_HudLarge_Tight}" 
                                   Color="{StaticResource A_Color_HUD_AlternateText}"
                                   CapHeight="42"
                                   HorizontalAlignment="Center"
                                   Margin="18,17"/>
            </local:FZMaterial>
        </StackPanel>
    </Grid>
</UserControl>
