<Page xmlns:local="clr-namespace:ForzaUI"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      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"
      x:Class="ForzaUI.Scenes.Anthem.A_PostRaceLeagueProgressPanel"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_PostRace}" />
    </local:UIPageTransitionManager.TransitionManager>
    <Page.Resources>
        <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_BarEdge"
                                           BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
                                           AlphaMode="Normal" />

        <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_BarEdgeGlow"
                                           Softness="60"
                                           BasedOn="{StaticResource A_FZMaterialPresetRoundtangle_BarEdge}" />

        <Color x:Key="A_Color_ProgressBackground_Overlay">#cd000000</Color>

        <Color x:Key="A_Color_LevelDark">#000</Color>
        <Color x:Key="A_Color_LevelLight">#ffff</Color>

        <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_LevelDarkGradient"
                                           BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
                                           GradientColorA="{StaticResource A_Color_LevelDark}"
                                           GradientColorB="#0000"
                                           GradientAngle="90" />
        <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_LevelLightGradient"
                                           BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
                                           AlphaMode="Additive"
                                           GradientColorA="#0000"
                                           GradientColorB="{StaticResource A_Color_LevelLight}"
                                           GradientAngle="90" />

        <Style x:Key="A_Style_ProgressBar"
               TargetType="{x:Type ProgressBar}">
            <Setter Property="Focusable"
                    Value="False" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid>
                            <local:FZMaterial x:Name="PART_Track"
                                              Color="#0000"
                                              Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}" />
                            <Grid x:Name="PART_Indicator"
                                  HorizontalAlignment="Left"
                                  ClipToBounds="True">
                                <local:FZMaterial Width="{TemplateBinding ActualWidth}"
                                                  Preset="{Binding OriginalLeague.LeagueNumber, Converter={StaticResource A_Converter_League_ID_To_GradientPreset_Horiz}}" />

                                <!-- Bar tips are currently tbd -->
                                <Decorator Visibility="Visible"
                                           HorizontalAlignment="Right">
                                    <local:FZMaterial Color="#fff"
                                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_BarEdge}"
                                                      Width="8" />
                                </Decorator>

                            </Grid>


                        </Grid>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="A_Style_FZRun_League_NUM"
               TargetType="{x:Type local:FZRun}">
            <Setter Property="FontFamily"
                    Value="Horizon_A" />
        </Style>

        <Style x:Key="A_Style_Whooshable"
               TargetType="FrameworkElement">
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform />
                </Setter.Value>
            </Setter>
            <Setter Property="Effect"
                    Value="{StaticResource A_MotionBlurEffect}" />
        </Style>

        <local:UIStoryboard x:Key="A_Storyboard_WhooshInFromLeft"
                            DurationOverride="0:0:0.4">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="-600" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                                        Value="0"
                                      EasingFunction="{local:CircleEasing EasingMode=EaseOut}"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                      Value="3"
                                      EasingFunction="{local:LinearEasing}" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                                      Value="1"
                                      EasingFunction="{local:LinearEasing}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(local:MotionBlurEffect.MotionBlurPositionXControl)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.7"
                                      Value="1000"
                                      EasingFunction="{local:SineEasing EasingMode=EaseOut}" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>

        <local:UIStoryboard x:Key="A_Storyboard_WhooshInFromRight"
                            DurationOverride="0:0:0.4">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="600" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                                      Value="0"
                                      EasingFunction="{local:CircleEasing EasingMode=EaseOut}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                      Value="3"
                                      EasingFunction="{local:LinearEasing}" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                                      Value="1"
                                      EasingFunction="{local:LinearEasing}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(local:MotionBlurEffect.MotionBlurPositionXControl)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.7"
                                      Value="1000"
                                      EasingFunction="{local:SineEasing EasingMode=EaseOut}" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>

        <local:MappingConverter x:Key="A_Converter_LeagueChangeStatesToVideoVisibility"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:LeagueChangeStates.Promoted}"
                                         Value="{x:Static Visibility.Visible}" />
            <local:MappingConverterEntry Key="{x:Static local:LeagueChangeStates.Qualified}"
                                         Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

    </Page.Resources>
    <Grid Width="1920"
          Height="540"
          ClipToBounds="True"
          DataContext="{Binding DataSource}">
        <Grid>
            <local:FZMaterial Color="#ff505050" />
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRace_Hatching}" />

            <ProgressBar x:Name="PART_RewardBar"
                         Style="{StaticResource A_Style_ProgressBar}"
                         local:BlendValue.Input="{Binding OriginalLeague.ProgressBlendInputValue, Converter={StaticResource A_IntToFloatConverter}}"
                         local:BlendValue.ShouldSkipInitialInputChange="True"
                         local:BlendValue.InputChangedStoryboard="{Binding OriginalLeague.LeagueChangeState, Converter={StaticResource A_Converter_LeagueChangeStatesToBlendValueChangedStoryboard}}"
                         Value="{Binding (local:BlendValue.Output), RelativeSource={RelativeSource Self}}"
                         Minimum="{Binding OriginalLeague.ProgressMin, Converter={StaticResource A_IntToFloatConverter}}"
                         Maximum="{Binding OriginalLeague.ProgressMax, Converter={StaticResource A_IntToFloatConverter}}" />

            <local:FZMaterial Preset="{Binding NewLeague.LeagueNumber, Converter={StaticResource A_Converter_League_ID_To_GradientPreset_Horiz}}"
                              Opacity="0"
                              x:Name="NewLeagueBG"/>

            <local:FZMediaElement Source="game:/Media/UI/Videos/Stars_Particles.bk2"
                                  local:FzMediaElementExtension.Loop="True"
                                  LoadedBehavior="Stop"
                                  UnloadedBehavior="Stop"
                                  Stretch="UniformToFill"
                                  Width="1920"
                                  Height="540"
                                  Visibility="{Binding OriginalLeague.LeagueChangeState, Converter={StaticResource A_Converter_LeagueChangeStatesToVideoVisibility}}"
                                  Preset="{StaticResource A_FZMaterialPresetAdditive}"
                                  x:Name="Video" />

            <Decorator HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       RenderTransformOrigin="0.5,0.5">
                <UIElement.RenderTransform>
                    <RotateTransform Angle="-6" />
                </UIElement.RenderTransform>

                <Grid RenderTransformOrigin="0.5,0.5"
                           RenderTransform="{StaticResource A_Transform_Italic}">
                    <StackPanel HorizontalAlignment="Center"
                                VerticalAlignment="Center">
                        <Decorator Style="{StaticResource A_Style_Whooshable}"
                                   x:Name="LeaguePoints">
                            <local:FZTextBlock CapHeight="180"
                                               HorizontalAlignment="Right"
                                               local:CompareValue.A="{Binding Value, ElementName=PART_RewardBar}"
                                               local:CompareValue.B="{Binding OriginalLeague.ProgressFinalValue}"
                                               Color="#fff">
                                <local:FZTextBlock.Style>
                                    <Style BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                           TargetType="{x:Type local:FZTextBlock}">
                                        <Setter Property="Margin"
                                                Value="0,0,0,0" />
                                        <Setter Property="Text"
                                                Value="{Binding Value, ElementName=PART_RewardBar, Converter={StaticResource A_NumUnitConverter_ShowUnit_0dp}}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding OriginalLeague.IsUnranked}"
                                                         Value="True">
                                                <Setter Property="Text"
                                                        Value="{Binding OriginalLeague.ProgressUnrankedInitialString}" />
                                            </DataTrigger>
                                            <MultiDataTrigger>
                                                <MultiDataTrigger.Conditions>
                                                    <Condition Binding="{Binding Path=(local:CompareValue.Result), RelativeSource={RelativeSource Self}}"
                                                               Value="0" />
                                                    <Condition Binding="{Binding OriginalLeague.IsUnranked}"
                                                               Value="True" />
                                                </MultiDataTrigger.Conditions>
                                                <Setter Property="Text"
                                                        Value="{Binding OriginalLeague.ProgressUnrankedFinalString}" />
                                            </MultiDataTrigger>
                                            <DataTrigger Binding="{Binding OriginalLeague.IsUnranked}"
                                                         Value="True">
                                                <Setter Property="Margin"
                                                        Value="0,0,100,0" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </local:FZTextBlock.Style>
                            </local:FZTextBlock>
                        </Decorator>
                        <Decorator Height="18" />
                        <Decorator x:Name="LeagueNameSlider">
                            <UIElement.RenderTransform>
                                <TranslateTransform />
                            </UIElement.RenderTransform>
                            <Decorator Style="{StaticResource A_Style_Whooshable}"
                                       x:Name="LeagueName">
                                <local:FZTextBlock local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_League_"
                                                   CapHeight="60"
                                                   Color="#fff">
                                    <FrameworkElement.Style>
                                        <Style BasedOn="{StaticResource A_Style_FZTextBlock_HorizonB}"
                                               TargetType="{x:Type local:FZTextBlock}">
                                            <Setter Property="local:TextBlockInlineMarkup.Markup"
                                                    Value="{Binding OriginalLeague.LeagueNumber, Converter={StaticResource A_Converter_League_ID_To_LeagueName}}" />
                                            <Setter Property="HorizontalAlignment"
                                                    Value="Right" />
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding OriginalLeague.IsUnranked}"
                                                             Value="True">
                                                    <Setter Property="local:TextBlockInlineMarkup.Markup"
                                                            Value="{local:Loc InGame.IDS_PostRace_AdventuresCompleted}" />
                                                    <Setter Property="HorizontalAlignment"
                                                            Value="Center" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </FrameworkElement.Style>
                                </local:FZTextBlock>
                            </Decorator>

                        </Decorator>
                    </StackPanel>

                    <FrameworkElement x:Name="PromotionAudio">
                        <FrameworkElement.Resources>
                            <local:EventFireTriggerCollection x:Key="A_Trigger">
                                <local:StartAudioTrigger local:EventFireTrigger.Event="LeagueChanged"
                                                         EventName="/Master/UI/E3/UI_Forzathon_Win" />
                            </local:EventFireTriggerCollection>
                        </FrameworkElement.Resources>
                        <FrameworkElement.Style>
                            <Style>
                                <Setter Property="local:EventFire.FzTriggers">
                                    <Setter.Value>
                                        <local:EventFireTriggerCollection>
                                            <local:StartAudioTrigger local:EventFireTrigger.Event="LeagueChanged"
                                                                     EventName="/Master/UI/PostRace/HZ2_SFX_HUD_PostRace_XPRewardsTitleOn_01" />
                                        </local:EventFireTriggerCollection>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding OriginalLeague.LeagueChangeState}"
                                                 Value="{x:Static local:LeagueChangeStates.Promoted}">
                                        <DataTrigger.Setters>
                                            <Setter Property="local:EventFire.FzTriggers"
                                                    Value="{StaticResource A_Trigger}"/>
                                        </DataTrigger.Setters>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding OriginalLeague.LeagueChangeState}"
                                                 Value="{x:Static local:LeagueChangeStates.Qualified}">
                                        <DataTrigger.Setters>
                                            <Setter Property="local:EventFire.FzTriggers"
                                                    Value="{StaticResource A_Trigger}" />
                                        </DataTrigger.Setters>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </FrameworkElement.Style>
                    </FrameworkElement>

                    <StackPanel HorizontalAlignment="Center"
                                VerticalAlignment="Center">
                        <Decorator x:Name="PromotionTextSlider">
                            <UIElement.RenderTransform>
                                <TranslateTransform />
                            </UIElement.RenderTransform>
                            <Decorator Style="{StaticResource A_Style_Whooshable}"
                                       Opacity="0"
                                       x:Name="PromotionText">
                                <local:FZTextBlock HorizontalAlignment="Left"
                                                   Style="{StaticResource A_Style_FZTextBlock_HorizonB}"
                                                   Text="{Binding OriginalLeague.LeagueChangeState, Converter={StaticResource A_Converter_LeagueChangeStatesToString}}"
                                                   CapHeight="60"
                                                   Color="#fff" />
                            </Decorator>

                        </Decorator>
                        <Decorator Height="18" />
                        <Decorator Style="{StaticResource A_Style_Whooshable}"
                                   x:Name="NewLeagueName"
                                   Opacity="0">
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                               CapHeight="180"
                                               local:TextBlockInlineMarkup.Markup="{Binding NewLeague.LeagueNumber, Converter={StaticResource A_Converter_League_ID_To_LeagueName}}"
                                               local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_League_"
                                               Color="#fff" />
                        </Decorator>
                    </StackPanel>
                </Grid>

            </Decorator>
        </Grid>

        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRacePanel_Vignette}"
                          IsHitTestVisible="False" />

        <local:FZMaterial Tag="{StaticResource A_FZMaterialPresetAdditive}"
                          x:Name="FullscreenFlash"
                          Color="#fff"
                          Opacity="0" />

        <Control>
            <Control.Template>
                <ControlTemplate>
                    <FrameworkElement />
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding LeagueChanged}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <local:RaiseFzEvent EventName="LevelChanged" />
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Control.Template>
        </Control>
    </Grid>
    <local:EventFire.FzTriggers>
        <local:BeginUIStoryboard local:EventFireTrigger.Event="LevelChanged">
            <local:UIStoryboard>
                <local:UIStoryboard.TriggerAnimation>
                    <local:PlayVideoTrigger local:TriggerAnimation.KeyTime="0:0:0.6"
                                            Storyboard.TargetName="Video" />
                    <local:BeginUIStoryboard Storyboard.TargetName="PromotionText"
                                                 Storyboard="{StaticResource A_Storyboard_WhooshInFromLeft}"
                                                 local:TriggerAnimation.KeyTime="0:0:0.6" />
                    <local:RaiseFzEvent local:TriggerAnimation.KeyTime="0:0:0.6"
                                        Storyboard.TargetName="PromotionAudio"
                                        EventName="LeagueChanged" />
                    <local:BeginUIStoryboard Storyboard.TargetName="NewLeagueName"
                                             Storyboard="{StaticResource A_Storyboard_WhooshInFromLeft}"
                                                 local:TriggerAnimation.KeyTime="0:0:0.6"/>

                    <local:BeginUIStoryboard Storyboard.TargetName="PromotionTextSlider"
                                                 local:TriggerAnimation.KeyTime="0:0:0.6">
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                                            Value="0" />
                                    <LinearDoubleKeyFrame KeyTime="0:0:20"
                                                          Value="100" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </local:BeginUIStoryboard>
                </local:UIStoryboard.TriggerAnimation>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FullscreenFlash"
                                               Storyboard.TargetProperty="Opacity">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                            Value="0" />
                    <EasingDoubleKeyFrame KeyTime="0:0:0.2"
                                            Value="1"
                                          EasingFunction="{local:QuadraticEasing EasingMode=EaseIn}"/>
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.6"
                                            Value="1" />
                    <EasingDoubleKeyFrame KeyTime="0:0:1.2"
                                            Value="0"
                                          EasingFunction="{local:QuadraticEasing EasingMode=EaseIn}"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="NewLeagueBG"
                                               Storyboard.TargetProperty="Opacity">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                            Value="0" />
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.2"
                                            Value="1" />
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LeaguePoints"
                                               Storyboard.TargetProperty="Opacity"
                                               FillBehavior="HoldEnd">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.2"
                                            Value="0" />
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LeagueName"
                                               Storyboard.TargetProperty="Opacity"
                                               FillBehavior="HoldEnd">
                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.2"
                                            Value="0" />
                </DoubleAnimationUsingKeyFrames>
            </local:UIStoryboard>
        </local:BeginUIStoryboard>
    </local:EventFire.FzTriggers>
    <Page.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <local:BeginUIStoryboard>
                <local:UIStoryboard>
                    <local:UIStoryboard.TriggerAnimation>
                        <local:BeginUIStoryboard Storyboard.TargetName="LeaguePoints"
                                                 Storyboard="{StaticResource A_Storyboard_WhooshInFromLeft}"
                                                 local:TriggerAnimation.KeyTime="0:0:0" />
                        <local:StartAudioTrigger local:TriggerAnimation.KeyTime="0:0:0"
                                                 EventName="/Master/UI/PostRace/HZ2_SFX_HUD_PostRace_XPRewardsTitleOn_01" />
                        <local:BeginUIStoryboard Storyboard.TargetName="LeagueName"
                                                 Storyboard="{StaticResource A_Storyboard_WhooshInFromRight}"
                                                 local:TriggerAnimation.KeyTime="0:0:0"/>

                        <local:BeginUIStoryboard Storyboard.TargetName="LeagueNameSlider"
                                                 local:TriggerAnimation.KeyTime="0:0:0">
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                                            Value="0" />
                                    <LinearDoubleKeyFrame KeyTime="0:0:20"
                                                          Value="-100" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </local:BeginUIStoryboard>
                    </local:UIStoryboard.TriggerAnimation>
                </local:UIStoryboard>
            </local:BeginUIStoryboard>
        </EventTrigger>
    </Page.Triggers>
</Page>
