<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_Tombola"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      FlowDirection="LeftToRight"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Resources/Anthem/Resources_Tombola.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>
    
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Grid>
        <Control
                Style="{StaticResource A_Style_Control_ScreenBackground}"
                Visibility="{Binding IsInPostRace, RelativeSource={RelativeSource AncestorType=Page}, Converter={FZBooleanToVisibilityConverter InvertResult=True}, FallbackValue={Static Visibility.Visible}}" />
        <Grid x:Name="PART_LayoutRoot"
              Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}"
              DataContext="{Binding DataSource}">


            <Control Style="{StaticResource A_Style_FrameworkElement_FadeOnlyTransition_0}">
                <Control.Template>
                    <ControlTemplate>
                        <Grid>
                            <Decorator Height="{StaticResource A_Double_Background_Height}"
                                       ClipToBounds="True">
                                <Grid>
                                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundGradient}" />

                                    <!-- Left Panel -->
                                    <Grid x:Name="LeftPanel"
                                          Margin="0,0"
                                          HorizontalAlignment="Left">
                                        <Grid Margin="-25,-227,0,0">
                                            <ItemsControl Style="{StaticResource A_Style_ItemsControl_TombolaBackgroundSpokes}">
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaBackgroundSpoke}" />
                                            </ItemsControl>

                                            <ContentControl x:Name="Logo" 
                                                            Template="{StaticResource A_Template_Tanky_Wheelspin_Logo}">
                                                <ContentControl Template="{StaticResource A_Template_Tombola_FlashGlow}">
                                                    <FZMaterial Style="{StaticResource A_Style_FZMaterial_HatFlash}"/>
                                                </ContentControl>             
                                            </ContentControl>
                                            <StackPanel HorizontalAlignment="Center"
                                                        VerticalAlignment="Center"
                                                        Margin="14,612,0,0">
                                                <ContentControl Template="{StaticResource A_ControlTemplate_TombolaCounter}"/>
                                                <local:FZTextBlock x:Name="SpinsRemainingLabel"
                                                                   Style="{StaticResource A_Style_FZTextBlock_TombolaSpinsRemaining}"/>
                                            </StackPanel>

                                        </Grid>
                                    </Grid>
                                </Grid>
                            </Decorator>

                            <Control Template="{StaticResource A_ControlTemplate_TombolaScene_Border}"/>

                            <Grid HorizontalAlignment="Right" Margin="0,2,231,0">
                                <FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaDrumBackground}"/>
                                <Control x:Name="PanelContents"
                                         Style="{StaticResource A_Style_Control_TombolaPanelContents}" />
                                <FZMaterial Style="{StaticResource A_Style_FZMaterial_TombolaDrumForeground}"/>
                                <Control Template="{StaticResource A_ControlTemplate_TombolaBorder}"/>
                            </Grid>

                            <Decorator Height="{StaticResource A_Double_Background_Height}" 
                                       ClipToBounds="True">
                                <Grid>
                                    <local:FZMaterial x:Name="TombolaFlash"
                                                      Style="{StaticResource A_Style_FZMaterial_TombolaFlash}" />
                                    <local:FZMaterial x:Name="TombolaSkipFlash"
                                                      Style="{StaticResource A_Style_FZMaterial_TombolaFlash}" />
                                </Grid>
                            </Decorator>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding AnimationState}"
                                         Value="{x:Static local:TombolaAnimationStates.Spinning}">
                                <DataTrigger.EnterActions>
                                    <local:BeginUIStoryboard x:Name="BeginStoryboard_Tombola">
                                        <local:UIStoryboard>
                                            <local:UIStoryboard.TriggerAnimation>
                                                <local:RaiseFzEvent EventName="SkipEnabled"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TombolaSkipEnabledTime}" />
                                                <local:RaiseFzEvent EventName="SkipDisabled"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TombolaSkipDisabledTime}" />
                                                <local:RaiseFzEvent EventName="PlayWinAudio"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TombolaPlayWinAudio}" />
                                                <local:RaiseFzEvent EventName="SpinComplete"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource PART_A_KeyTime_TombolaLockInTime}" />
                                                <local:RaiseFzEvent EventName="CanSpinAgain"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource PART_A_KeyTime_TombolaSpinAgainTime}" />
                                                <local:StartAudioTrigger EventName="/Master/UI/Tombola/HZ2_SFX_HUD_Tombola_Spin_01"
                                                                         local:TriggerAnimation.KeyTime="0:0:0.0" />
                                            </local:UIStoryboard.TriggerAnimation>

                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="TombolaFlash"
                                                                           Storyboard.TargetProperty="Opacity">
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeInEnd}"
                                                                      Value="0.0"
                                                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseIn}" />
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaLockInFlashFadeInStart}"
                                                                        Value="0.0" />
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaLockInFlashFadeInEnd}"
                                                                      Value="1.0"
                                                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseOut}" />
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaLockInFlashFadeOutStart}"
                                                                        Value="1.0" />
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaLockInFlashFadeOutEnd}"
                                                                      Value="0.0"
                                                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseIn}" />
                                            </DoubleAnimationUsingKeyFrames>

                                        </local:UIStoryboard>
                                    </local:BeginUIStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding AnimationState}"
                                         Value="{x:Static local:TombolaAnimationStates.Hiding}">
                                <DataTrigger.EnterActions>
                                    <local:BeginUIStoryboard>
                                        <local:UIStoryboard>
                                            <local:UIStoryboard.TriggerAnimation>
                                                <local:RaiseFzEvent EventName="HideComplete"
                                                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TombolaResetTime}" />
                                            </local:UIStoryboard.TriggerAnimation>

                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="TombolaFlash"
                                                                           Storyboard.TargetProperty="Opacity">
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeInStart}"
                                                                        Value="0.0" />
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeInEnd}"
                                                                      Value="1.0"
                                                                      EasingFunction="{local:LinearEasing}" />
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeOutStart}"
                                                                        Value="1.0" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </local:UIStoryboard>
                                    </local:BeginUIStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding AnimationState}" Value="{x:Static local:TombolaAnimationStates.Skipping}">
                                <DataTrigger.EnterActions>
                                    <local:BeginUIStoryboard>
                                        <local:UIStoryboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="TombolaSkipFlash"
                                                                           Storyboard.TargetProperty="Opacity">
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeInStart}"
                                                                        Value="0.0" />
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeInEnd}"
                                                                      Value="1.0"
                                                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseOut}" />
                                                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeOutStart}"
                                                                        Value="1.0" />
                                                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_TombolaResetFlashFadeOutEnd}"
                                                                      Value="0.0"
                                                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseIn}" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </local:UIStoryboard>
                                    </local:BeginUIStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding IsSkipComplete}"
                                         Value="True">
                                <DataTrigger.EnterActions>
                                    <SeekStoryboard BeginStoryboardName="BeginStoryboard_Tombola"
                                                    Offset="{StaticResource PART_A_TimeSpan_TombolaSkipOffset}"
                                                    Origin="{x:Static TimeSeekOrigin.BeginTime}" />
                                </DataTrigger.EnterActions>
                            </DataTrigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Control.Template>
            </Control>
        </Grid>

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