<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_PostRaceBucketListStarsWithInput"
      mc:Ignorable="d"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Style="{StaticResource A_Style_Page_Generic}">
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_PostRace}"/>
    </local:UIPageTransitionManager.TransitionManager>
    <Page.Resources>
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxGlow_Start"
                             KeyTime="{StaticResource A_KeyTime_Star_Slam_Bloom_Up}"
                             Offset="0:0:0.0" />
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxGlow_Up"
                             KeyTime="{StaticResource A_KeyTime_MaxGlow_Start}"
                             Offset="0:0:0.21" />
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxGlow_Hold"
                             KeyTime="{StaticResource A_KeyTime_MaxGlow_Up}"
                             Offset="0:0:0.03" />
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxGlow_Down"
                             KeyTime="{StaticResource A_KeyTime_MaxGlow_Hold}"
                             Offset="0:0:0.24" />


        <local:UIStoryboard x:Key="A_Storyboard_FinalStarEarned">
            <local:UIStoryboard.TriggerAnimation>
                <local:PlayVideoTrigger local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Star_Slam_Bloom_Begin}"
                                        Storyboard.TargetName="Video" />
                <local:StartAudioTrigger local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_MaxGlow_Start}"
                                         EventName="/Master/UI/E3/UI_Forzathon_Win" />
            </local:UIStoryboard.TriggerAnimation>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FullGlow"
                                           Storyboard.TargetProperty="Opacity">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxGlow_Start}"
                                        Value="0" />
                <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxGlow_Up}"
                                        Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxGlow_Hold}"
                                        Value="1" />
                <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxGlow_Down}"
                                        Value="0" />
            </DoubleAnimationUsingKeyFrames>

        </local:UIStoryboard>

        <local:UIStoryboard x:Key="A_Storyboard_FinalStarNotEarned">
            <local:UIStoryboard.TriggerAnimation>
                <local:StartAudioTrigger local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_MaxGlow_Start}"
                                         EventName="/Master/UI/E3/UI_Forzathon_Lose" />
            </local:UIStoryboard.TriggerAnimation>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FullGlow"
                                           Storyboard.TargetProperty="Opacity">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
            </DoubleAnimationUsingKeyFrames>

        </local:UIStoryboard>

        <local:UIStoryboard x:Key="A_Storyboard_NewStarsEarned">
            <local:UIStoryboard.TriggerAnimation>
                <!--0:0:1.5-->
                <local:RaiseEntityModelEvent local:TriggerAnimation.KeyTime="0:0:3.5" EventName="UISequence_Continue" />
            </local:UIStoryboard.TriggerAnimation>
            <Int32AnimationUsingKeyFrames Storyboard.TargetName="TickerStars"
                                          Storyboard.TargetProperty="(local:MinValue.A)">
                <DiscreteInt32KeyFrame KeyTime="0:0:0"
                                       Value="1" />
                <DiscreteInt32KeyFrame KeyTime="0:0:0.5"
                                       Value="2" />
                <DiscreteInt32KeyFrame KeyTime="0:0:1"
                                       Value="3" />
            </Int32AnimationUsingKeyFrames>
            <Int32AnimationUsingKeyFrames Storyboard.TargetName="TickerEmptyStars"
                                          Storyboard.TargetProperty="(local:MinValue.A)">
                <DiscreteInt32KeyFrame KeyTime="0:0:0"
                                       Value="1" />
                <DiscreteInt32KeyFrame KeyTime="0:0:0.5"
                                       Value="2" />
                <DiscreteInt32KeyFrame KeyTime="0:0:1"
                                       Value="3" />
            </Int32AnimationUsingKeyFrames>
        </local:UIStoryboard>

        <local:LinearTransformConverter x:Key="A_Converter_Identity" />

        <DataTemplate x:Key="A_ItemTemplate_BucketListStar_EmptyStar">
            <Control Style="{StaticResource A_Style_Control_BucketListStar_EmptyStar}" />
        </DataTemplate>
        <DataTemplate x:Key="A_ItemTemplate_BucketListStar">
            <Control Style="{StaticResource A_Style_Control_BucketListStar}" />
        </DataTemplate>
        <Style x:Key="A_Style_Control_PostRace_BonusValueBlock_Stars"
               TargetType="Control">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <ControlTemplate.Resources>
                            <System:Int32 x:Key="A_Int_Zero">0</System:Int32>
                        </ControlTemplate.Resources>
                        <Grid>
                            <local:TickerItemsControl Max="3"
                                                      Value="{Binding Path=(local:MinValue.Result), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_Identity}}"
                                                      local:MinValue.A="{StaticResource A_Int_Zero}"
                                                      local:MinValue.B="{Binding RawValue}"
                                                      x:Name="TickerEmptyStars"
                                                      ItemsPanel="{StaticResource A_PanelTemplate_BucketListStars}"
                                                      ItemTemplate="{StaticResource A_ItemTemplate_BucketListStar_EmptyStar}"/>
                            <local:TickerItemsControl Max="3"
                                                      Value="{Binding Path=(local:MinValue.Result), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_Identity}}"
                                                      local:MinValue.A="{StaticResource A_Int_Zero}"
                                                      local:MinValue.B="{Binding RawValue}"
                                                      x:Name="TickerStars"
                                                      ItemsPanel="{StaticResource A_PanelTemplate_BucketListStars}"
                                                      ItemTemplate="{StaticResource A_ItemTemplate_BucketListStar}"/>

                            <local:EventFire.FzTriggers>
                                <local:BeginUIStoryboard local:EventFireTrigger.Event="AnimateStars"
                                                         Storyboard="{StaticResource A_Storyboard_NewStarsEarned}" />
                            </local:EventFire.FzTriggers>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding BonusItems.Count, RelativeSource={RelativeSource AncestorType=Page}, Converter={CompareConverter}, ConverterParameter=0}" Value="{x:Static CompareResult.GreaterThan}">
                    <Setter Property="DataContext" Value="{Binding BonusItems[0], RelativeSource={RelativeSource AncestorType=Page}}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>


        <local:UIStoryboard x:Key="A_Storyboard_PlayNewUnlockAudio">
            <local:UIStoryboard.TriggerAnimation>
                <local:StartAudioTrigger local:TriggerAnimation.KeyTime="0:0:0.0"
                                         EventName="/Master/UI/PostRace/HZ2_SFX_HUD_PostRace_CashRewardsBalanceOn_01" />
                <local:StartAudioTrigger local:TriggerAnimation.KeyTime="0:0:1.0"
                                         EventName="/Master/UI/PostRace/HZ3_SFX_HUD_PostRace_FanRewardsSheen" />
            </local:UIStoryboard.TriggerAnimation>
        </local:UIStoryboard>

        <local:OffsetKeyTime x:Key="A_KeyTime_MaxScore_TextIn_Begin"
                             KeyTime="{StaticResource A_KeyTime_MaxGlow_Down}"
                             Offset="0:0:1.0" />
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxScore_TextIn_End"
                             KeyTime="{StaticResource A_KeyTime_MaxScore_TextIn_Begin}"
                             Offset="0:0:0.1" />
        <local:OffsetKeyTime x:Key="A_KeyTime_MaxScore_TextSlip_Begin"
                             KeyTime="{StaticResource A_KeyTime_MaxScore_TextIn_End}"
                             Offset="0:0:0.15" />

        <local:OffsetKeyTime x:Key="A_KeyTime_Complete"
                             KeyTime="{StaticResource A_KeyTime_MaxScore_TextSlip_Begin}"
                             Offset="0:0:11.5" />
        <local:OffsetKeyTime x:Key="A_KeyTime_Continue"
                             KeyTime="{StaticResource A_KeyTime_Complete}"
                             Offset="0:0:0.5" />

        <local:UIStoryboard x:Key="PART_Storyboard_Stars_Coop">
            <local:UIStoryboard.TriggerAnimation>
                <local:RaiseFzEvent local:TriggerAnimation.KeyTime="0:0:0.0"
                                    EventName="StartStarRewards" />
                <local:RaiseFzEvent local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Complete}"
                                    EventName="Complete" />
                <local:RaiseFzEvent local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Continue}"
                                    EventName="AutoContinue" />
                <local:StartAudioTrigger local:TriggerAnimation.KeyTime="0:0:0"
                                         EventName="/Master/UI/PostRace/HZ2_SFX_HUD_PostRace_XPRewardsTitleOn_01" />
            </local:UIStoryboard.TriggerAnimation>

            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BottomTextContainer"
                                           Storyboard.TargetProperty="Opacity">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                        Value="0" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxScore_TextIn_Begin}"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxScore_TextIn_End}"
                                      Value="1"
                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseOut}" />
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BottomTextContainer"
                                           Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="100" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxScore_TextIn_Begin}"
                                        Value="100" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_MaxScore_TextSlip_Begin}"
                                      Value="0"
                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseOut}" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>

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

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

        <MappingConverter x:Key="A_MappingConverter_PostRaceMessage">
            <MappingConverterEntry Key="{NoCase BOLD}" Value="{StaticResource A_Style_FZRun_PostRaceMessageText_BOLD}" />
            <MappingConverterEntry Key="{NoCase NUM}" Value="{StaticResource A_Style_FZRun_PostRaceMessageText_NUM}" />
        </MappingConverter>

        <Style x:Key="A_Style_FZTextBlock_PostRace_MessageText" 
               TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="FontFamily" Value="Horizon_A"/>
            <Setter Property="TextAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="Stretch" Value="None"/>
        </Style>

        <Style x:Key="A_Style_WinnerAtThreeStars">
            <Setter Property="local:MultiStringFormatter.Format" Value="{Loc Scoreboard.IDS_ScreenReader_Format_Stars}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding StarsEarned}" Value="3">
                    <Setter Property="local:MultiStringFormatter.Format" Value="{Loc Scoreboard.IDS_ScreenReader_Format_Stars_Winner}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <System:Double x:Key="A_Double_SwipeTopHeight">330</System:Double>
        <System:Double x:Key="A_Double_SwipeBottomHeight">8</System:Double>

    </Page.Resources>
    <Grid x:Name="PART_LayoutRoot">
        <local:FZMaterial x:Name="HighContrastBg"
                          Color="#99000000"
                          Visibility="{StaticResource A_Visibility_ShowForHighContrastOnly}" />
        
        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <FZMediaElement Source="game:/Media/UI/Videos/Stars_Particles.bk2"
                            local:FzMediaElementExtension.Loop="True"
                            LoadedBehavior="Stop"
                            UnloadedBehavior="Stop"
                            Stretch="UniformToFill"
                            Width="1920"
                            Height="810"
                            x:Name="Video" />

            <Grid VerticalAlignment="Center"
                  HorizontalAlignment="Center">
                <StackPanel Orientation="Vertical">

                    <DockPanel x:Name="HorizontalSwipe"
                               Width="1300">
                        <local:FZMaterial Color="{StaticResource H_Color_Primary_Yellow}"
                                          Height="{StaticResource A_Double_SwipeBottomHeight}"
                                          DockPanel.Dock="Top"
                                          ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Gradient_Bar.png"/>
                        <local:FZMaterial Color="{StaticResource H_Color_Primary_Yellow}"
                                          Height="{StaticResource A_Double_SwipeBottomHeight}"
                                          DockPanel.Dock="Bottom"
                                          ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Gradient_Bar.png"/>
                        <local:FZMaterial Color="{StaticResource H_Color_Primary_Black}"
                                          Height="{StaticResource A_Double_SwipeTopHeight}"
                                          ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Gradient_Bar.png"/>
                    </DockPanel>

                    <Decorator x:Name="BottomTextContainer"
                               Effect="{StaticResource A_MotionBlurEffect}"
                               local:MotionBlurEffect.MotionBlurPositionXControl="{Binding RenderTransform.X, RelativeSource={RelativeSource Self}}"
                               HorizontalAlignment="Center"
                               Margin="0,40,0,5">
                        <UIElement.RenderTransform>
                            <TranslateTransform />
                        </UIElement.RenderTransform>
                        <StackPanel Orientation="Vertical"
                                Style="{StaticResource A_Style_WinnerAtThreeStars}"
                                local:MultiStringFormatter.Param0="{Binding StarsEarned}"
                                local:ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                local:ScreenReader.LineType="ScreenDescription"
                                local:ScreenReader.Event="OnChange">

                            <!--Arrived in-->
                            <Decorator RenderTransform="{StaticResource A_Transform_Italic}">
                                <local:FZTextBlock x:Name="TimeText"
                                                   Style="{StaticResource A_Style_FZTextBlock_PostRace_MessageText}"
                                                   Effect="{StaticResource A_DropShadowEffect_DefaultHud}"
                                                   Color="{StaticResource H_Color_Primary_White}"
                                                   CapHeight="60"
                                                   MarkupConverter="{StaticResource A_MappingConverter_PostRaceMessage}"
                                                   Text="{Binding TeamScore}"
                                                   Visibility="{Binding TeamScore, Converter={StaticResource A_StringVisConverter}}"
                                                   local:ScreenReader.Line="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                                   local:ScreenReader.LineType="ItemDescription"
                                                   local:ScreenReader.Event="OnChange"/>
                            </Decorator>

                            <!--Time to stars-->
                            <Decorator RenderTransform="{StaticResource A_Transform_Italic}">
                                <local:FZTextBlock x:Name="TimeToStarsText"
                                                   FontFamily="Horizon_B"
                                                   Style="{StaticResource A_Style_FZTextBlock_PostRace_MessageText}"
                                                   Effect="{StaticResource A_DropShadowEffect_DefaultHud}"
                                                   Color="{StaticResource H_Color_Primary_Yellow}"
                                                   CapHeight="30"
                                                   Margin="0,30,0,0"
                                                   MarkupConverter="{StaticResource A_MappingConverter_PostRaceMessage}"
                                                   Text="{Binding NextStarScoreText}"
                                                   Visibility="{Binding NextStarScoreText, Converter={StaticResource A_StringVisConverter}}"
                                                   local:ManualPassthroughProperty.Input="{Binding Text, RelativeSource={RelativeSource Self}}"
                                                   local:ManualPassthroughProperty.Allowed="{Binding Visibility, RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_VisibilityToBool}}"
                                                   local:ScreenReader.Line="{Binding (local.ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                                   local:ScreenReader.LineType="ItemState"
                                                   local:ScreenReader.Event="OnChange"/>
                            </Decorator>
                        </StackPanel>
                    </Decorator>
                </StackPanel>

                <Control x:Name="BonusValue1"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Top"
                         Margin="0,8,0,0"
                         Height="{StaticResource A_Double_SwipeTopHeight}"
                         Style="{StaticResource A_Style_Control_PostRace_BonusValueBlock_Stars}"
                         Opacity="1"/>
            </Grid>

        </Grid>

        <local:FZMaterial x:Name="FullGlow"
                          Preset="{StaticResource A_FZMaterialPresetAdditive}"
                          Opacity="0" />

        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}"/>
        </ContentControl>

        <local:EventFire x:Name="PART_EventFire" />
        <local:EventFire x:Name="PART_UnlockRewardEventFire" />
    </Grid>


    <local:EventFire.FzTriggers>
        <local:EventFireTrigger Event="ShowNewUnlock"
                                TargetName="NewUnlockAudio"
                                Storyboard="{StaticResource A_Storyboard_PlayNewUnlockAudio}" />
        <local:RaiseFzEvent local:EventFireTrigger.Event="StartStarRewards"
                            local:EventFireTrigger.TargetName="BonusValue1"
                            EventName="AnimateStars" />

        <!-- Compose this BeginUIStoryboard so that it doesn't kill the trigger animation in PART_Storyboard_Stars_Coop -->
        <local:BeginUIStoryboard local:EventFireTrigger.Event="FinalStarAnimationFullStar"
                                 HandoffBehavior="Compose"
                                 Storyboard="{StaticResource A_Storyboard_FinalStarEarned}" />
        
        <local:BeginUIStoryboard local:EventFireTrigger.Event="FinalStarAnimationNotFullStar"
                                 HandoffBehavior="Compose"
                                 Storyboard="{StaticResource A_Storyboard_FinalStarNotEarned}" />
        
        <local:RaiseEntityModelEvent local:EventFireTrigger.Event="StartPanelAnimation"
                                     EventName="PostRaceBucketListStarsPanel" />
    </local:EventFire.FzTriggers>
</Page>
