<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.HUDNetworkStatusControl"
    Margin="0,13,0,0"
    VerticalAlignment="Top"
    HorizontalAlignment="Center">

    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="A_Style_FZTextBlock_NetworkStatus" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HudMedium}">
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="TextAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="TextWrapping" Value="NoWrap"/>
                <Setter Property="CapHeight" Value="19" />
                <Setter Property="local:ScreenReader.LineType" Value="NetworkStatusText"/>
                <Setter Property="local:ScreenReader.Event" Value="OnChange"/>
                <Setter Property="local:ScreenReader.Line" Value="{Binding TextScreenReader, Converter={StaticResource A_Converter_TrimInlineMarkup}}"/>
                <Setter Property="local:ScreenReader.InterruptBehavior" Value="CancelAllExceptPlaying"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="{x:Static Visibility.Collapsed}">
                        <Setter Property="TextWrapping" Value="Wrap" />
                        <Setter Property="MaxWidth" Value="600" />
                        <Setter Property="LineHeight" Value="25" />
                        <Setter Property="LineStackingStrategy" Value="BlockLineHeight" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_NetworkStatusSubtext" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_NetworkStatus}">
                <Setter Property="local:ScreenReader.LineType" Value="NetworkStatusSubtext"/>
                <Setter Property="local:ScreenReader.Line" Value="{Binding SubtextScreenReader, Converter={StaticResource A_Converter_TrimInlineMarkup}}"/>
            </Style>
            
            <Style x:Key="A_Style_FZRun_NetworkStatusMarkup_HIGHLIGHT" TargetType="{x:Type local:FZRun}">
                <Setter Property="Color" Value="{StaticResource A_Color_HUD_AlternateText}"/>
            </Style>

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

            <Style x:Key="A_Style_StackPanel_LatencyMargin" TargetType="StackPanel">
                <Setter Property="Margin" Value="13,12,13,11" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding HasLatencyIcon}" Value="True">
                        <Setter Property="Margin" Value="13,6"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot">
        <Grid.Resources>
            <QuadraticEase x:Key="A_EasingFunction_EaseIn" EasingMode="EaseIn"/>
            <QuadraticEase x:Key="A_EasingFunction_EaseOut" EasingMode="EaseOut"/>

            <Storyboard x:Key="A_Storyboard_Show_Indefinite">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Hidden">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Show_3Seconds">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(local:EventFire.EventName)" Storyboard.TargetName="EventFire">
                    <DiscreteStringKeyFrame KeyTime="0:0:0.0" Value=""/>
                    <DiscreteStringKeyFrame KeyTime="0:0:3.0" Value="Expired"/>
                    <DiscreteStringKeyFrame KeyTime="0:0:3.2" Value=""/>
                </StringAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Show_5Seconds">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(local:EventFire.EventName)" Storyboard.TargetName="EventFire">
                    <DiscreteStringKeyFrame KeyTime="0:0:0.0" Value=""/>
                    <DiscreteStringKeyFrame KeyTime="0:0:5.0" Value="Expired"/>
                    <DiscreteStringKeyFrame KeyTime="0:0:5.2" Value=""/>
                </StringAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Hidden_To_Any">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1" EasingFunction="{StaticResource A_EasingFunction_EaseOut}"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

            <Storyboard x:Key="A_Storyboard_Any_To_Hidden">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TextBlock">
                    <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="0" EasingFunction="{StaticResource A_EasingFunction_EaseIn}"/>
                </DoubleAnimationUsingKeyFrames>
                <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(local:EventFire.EventName)" Storyboard.TargetName="EventFire">
                    <DiscreteStringKeyFrame KeyTime="0:0:0.0" Value=""/>
                    <DiscreteStringKeyFrame KeyTime="0:0:0.25" Value="Finished"/>
                    <DiscreteStringKeyFrame KeyTime="0:0:0.27" Value=""/>
                </StringAnimationUsingKeyFrames>
            </Storyboard>

        </Grid.Resources>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="PART_Hidden" Storyboard="{StaticResource A_Storyboard_Hidden}"/>
                <VisualState x:Name="PART_RaceStarting" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_ActionForbidden" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_LeaderChange" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_PlayerLeft" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_PlayerJoined" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_PlayerJoining" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_ConvoySynchronizing" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_OnlyPlayerPrompt" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_MatchMakingComplete" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_MatchMakingProgress" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_EventProgress" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_BucketListWaitPlayer" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_BucketListStarted" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_BucketListEnded" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_LatencyWarning" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_PartyStatus" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_ScheduledEventSignup" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualState x:Name="PART_ScheduledEventCountdown" Storyboard="{StaticResource A_Storyboard_Show_Indefinite}"/>
                <VisualState x:Name="PART_EliminatorPlayerEliminated" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_EliminatorActivityNotice" Storyboard="{StaticResource A_Storyboard_Show_3Seconds}"/>
                <VisualState x:Name="PART_QuickChatPartyState" Storyboard="{StaticResource A_Storyboard_Show_5Seconds}"/>
                <VisualStateGroup.Transitions>
                    <VisualTransition From="PART_Hidden" GeneratedDuration="0:0:0.25" Storyboard="{StaticResource A_Storyboard_Hidden_To_Any}"/>
                    <VisualTransition To="PART_Hidden" GeneratedDuration="0:0:0.25" Storyboard="{StaticResource A_Storyboard_Any_To_Hidden}"/>
                </VisualStateGroup.Transitions>
            </VisualStateGroup>

        </VisualStateManager.VisualStateGroups>

        <Decorator x:Name="TextBlock" Opacity="0">
            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_Base}" Color="{StaticResource H_Color_Glass_Purple_20pc}">
                <Viewbox MaxHeight="70" MaxWidth="640" StretchDirection="DownOnly" Stretch="Uniform">
                    <Decorator>
                        <StackPanel Style="{StaticResource A_Style_StackPanel_LatencyMargin}">
                            <StackPanel Orientation="Horizontal"
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center">
                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_HudNetworkStatus_PoorNetworkIcon}" 
                                                  VerticalAlignment="Center" 
                                                  Margin="0,0,10,0" 
                                                  Visibility="{Binding HasLatencyIcon, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                                <local:FZTextBlock Text="{Binding Text}"
                                                   MarkupConverter="{StaticResource A_MappingConverter_NetworkStatus}" 
                                                   Style="{StaticResource A_Style_FZTextBlock_NetworkStatus}" 
                                                   Tag="{Binding SubText, Converter={StaticResource A_StringVisConverter}}"
                                                   Margin="0,-4,0,0" />
                            </StackPanel>
                            <local:FZTextBlock x:Name="SubText" Text="{Binding SubText}" 
                                               MarkupConverter="{StaticResource A_MappingConverter_NetworkStatus}"
                                               Style="{StaticResource A_Style_FZTextBlock_NetworkStatusSubtext}" 
                                               Visibility="{Binding SubText, Converter={StaticResource A_StringVisConverter}}" 
                                               Color="{StaticResource H_Color_Primary_Yellow}"
                                               Margin="0,10,0,0"/>
                        </StackPanel>
                    </Decorator>
                </Viewbox>
            </local:FZMaterial>
        </Decorator>
        <local:EventFire x:Name="EventFire" />
    </Grid>
</UserControl>