<Page x:Class="ForzaUI.Scenes.Anthem.A_TreasureHunt"
      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" 
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Page.Resources>
        <Style x:Key="A_Style_FZMaterial_ItemBackground_Locked"
               BasedOn="{StaticResource A_Style_FZMaterial_GlassPanel_Interactive}"
               TargetType="{x:Type local:FZMaterial}">
            <Style.Resources>
                <local:FZMaterialPresetGlassRoundtangle x:Key="A_FZMaterialPresetGlassRoundtangle_GlassPanel_Locked"
                                                        BasedOn="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll}"
                                                        BlurAmount="High" />
            </Style.Resources>
            <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_Locked}" />
        </Style>
        <Style x:Key="A_Style_FZMaterial_ItemBackground"
               TargetType="{x:Type local:FZMaterial}">
            <Style.Resources>
                <Color x:Key="A_Color_Background_GradientA">#00B592</Color>
                <Color x:Key="A_Color_Background_GradientB">#4CBDE5</Color>
                <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_TileContentBackground"
                                                   BasedOn="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                                   GradientColorA="{StaticResource A_Color_Background_GradientA}"
                                                   GradientColorB="{StaticResource A_Color_Background_GradientB}"
                                                   GradientAngle="45"
                                                   CornerRadius="12" />
                <Color x:Key="A_Color_Background_RewardCollected_GradientA">#895D2D</Color>
                <Color x:Key="A_Color_Background_RewardCollected_GradientB">#FCE270</Color>
                <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_RewardCollected_TileContentBackground"
                                                   BasedOn="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                                   GradientColorA="{StaticResource A_Color_Background_RewardCollected_GradientA}"
                                                   GradientColorB="{StaticResource A_Color_Background_RewardCollected_GradientB}"
                                                   GradientAngle="45"
                                                   CornerRadius="12" />
            </Style.Resources>
            <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_TileContentBackground}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding TreasureHuntItemState}"
                             Value="{x:Static local:TreasureHuntItemState.RewardCollected}">
                    <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_RewardCollected_TileContentBackground}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <local:MappingConverter x:Key="A_Converter_TreasureStateToBackgroundStyle"
                                Default="{StaticResource A_Style_FZMaterial_ItemBackground}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.Locked}" Value="{StaticResource A_Style_FZMaterial_ItemBackground_Locked}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_TreasureStateToRiddleVis"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.ChallengeAvailable}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_TreasureStateToPolaroidVis"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.ChallengeComplete}" Value="{x:Static Visibility.Visible}" />
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.RewardCollected}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_TreasureStateToLocText"
                                Default="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/EN/NotFoundText.png">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.RewardCollected}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/EN/FoundText.png" />
        </local:MappingConverter>

        <Style x:Key="A_Style_FZTextBlock_TreasureName"
            BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}"
            TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="Text"
                    Value="{Binding Name}" />
            <Setter Property="Color"
                    Value="{StaticResource A_Color_Tile_Text}" />
            <Setter Property="CapHeight"
                    Value="16" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_TreasureCount"
            BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}"
            TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="Color"
                    Value="{StaticResource A_Color_Tile_Title}" />
            <Setter Property="CapHeight"
                    Value="24" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
        </Style>

        <Style x:Key="A_Style_FZMaterial_TreasureDescriptionPattern"
               TargetType="{x:Type local:FZMaterial}">
            <Setter Property="ImageSource"
                    Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Pattern.png" />
            <Setter Property="RenderTransformOrigin"
                    Value="0.5,0.5" />
            <Setter Property="Width"
                    Value="122" />
            <Setter Property="Height"
                    Value="62" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
            <Setter Property="Margin"
                    Value="25" />
        </Style>

        <local:MappingConverter x:Key="A_Converter_ShownIfLocked"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.Locked}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>
        <local:MappingConverter x:Key="A_Converter_ShownIfUnlocked"
                                Default="{x:Static Visibility.Visible}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.Locked}" Value="{x:Static Visibility.Collapsed}" />
        </local:MappingConverter>
        <local:MappingConverter x:Key="A_Converter_ShownIfRewardCollected"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.RewardCollected}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>
        <local:MappingConverter x:Key="A_Converter_ShownIfChallengeCompleteOrRewardCollected"
                                Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.ChallengeComplete}" Value="{x:Static Visibility.Visible}" />
            <local:MappingConverterEntry Key="{x:Static local:TreasureHuntItemState.RewardCollected}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_SeasonToPolaroidLocation"
                                Default="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Summer/">
            <local:MappingConverterEntry Key="{x:Static local:Season.Summer}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Summer/" />
            <local:MappingConverterEntry Key="{x:Static local:Season.Autumn}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Autumn/" />
            <local:MappingConverterEntry Key="{x:Static local:Season.Winter}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Winter/" />
            <local:MappingConverterEntry Key="{x:Static local:Season.Spring}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/Spring/" />
        </local:MappingConverter>

        <DataTemplate x:Key="A_DataTemplate_TreasureHuntItem">
            <Grid>
                <DockPanel>
                    <StackPanel VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                DockPanel.Dock="Bottom">
                        <Decorator Height="20" />
                        <local:FZTextBlock Text="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_StringToUpper}}"
                                           local:MultiStringFormatter.Param0="{Binding TreasureNumber}"
                                           local:MultiStringFormatter.Format="{local:Loc Expansions.IDS_TreasureHunt_TreasureCount}"
                                           Style="{StaticResource A_Style_FZTextBlock_TreasureCount}" />
                        <Decorator Height="9" />
                        <Grid>
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreasureName}"
                                               Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfUnlocked}}" />
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreasureName}"
                                               Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfLocked}}"
                                               Text="{local:Loc Expansions.IDS_TreasureHunt_TreasureLockedName}" />
                        </Grid>
                        <Decorator Height="22" />
                    </StackPanel>
                    <local:FZMaterial Margin="6"
                                      DockPanel.Dock="Top"
                                      Style="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_TreasureStateToBackgroundStyle}}">
                        <Grid>
                            <Grid Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_TreasureStateToRiddleVis}}">
                                <local:FZMaterial x:Name="HighContrastUnderlay"
                                                  Color="#66000000" 
                                                  Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                                  Visibility="{StaticResource A_Visibility_ShowForHighContrastOnly}" />
                                <local:FZMaterial Margin="10"
                                                  Color="#80FFFFFF"
                                                  Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfUnlocked}}">
                                    <local:FZMaterial.Preset>
                                        <local:FZMaterialPresetRoundtangleStroke BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
                                                                                 Thickness="2"
                                                                                 CornerRadius="{StaticResource A_CornerRadius_Outer_All}" />
                                    </local:FZMaterial.Preset>
                                    <StackPanel HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Margin="38">
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TreasureDescriptionPattern}">
                                            <local:FZMaterial.RenderTransform>
                                                <RotateTransform Angle="180" />
                                            </local:FZMaterial.RenderTransform>
                                        </local:FZMaterial>
                                        <local:FZTextBlock Text="{Binding Description}"
                                                            Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                                            CapHeight="26"
                                                            Color="#FFFFFF"
                                                            TextWrapping="WrapWithOverflow"
                                                            TextAlignment="Center" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TreasureDescriptionPattern}" />
                                    </StackPanel>
                                </local:FZMaterial>
                            </Grid>
                            <Grid Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_TreasureStateToPolaroidVis}}">
                                <local:FZMaterial Width="406"
                                                  Height="615"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  local:MultiStringFormatter.Format="{StaticResource A_String_01FormatString}"
                                                  local:MultiStringFormatter.Param0="{Binding ActiveSeason, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_SeasonToPolaroidLocation}}"
                                                  local:MultiStringFormatter.Param1="{Binding Image}"
                                                  ImageSource="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}" />
                                <local:FZMaterial Width="406"
                                                  Height="134"
                                                  VerticalAlignment="Bottom"
                                                  ImageSource="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_TreasureStateToLocText}}" />
                                <local:FZMaterial Width="174"
                                                  Height="174"
                                                  ImageSource="{Binding CollectedIcon}"
                                                  Margin="25,6"
                                                  VerticalAlignment="Top"
                                                  HorizontalAlignment="Right"
                                                  Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfRewardCollected}}" />
                            </Grid>
                            <Decorator Visibility="{Binding TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfLocked}}"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center">
                                <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/PDLC1/TreasureHunt/LockedItem.png"
                                                  Width="406"
                                                  Height="337" />
                            </Decorator>
                        </Grid>
                    </local:FZMaterial>
                </DockPanel>
            </Grid>
        </DataTemplate>

        <System:Double x:Key="A_Double_FullScreenCarousel_1ItemHigh_ListItemWidthOffset">573</System:Double>
        <System:Double x:Key="A_Double_FullScreenCarousel_1ItemHigh_ListItemWidth">426</System:Double>
        <System:Double x:Key="A_Double_FullScreenCarousel_1ItemHigh_ListItemHeight">711</System:Double>
        <System:Double x:Key="A_Double_FullScreenCarousel_1ItemHigh_ListHeight">711</System:Double>

        <Style x:Key="A_Style_FrameworkElement_CarouselSelectionScale_TreasureHuntItem"
               TargetType="FrameworkElement">
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <ScaleTransform />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding (Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                             Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)">
                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                            Value="1.03" />
                                </DoubleAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleY)">
                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                            Value="1.03" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)">
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                          Value="1.0"
                                                          EasingFunction="{local:CircleEasing}" />
                                </DoubleAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleY)">
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                          Value="1.0"
                                                          EasingFunction="{local:CircleEasing}" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_ContentControl_TreasureHuntItemContainer"
               BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle}"
               TargetType="ContentControl">
            <Style.Resources>
                <Style x:Key="A_Style_FrameworkElement_CarouselSelectionScale_Dynamic"
                       TargetType="FrameworkElement"
                       BasedOn="{StaticResource A_Style_FrameworkElement_CarouselSelectionScale_TreasureHuntItem}"/>

                <Style x:Key="A_Style_FZMaterial_MouseRollOverVisual_Dynamic"
                       BasedOn="{StaticResource A_Style_FZMaterial_MouseRollOverVisual_Default}"
                       TargetType="local:FZMaterial">
                    <Setter Property="Margin" Value="-0.5"/>
                    <Setter Property="Preset">
                        <Setter.Value>
                            <local:FZMaterialPresetRoundtangleStroke BasedOn="{StaticResource A_FZMaterialPresetRoundtangleStroke_Rollover_Outer_All}"
                                                                     CornerRadius="16"/>
                        </Setter.Value>
                    </Setter>
                </Style>

                <CornerRadius x:Key="A_Dynamic_CornerRadius_Carousel_SelectionStroke">22</CornerRadius>
                <Thickness x:Key="A_Dynamic_Thickness_Carousel_SelectionStroke">6.5</Thickness>
                <CornerRadius x:Key="A_CornerRadius_Dynamic_CarouselTile">16</CornerRadius>
            </Style.Resources>
        </Style>

        <Style TargetType="local:WrapListBox"
               x:Key="A_Style_Carousel_TreasureHunt">
            <Setter Property="Template"
                    Value="{StaticResource A_ControlTemplate_Carousel_Default}" />
            <Setter Property="ItemContainerStyle"
                    Value="{StaticResource A_Style_ContentControl_TreasureHuntItemContainer}" />
            <Setter Property="ItemTemplate"
                    Value="{StaticResource A_DataTemplate_TreasureHuntItem}" />
            <Setter Property="Height"
                    Value="{StaticResource A_Double_FullScreenCarousel_1ItemHigh_ListHeight}" />
            <Setter Property="Width"
                    Value="1920" />
            <Setter Property="ItemWidth"
                    Value="{StaticResource A_Double_FullScreenCarousel_1ItemHigh_ListItemWidth}" />
            <Setter Property="ItemHeight"
                    Value="{StaticResource A_Double_FullScreenCarousel_1ItemHigh_ListItemHeight}" />
            <Setter Property="SelectionLimitTop"
                    Value="{StaticResource A_Double_FullScreenCarousel_1ItemHigh_ListItemWidthOffset}" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
            <Setter Property="PageSize"
                    Value="1" />
            <Setter Property="Margin"
                    Value="-30,5" />
            <Setter Property="AlternationCount"
                    Value="10000" />
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_ShowOnMapButton"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_Default}"
               TargetType="{x:Type local:ControllerButtonControl}">
            <Setter Property="Visibility"
                    Value="{Binding SelectedItem.TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfChallengeCompleteOrRewardCollected}}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding CanShowOnMap, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="False">
                    <Setter Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </Page.Resources>

    <Grid>
        <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl Style="{StaticResource A_Style_PlayerBarControl_WithTokens}"
                                x:Name="TopBar" />

        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <local:ControllerButtonPanel x:Name="HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="B" Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_TreasureHuntShowOnMap}"
                                               Style="{StaticResource A_Style_ControllerButtonControl_ShowOnMapButton}" />
                <local:ControllerButtonControl Button="X"
                                               Description="{local:Loc HelpButtons.IDS_TreasureHuntPlayVO}"
                                               Visibility="{Binding SelectedItem.TreasureHuntItemState, Converter={StaticResource A_Converter_ShownIfUnlocked}}" />
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding_Opus}">
            <StackPanel VerticalAlignment="Bottom"
                Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                <Decorator HorizontalAlignment="Left"
                           VerticalAlignment="Top">
                    <ContentControl Content="{local:Loc ScreenTitles.IDS_TreasureHunt}"
                                    local:BindingProxy.A="/ForzaUI;component/Textures/Data_Bound/PDLC1/Title_TreasureHunt.png"
                                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                    x:Name="TitleBlock" />
                </Decorator>
                <Grid>
                    <local:WrapListBox Style="{StaticResource A_Style_Carousel_TreasureHunt}"
                                       SelectedItem="{Binding SelectedItem}"
                                       ItemsSource="{Binding Collection}"
                                       x:Name="Items"
                                       local:FocusOnPageFocusGained.SelectorSelectedItem="True" />

                    <local:NavigationArrows Style="{StaticResource A_Style_Control_NavigationArrows}"
                                            Margin="-40,0,-20,0"
                                            CanSelectPrev="{Binding CanSelectPrev, ElementName=Items}"
                                            CanSelectNext="{Binding CanSelectNext, ElementName=Items}"
                                            ScrollPagePrevCommand="{Binding ScrollPagePrevCommand, ElementName=Items}"
                                            ScrollPageNextCommand="{Binding ScrollPageNextCommand, ElementName=Items}" />
                </Grid>
            </StackPanel>
        </Border>
    </Grid>
</Page>
