<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"
    mc:Ignorable="d"
    xmlns:local="clr-namespace:ForzaUI" 
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    x:Class="ForzaUI.HUDHideSeekProgressControl"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    x:Name="UserControl">

    <UserControl.Resources>
        <ResourceDictionary>
             <Style x:Key="A_Style_FZTextBlock_Time"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
                <Setter Property="CapHeight" Value="59" />
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                <Setter Property="Effect" Value="{StaticResource A_DropShadowEffect_DefaultHud}" />
            </Style>

            <Style x:Key="A_Style_FZTextBlock_TimeRemainingLabel"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
                <Setter Property="CapHeight" Value="26" />
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                <Setter Property="Effect" Value="{StaticResource A_DropShadowEffect_DefaultHud}" />
                <Setter Property="Text" Value="{Loc HideSeek.IDS_ProgressStatus_TimeRemaining}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsTargetZoneLocked}" Value="True">
                        <Setter Property="Text" Value="{Loc HideSeek.IDS_ProgressStatus_TargetUnlockTimeRemaining}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_Progress"
                   TargetType="local:FZTextBlock">
                <Setter Property="CapHeight" Value="14" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                <Setter Property="Effect" Value="{StaticResource A_DropShadowEffect_DefaultHud}" />
            </Style>

            <KeyTime x:Key="A_KeyTime_Flash_Start">0:0:0</KeyTime>
            <local:OffsetKeyTime x:Key="A_KeyTime_Flash_MidPoint"
                     KeyTime="{StaticResource A_KeyTime_Flash_Start}"
                     Offset="0:0:0.200"/>
            <local:OffsetKeyTime x:Key="A_KeyTime_Flash_End"
                     KeyTime="{StaticResource A_KeyTime_Flash_MidPoint}"
                     Offset="0:0:0.600" />

            <ExponentialEase x:Key="A_EasingFunction_EaseInExpo" EasingMode="EaseIn" />
            <ExponentialEase x:Key="A_EasingFunction_EaseOutExpo" EasingMode="EaseOut" />

            <CircleEase x:Key="A_EasingFunction_EaseInCirc" EasingMode="EaseIn" />
            <CircleEase x:Key="A_EasingFunction_EaseOutCirc" EasingMode="EaseOut" />

            <local:UIStoryboard x:Key="A_Storyboard_AnimateFlash">
                <UIStoryboard.TriggerAnimation>
                    <StartAudioTrigger EventName="AudioUITrigger_HideSeek_Ability_Off_Cooldown" TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Flash_Start}"/>
                </UIStoryboard.TriggerAnimation>
                
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Flash"
                                               FillBehavior="Stop">
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_Start}" Value="0" />
                    <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_MidPoint}"
                                          Value="1"
                                          EasingFunction="{StaticResource A_EasingFunction_EaseInCirc}"/>
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_MidPoint}" Value="1" />
                    <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_End}"
                                          Value="0"
                                          EasingFunction="{StaticResource A_EasingFunction_EaseOutExpo}" />
                </DoubleAnimationUsingKeyFrames>

                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleY)"
                                               Storyboard.TargetName="Flash"
                                               FillBehavior="Stop">
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_Start}" Value="1" />
                    <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_End}"
                                              Value="1.60"
                                              EasingFunction="{StaticResource A_EasingFunction_EaseInCirc}"/>
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_End}" Value="1" />
                </DoubleAnimationUsingKeyFrames>

                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)"
                                               Storyboard.TargetName="Flash"
                                               FillBehavior="Stop">
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_Start}" Value="1" />
                    <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_End}"
                                          Value="1.15"
                                          EasingFunction="{StaticResource A_EasingFunction_EaseInCirc}"/>
                    <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_End}" Value="1" />
                </DoubleAnimationUsingKeyFrames>

                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                               Storyboard.TargetName="CountdownText"
                               FillBehavior="Stop">
                    <DiscreteObjectKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_Start}" Value="{x:Static Visibility.Visible}" />
                    <DiscreteObjectKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_MidPoint}" Value="{x:Static Visibility.Hidden}" />
                </ObjectAnimationUsingKeyFrames>

                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                               Storyboard.TargetName="PressButtonText"
                               FillBehavior="Stop">
                    <DiscreteObjectKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_Start}" Value="{x:Static Visibility.Hidden}" />
                    <DiscreteObjectKeyFrame KeyTime="{StaticResource A_KeyTime_Flash_MidPoint}" Value="{x:Static Visibility.Visible}" />
                </ObjectAnimationUsingKeyFrames>
            </local:UIStoryboard>

            <local:MappingConverter x:Key="A_MappingConverter_IsLocalPlayerHider_To_LeftSideImageSource">
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_True}" Value="/ForzaUI;component/Textures/Data_Bound/Hide_Seek/Progress_HUD/hider_chasebreak.png" />
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_False}" Value="/ForzaUI;component/Textures/Data_Bound/Hide_Seek/Progress_HUD/seeker_ping.png" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_IsLocalPlayerHider_To_RightSideImageSource">
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_True}" Value="/ForzaUI;component/Textures/Data_Bound/Hide_Seek/Progress_HUD/hider_chasebreak_end.png" />
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_False}" Value="/ForzaUI;component/Textures/Data_Bound/Hide_Seek/Progress_HUD/seeker_ping_end.png" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_IsLocalPlayerHider_To_BarText">
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_True}" Value="{local:Loc HideSeek.IDS_ProgressStatus_ChaseBreaker}" />
                <local:MappingConverterEntry Key="{StaticResource A_Boolean_False}" Value="{local:Loc HideSeek.IDS_ProgressStatus_HiderPing}" />
            </local:MappingConverter>

            <ControlTemplate x:Key="A_Control_RechargeableBar_Template" TargetType="Control">
                <DockPanel Height="44">
                    <local:FZMaterial DockPanel.Dock="Left"
                                      ImageSource="{Binding IsLocalPlayerHider, Converter={StaticResource A_MappingConverter_IsLocalPlayerHider_To_LeftSideImageSource}}"
                                      Width="44" />
                    <Grid DockPanel.Dock="Left" MinWidth="195" >
                        <ProgressBar DockPanel.Dock="Top"
                                     Value="{Binding RechargingRatio}"
                                     Minimum="0"
                                     Maximum="{StaticResource H_Double_One}">
                            <ProgressBar.Template>
                                <ControlTemplate TargetType="{Type ProgressBar}">
                                    <Grid x:Name="PART_Track" >
                                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_Base}"
                                                          Color="{StaticResource H_Color_Glass_Purple_20pc}"/>
                                        <local:FZMaterial x:Name="PART_Indicator" 
                                                          HorizontalAlignment="Left" 
                                                          Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_Base}"
                                                          Color="{StaticResource H_Color_Glass_Purple_60pc}" />
                                    </Grid>
                                </ControlTemplate>
                            </ProgressBar.Template>
                        </ProgressBar>
                        <Grid Margin="15,4">
                            <FZTextBlock x:Name="CountdownText"
                                         Style="{StaticResource A_Style_FZTextBlock_Progress}"
                                         Text="{Binding CountdownRemainingTimeString}" />
                            <DockPanel x:Name="PressButtonText">
                                <FZTextBlock Style="{StaticResource A_Style_FZTextBlock_Progress}"
                                             Text="{Binding IsLocalPlayerHider, Converter={StaticResource A_MappingConverter_IsLocalPlayerHider_To_BarText}}" />
                                <ControllerButtonControl InputOverride="{Input Command=INPUTCMD_HIDESEEK_PING_OR_CHASEBREAK, Context=INPUTCONTEXT_HIDE_SEEK}" 
                                                         Style="{StaticResource A_Style_ControllerButtonControl_Standalone}"
                                                         Visibility="Visible"
                                                         MinHeight="25"
                                                         Margin="5,0"/>
                                <FZTextBlock Style="{StaticResource A_Style_FZTextBlock_Progress}"
                                             Text="{local:Loc HideSeek.IDS_ProgressStatus_Available}" />
                            </DockPanel>
                        </Grid>
                        <local:FZMaterial x:Name="Flash" Color="{StaticResource H_Color_Primary_White}" 
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Opacity="0"                 
                                          RenderTransformOrigin="0.5,0.5">
                            <FZMaterial.RenderTransform>
                                <ScaleTransform ScaleX="0.85" ScaleY="0.85"/>
                            </FZMaterial.RenderTransform>
                        </local:FZMaterial>
                    </Grid>
                    <local:FZMaterial ImageSource="{Binding IsLocalPlayerHider, Converter={StaticResource A_MappingConverter_IsLocalPlayerHider_To_RightSideImageSource}}"
                                      Width="3"
                                      HorizontalAlignment="Left"/>
                </DockPanel>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding CountdownActive}" Value="False" >
                        <Setter TargetName="CountdownText" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="PressButtonText" Property="Visibility" Value="Visible" />
                        <DataTrigger.EnterActions>
                            <local:BeginUIStoryboard x:Name="BeginStoryboard_AnimateFlash"
                                                     Storyboard="{StaticResource A_Storyboard_AnimateFlash}"/>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding CountdownActive}" Value="True" >
                        <Setter TargetName="CountdownText" Property="Visibility" Value="Visible" />
                        <Setter TargetName="PressButtonText" Property="Visibility" Value="Hidden" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.0"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PART_LayoutRoot">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Shown"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,1,0,20">
            <DockPanel RenderTransform="{StaticResource A_Transform_Italic}">
                <FZTextBlock DockPanel.Dock="Left"
                             Style="{StaticResource A_Style_FZTextBlock_Time}"
                             Text="{Binding RemainingTime}" />
                <Decorator Width="10" />
                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TimeRemainingLabel}" />
            </DockPanel>
            <Decorator Height="35" />
            <ContentControl Template="{StaticResource A_Control_RechargeableBar_Template}" />
        </StackPanel>
    </Grid>
</UserControl>