<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.A_PopupPurchaseOptions"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Page.Resources>
        <ResourceDictionary>
            <local:MappingConverter x:Key="A_Converter_VisibleIfFeaturedContentTypeNotExpansion"
                Default="{x:Static Visibility.Visible}">
                <local:MappingConverterEntry Key="{x:Static local:XAMLFeaturedContentType.Expansion}" Value="{x:Static Visibility.Collapsed}"/>
                <local:MappingConverterEntry Key="{x:Static local:XAMLFeaturedContentType.ExpansionPass}" Value="{x:Static Visibility.Collapsed}"/>
                <local:MappingConverterEntry Key="{x:Static local:XAMLFeaturedContentType.Bundle}" Value="{x:Static Visibility.Collapsed}"/>
            </local:MappingConverter>

            <Style x:Key="A_Style_FZTextBlock_MarketplaceItem_Info" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_TileText}">
                <Setter Property="Color" Value="{StaticResource A_Color_Tile_Title_Alternate}"/>
                <Setter Property="Margin" Value="0,10,0,0"/>
                <Setter Property="Visibility" Value="{Binding FeaturedContentType, Converter={StaticResource A_Converter_VisibleIfFeaturedContentTypeNotExpansion}}"/>
            </Style>

            <Style x:Key="A_Style_FrameworkElement_ElementWithTitle" TargetType="FrameworkElement">
                <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_SingleCar}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Car}">
                        <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_SingleCar}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPack}">
                        <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_CarPack}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPass}">
                        <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_SeasonPass}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.ExpansionPass}">
                        <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_ExpansionPass}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.VIPMembership}">
                        <Setter Property="Tag" Value="{local:Loc InGameMarketplace.IDS_VIPMembership}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Expansion}">
                        <Setter Property="Tag" Value="{Binding Title}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Bundle}">
                        <Setter Property="Tag" Value="{Binding Title}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <ControlTemplate x:Key="A_ControlTemplate_Button_PurchaseOptionsItem"
                             TargetType="local:FZButton">
                <Grid>
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TileShadow}" />
                    <ContentPresenter />
                    <ContentControl Style="{StaticResource A_Style_ContentControl_TileSelectionStroke}" />
                </Grid>
            </ControlTemplate>

            <ControlTemplate TargetType="ListBoxItem"
                             x:Key="A_Template_ListBoxItem_PurchaseOptions">
                <StackPanel Orientation="Horizontal">
                    <local:FZButton Focusable="True"
                            x:Name="ItemButton"
                            VerticalAlignment="Stretch"
                            Height="378"
                            Width="210"
                            local:UIPageTransitionManager.TransitionIndex="0"
                            Style="{StaticResource A_Style_Button_RootTile}"
                            Command="{Binding SelectCommand, RelativeSource={RelativeSource AncestorType=Page}}"
                            Template="{StaticResource A_ControlTemplate_Button_PurchaseOptionsItem}"
                            local:ScreenReader.Line=""
                            local:ScreenReader.LineType="QuickChatItem"> <!-- Clear this, as we don't want this control to read out the description, we do that manually -->
                        <ContentPresenter />
                    </local:FZButton>
                    <Grid Width="{StaticResource A_Double_Size_SunriseTileGap}" />
                </StackPanel>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsFocused, ElementName=ItemButton}"
                                 Value="True">
                        <Setter Property="local:ZPanel.ZIndex"
                                Value="100" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsPurchased}"
                                 Value="True">
                        <Setter Property="Opacity"
                                Value="0.5" />
                        <Setter Property="Focusable"
                                Value="False"
                                TargetName="ItemButton" />
                        <Setter Property="IsEnabled"
                                Value="False"
                                TargetName="ItemButton" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}"
                                 Value="{x:Static local:XAMLFeaturedContentType.Expansion}">
                        <Setter Property="Opacity"
                                Value="1" />
                        <Setter Property="Focusable"
                                Value="True"
                                TargetName="ItemButton" />
                        <Setter Property="IsEnabled"
                                Value="True"
                                TargetName="ItemButton" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <String x:Key="A_String_TitleFormat">{0}, {1}, {2}, {3}, {4}</String>

            <Style x:Key="A_Style_ListBoxItem_MarketplaceItem"
                   TargetType="ListBoxItem"
                   BasedOn="{StaticResource A_Style_FrameworkElement_ElementWithTitle}">
                <Setter Property="Focusable"
                        Value="False" />
                <Setter Property="local:RecursiveFocusOnMouseOverBehaviour.Self"
                        Value="True" />
                <Setter Property="Template"
                        Value="{StaticResource A_Template_ListBoxItem_PurchaseOptions}" />
                <Setter Property="Panel.ZIndex" Value="0"/>
                <Setter Property="local:ZPanel.ZOffset" Value="0"/>
                <Setter Property="local:MultiStringFormatter.Format" Value="{StaticResource A_String_TitleFormat}" />
                <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding Title}" />
                <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}" />
                <Setter Property="local:MultiStringFormatter.Param2" Value="{Binding ContentInfo}" />
                <Setter Property="local:MultiStringFormatter.Param3" Value="{Binding Price}" />
                <Setter Property="local:MultiStringFormatter.Param4" Value="{Binding Description}" />
                <Setter Property="local:ScreenReader.Event" Value="OnFocus" />
                <Setter Property="local:ScreenReader.LineType" Value="SelectedItem" />
                <Setter Property="local:ScreenReader.Line" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}" />
                <Setter Property="local:ScreenReader.SelectedNumber" Value="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource Self}, Converter={StaticResource A_IndexToNumberConverter}, FallbackValue=0}" />
                <Setter Property="local:ScreenReader.SelectedCount" Value="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}, FallbackValue=0}" />
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsKeyboardFocusWithin"
                             Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource A_Storyboard_Tile_Selected}"/>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard Storyboard="{StaticResource A_Storyboard_Tile_Unselected}"/>
                        </Trigger.ExitActions>
                        <Setter Property="IsSelected"
                                Value="True" />
                    </Trigger>
                    <DataTrigger Binding="{Binding IsPurchased}" Value="True">
                        <Setter Property="local:MultiStringFormatter.Param3" Value="{local:Loc InGameMarketplace.IDS_Purchased}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_MarketplaceItemIcon" TargetType="local:FZMaterial">
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Single_Car.png" />
                <Setter Property="Stretch" Value="Uniform"/>
                <Setter Property="StretchDirection" Value="Both"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Car}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Single_Car.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPack}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Car_Pack.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPass}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Car_Pass.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.ExpansionPass}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Expansion_Pass.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.VIPMembership}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/VIP_Pass.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Expansion}">
                        <Setter Property="ImageSource" Value="{Binding Image}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Bundle}">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Marketplace/Expansion_Pass.png" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_MarketplaceItemTitle" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_TileTitle}">
                <Setter Property="TextWrapping" Value="Wrap"/>
                <Setter Property="TextAlignment" Value="Center" />
                <Setter Property="MaxHeight" Value="68"/>
                <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_SingleCar}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Car}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_SingleCar}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPack}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_CarPack}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.CarPass}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_SeasonPass}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.ExpansionPass}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_ExpansionPass}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.VIPMembership}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{local:Loc InGameMarketplace.IDS_VIPMembership}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Expansion}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{Binding Title}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding FeaturedContentType}" Value="{x:Static local:XAMLFeaturedContentType.Bundle}">
                        <Setter Property="local:TextBlockInlineMarkup.Markup" Value="{Binding Title}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_PriceInfo" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_TileTitle}">
                <Setter Property="Color" Value="{StaticResource A_Color_Tile_Title_Alternate}"/>
                <Setter Property="Text" Value="{Binding Price}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsPurchased}" Value="True">
                        <Setter Property="Text" Value="{local:Loc InGameMarketplace.IDS_Purchased}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_ListBox_PurchaseOptions" TargetType="ListBox">
                <Setter Property="SelectedIndex" Value="0" />
                <Setter Property="ItemContainerStyle" Value="{StaticResource A_Style_ListBoxItem_MarketplaceItem}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBox">
                            <StackPanel Orientation="Horizontal" IsItemsHost="True" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <DockPanel>
                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_FlatPanel_FooterPanel}" Height="90" DockPanel.Dock="Bottom">
                                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">
                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PriceInfo}"
                                            HorizontalAlignment="Center"/>
                                        <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding ContentInfo}"
                                            Style="{StaticResource A_Style_FZTextBlock_MarketplaceItem_Info}"
                                            HorizontalAlignment="Center"/>
                                    </StackPanel>
                                </local:FZMaterial>
                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TileBackground_NoAlternate}"
                                    Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterTopOnly}">
                                    <Grid>
                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_MarketplaceItemTitle}" 
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Top"
                                            Margin="18,20"/>
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_MarketplaceItemIcon}"
                                                      Height="126" Width="126"
                                                      HorizontalAlignment="Center"
                                                      VerticalAlignment="Bottom"
                                                      Margin="0,0,0,57" />
                                    </Grid>
                                </local:FZMaterial>
                            </DockPanel>
                        </DataTemplate>
                    </Setter.Value> 
                </Setter>
            </Style>

            <Style x:Key="A_Style_Run_Purchase_CarDetails" TargetType="local:FZRun">
                <Setter Property="FontFamily" Value="Horizon_C" />
                <Setter Property="FontSize" Value="19" />
            </Style>

            <Style x:Key="A_Style_AutoScrollPanel_PopupPurchaseOptions" BasedOn="{StaticResource A_Style_AutoScrollPanel_Masked}" TargetType="local:AutoScrollPanel">
                <Style.Resources>
                    <ControlTemplate x:Key="A_ControlTemplate_AutoscrollTemplate_Dynamic">
                        <StackPanel>
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                                               Text="{local:Loc InGameMarketplace.IDS_UltimateAddOnDisclaimer}"
                                               Visibility="{Binding AnimationContext.IsPartOfUltimateBundle, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AutoScrollPanel}, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"
                                               Margin="0,0,0,33"
                                               TextWrapping="Wrap" />
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                                               Text="{local:Loc InGameMarketplace.IDS_CarPackDisclaimer}"
                                               Visibility="{Binding AnimationContext.IsPartOfSeasonPass, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AutoScrollPanel}, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"
                                               Margin="0,0,0,33"
                                               TextWrapping="Wrap" />
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                                               Text="{local:Loc InGameMarketplace.IDS_ExpansionPassDisclaimer}"
                                               Visibility="{Binding AnimationContext.IsPartOfExpansionPass, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AutoScrollPanel}, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"
                                               Margin="0,0,0,33"
                                               TextWrapping="Wrap" />
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                                           local:TextBlockInlineMarkup.Markup="{Binding AnimationContext.Description, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AutoScrollPanel}}"
                                           local:TextBlockInlineMarkup.ResourceBaseName="A_Style_Run_Purchase_"
                                           TextWrapping="Wrap" />
                        </StackPanel>
                    </ControlTemplate>
                </Style.Resources>
            </Style>

            <ControlTemplate x:Key="A_ControlTemplate_SidePanelContent" TargetType="ContentControl">
                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_GlassPanel_PopupPanel}" >
                    <ContentPresenter/>
                </local:FZMaterial>
            </ControlTemplate>

        </ResourceDictionary>
    </Page.Resources>

    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Popup}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Border x:Name="LayoutRoot">
        <Grid>
            <!-- Background Blur -->
            <local:FZMaterialGlassCapture />
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"/>

            <!-- Help Button Bar -->
            <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
                <ContentControl x:Name="DefaultHelpPanel"
                    local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                    local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                    Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>

            <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
                <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"
                    Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">

                    <ContentControl Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                    Content="{local:Loc InGameMarketplace.IDS_UpsellTitle}" 
                                    local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Car.png"
                                    HorizontalAlignment="Left"
                                    local:ScreenReader.Line="{Binding Content, RelativeSource={RelativeSource Self}}"
                                    local:ScreenReader.LineType="ScreenTitle"
                                    local:ScreenReader.Event="OnLoad" />

                    <StackPanel Orientation="Horizontal"
                                Height="378">
                        <local:CommonListBox x:Name="Menu"
                                             ItemsSource="{Binding PurchaseOptions}"
                                             Style="{StaticResource A_Style_ListBox_PurchaseOptions}"
                                             local:ZPanel.ZIndex="1"
                                             AlternationCount="10000"/>
                        <ContentControl Width="500"
                                        Template="{StaticResource A_ControlTemplate_SidePanel}"
                                        Tag="{local:Loc InGameMarketplace.IDS_Description}">
                            <Decorator Margin="24">
                                <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_PopupPurchaseOptions}"
                                                   AnimationContext="{Binding SelectedItem, ElementName=Menu}"
                                                   Visibility="{Binding Path=HasItems, ElementName=Menu, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                            </Decorator>
                        </ContentControl>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </Grid>
    </Border>
</Page>
