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

    <Page.Resources>
        <System:Double x:Key="A_Double_PlayerHousePurchasePanelWidth">468</System:Double>

        <Style x:Key="A_Style_ContentControl_SlimHeader"
            BasedOn="{StaticResource A_Style_ContentControl_Header_Custom}"
            TargetType="{x:Type ContentControl}">
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="Height" Value="48"/>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_SubHeaderBlock"
            BasedOn="{StaticResource A_Style_FZTextBlock_SubTitle}"
            TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="Color" Value="{StaticResource A_Color_Header_Text}"/>
            <Setter Property="CapHeight" Value="15"/>
            <Setter Property="Margin" Value="24, 15"/>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_PropertyPurchaseCost"
            BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}"
            TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="Color" Value="{StaticResource A_Color_Header_Background}"/>
            <Setter Property="CapHeight" Value="33"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>


        <local:MappingConverter x:Key="A_MappingConverter_RewardTypeToColor"
            Default="{StaticResource A_Color_Header_Background}">
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_MappingConverter_SceneEnumToSceneTitleImageSource"
            Default="/ForzaUI;component/Textures/Anthem/Icons/Titles/PlayerHouses.png">
            <local:MappingConverterEntry Key="{x:Static local:SceneEntryEnum.PlayerBusinessPurchase}" Value="/ForzaUI;component/Textures/Anthem/Icons/Titles/PlayerBusiness.png"/>
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_MappingConverter_SceneEnumToRewardPanelHeaderString"
            Default="{local:Loc Festival.IDS_PlayerHouse_Rewards}">
            <local:MappingConverterEntry Key="{x:Static local:SceneEntryEnum.PlayerBusinessPurchase}" Value="{local:Loc Festival.IDS_PlayerBusiness_Description}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_RewardTypeShouldUseThumbnail" Default="{StaticResource A_Boolean_False}">
            <local:MappingConverterEntry Key="{x:Static local:UIRewardType.Perk}" Value="{StaticResource A_Boolean_True}" />
            <local:MappingConverterEntry Key="{x:Static local:UIRewardType.HorizonStory}" Value="{StaticResource A_Boolean_True}" />
            <local:MappingConverterEntry Key="{x:Static local:UIRewardType.Collectable}" Value="{StaticResource A_Boolean_True}" />
            <local:MappingConverterEntry Key="{x:Static local:UIRewardType.CareerRaceCollection}" Value="{StaticResource A_Boolean_True}" />
            <local:MappingConverterEntry Key="{x:Static local:UIRewardType.Currency}" Value="{StaticResource A_Boolean_True}" />
        </local:MappingConverter>

        <Style x:Key="A_Style_FZMaterial_RewardIcon"
            TargetType="{x:Type local:FZMaterial}">
            <Setter Property="Width" Value="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
            <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"/>
            <Setter Property="ImageSource" Value="{Binding RewardType, Converter={StaticResource A_Converter_RewardTypeToIcon}}"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Thumbnail, Converter={StaticResource A_StringVisConverter}}" Value="{x:Static Visibility.Visible}"/>
                        <Condition Binding="{Binding RewardType, Converter={StaticResource A_Converter_RewardTypeShouldUseThumbnail}}" Value="{StaticResource A_Boolean_True}"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="ImageSource" Value="{Binding Thumbnail}"/>
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding SmallThumbnail, Converter={StaticResource A_StringVisConverter}}" Value="{x:Static Visibility.Visible}"/>
                        <Condition Binding="{Binding RewardType, Converter={StaticResource A_Converter_RewardTypeShouldUseThumbnail}}" Value="{StaticResource A_Boolean_True}"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="ImageSource" Value="{Binding SmallThumbnail}"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_AutoScrollPanel_BusinessDescription" BasedOn="{StaticResource A_Style_AutoScrollPanel_Masked}" TargetType="local:AutoScrollPanel">
            <Style.Resources>
                <ControlTemplate x:Key="A_ControlTemplate_AutoscrollTemplate_Dynamic">
                    <local:FZTextBlock Text="{Binding Description}"
                        Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                        Margin="0"
                        TextWrapping="Wrap" />
                </ControlTemplate>
            </Style.Resources>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_OptionText_CostValue"
               BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}"
               TargetType="local:FZTextBlock">
            <Style.Resources>
                <Color x:Key="A_Color_TextMenu_Text_Dynamic">#FF00B18D</Color>
            </Style.Resources>
        </Style>

        <Style x:Key="A_Style_FZMaterial_OptionText_Strikethrough" TargetType="local:FZMaterial">
            <Setter Property="Color" Value="#FF00B18D" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}"
                             Value="True">
                    <Setter Property="Color"
                            Value="{StaticResource A_Color_TextMenu_Text_Highlighted}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <local:NumUnitConverter x:Key="A_NumUnitConverter_CreditsConverter" FractionDigits="0" FormatString="UnitStrings.IDS_Units_Credits_Format"/>
    </Page.Resources>

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

    <Grid>
        <!-- Bars -->
        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />
        <ContentControl x:Name="BottomBar"
                        Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="DefaultHelpPanel"
                            local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <Grid Style="{StaticResource A_Style_FrameworkElement_ScreenTilt}" Focusable="False" >
                <StackPanel x:Name="LayoutRoot"
                    Orientation="Vertical"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Left"
                    Width="{StaticResource A_Double_PlayerHousePurchasePanelWidth}"
                    Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl Content="{Binding Title, Converter={StaticResource A_StringToUpper}}"
                            local:BindingProxy.A="{Binding SceneEnum, Converter={StaticResource A_MappingConverter_SceneEnumToSceneTitleImageSource}}"
                            Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                            Focusable="False" />
                    </StackPanel>

                    <ContentControl Style="{StaticResource A_Style_ContentControl_SlimHeader}">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_SubHeaderBlock}"
                            Text="{Binding SceneEnum, Converter={StaticResource A_MappingConverter_SceneEnumToRewardPanelHeaderString}}" />
                    </ContentControl>
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_GlassPanel_BodyPanel}">
                        <StackPanel Margin="12,9">
                            <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_BusinessDescription}"
                                Margin="14,9,14,18"
                                Height="163"
                                AnimationContext="{Binding Description}"
                                Visibility="{Binding Description, Converter={StaticResource A_StringVisConverter}}"/>

                            <ItemsControl ItemsSource="{Binding Rewards}"
                                VerticalAlignment="Bottom">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_GlassPanel_Interactive}"
                                        Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_InnerAll}"
                                        Color="#66262626"
                                        Margin="0,3"
                                        Height="94">
                                            <DockPanel Margin="6">
                                                <local:FZMaterial DockPanel.Dock="Left"
                                                    Style="{StaticResource A_Style_FZMaterial_RewardBacking_InnerAll}">
                                                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RewardIcon}"/>
                                                </local:FZMaterial>
                                                <StackPanel VerticalAlignment="Center"
                                                    Margin="26,0,0,0">
                                                    <local:FZTextBlock Text="{Binding Description, Converter={StaticResource A_StringToUpper}}"
                                                        Style="{StaticResource A_Style_FZTextBlock_Heading}"
                                                        Color="{StaticResource A_Color_Header_Text}"
                                                        CapHeight="18"/>
                                                    <Decorator Height="10"
                                                        Visibility="{Binding PerkDescription, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"/>
                                                    <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_Masked}"
                                                        MaxHeight="30"
                                                        Orientation="Horizontal"
                                                        AnimationContext="{Binding PerkDescription}"
                                                        Visibility="{Binding PerkDescription, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}">
                                                        <local:AutoScrollPanel.Resources>
                                                            <ControlTemplate x:Key="A_ControlTemplate_AutoscrollTemplate_Dynamic">
                                                                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonB}"
                                                                    Text="{Binding PerkDescription}" 
                                                                    Color="{StaticResource A_Color_Header_Text}"
                                                                    CapHeight="15"
                                                                    Stretch="None"
                                                                    VerticalAlignment="Center" />
                                                            </ControlTemplate>
                                                        </local:AutoScrollPanel.Resources>
                                                    </local:AutoScrollPanel>
                                                </StackPanel>
                                            </DockPanel>
                                        </local:FZMaterial>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </local:FZMaterial>

                    <Decorator Height="6"
                               Visibility="{Binding ShowPrice, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>

                    <ContentControl Style="{StaticResource A_Style_ContentControl_SlimHeader}" Visibility="{Binding ShowPrice, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_SubHeaderBlock}" Text="{local:Loc Festival.IDS_PlayerHouse_Price}" />
                    </ContentControl>
                    <local:FZMaterial Height="80"
                        Color="{StaticResource A_Color_Tile_Background}"
                        Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterBottomOnly}" Visibility="{Binding ShowPrice, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                        <DockPanel Margin="19" DockPanel.LastChildFill="False">
                            <DockPanel DockPanel.Dock="Left">
                                <local:FZMaterial Width="42" Height="42"
                                    ImageSource="/ForzaUI;component/Textures/Anthem/Icons/CRIcon/CR_85_FilledCircle.png"
                                    Color="{StaticResource A_Color_Header_Background}"
                                    Margin="0,0,10,0"/>
                                <local:FZTextBlock Text="{Binding CostCredits, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}}"
                                    Style="{StaticResource A_Style_FZTextBlock_PropertyPurchaseCost}"/>
                            </DockPanel>
                            <DockPanel DockPanel.Dock="Right"
                                Visibility="{Binding AreTokensEnabled, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                <local:FZMaterial Width="42" Height="42"
                                    ImageSource="/ForzaUI;component/Textures/Anthem/Icons/TokenIcon/Token_85_FilledCircle.png"
                                    Color="{StaticResource A_Color_Header_Background}"
                                    Margin="10,0,10,0"/>
                                <local:FZTextBlock Text="{Binding CostTokens, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}}"
                                    Style="{StaticResource A_Style_FZTextBlock_PropertyPurchaseCost}"/>
                            </DockPanel>
                        </DockPanel>
                    </local:FZMaterial>

                    <Decorator Height="12"/>

                    <local:CommonListBox Style="{StaticResource A_Style_ListBox_TextMenu_Default}"
                        SelectedItem="{Binding SelectedItem}"
                        ItemsSource="{Binding Options}"
                        x:Name="PART_List"
                        local:FocusOnPageFocusGained.SelectorSelectedItem="True">
                        <local:CommonListBox.ItemTemplate>
                            <DataTemplate>
                                <DockPanel IsHitTestVisible="False" Height="{StaticResource A_Double_TextMenu_Height_Default}">
                                    <local:FZTextBlock Text="{Binding Text}" 
                                                       Style="{StaticResource A_Style_FZTextBlock_OptionText}" 
                                                       TextAlignment="Left" 
                                                       DockPanel.Dock="Left"
                                                       MaxWidth="200"/>
                                    <Viewbox StretchDirection="DownOnly"
                                             HorizontalAlignment="Right"
                                             x:Name="VIPCosts"
                                             Visibility="Collapsed"
                                             Margin="5,0,0,0">
                                        <StackPanel Orientation="Horizontal" 
                                                    HorizontalAlignment="Right">
                                            <Grid HorizontalAlignment="Right">
                                                <local:FZTextBlock x:Name="CostText"
                                                                   Text="{Binding CostCredits, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_NumUnitConverter_CreditsConverter}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_OptionText_CostValue}"/>
                                                <local:FZMaterial x:Name="CostStrikethrough"
                                                                  Style="{StaticResource A_Style_FZMaterial_OptionText_Strikethrough}" 
                                                                  Height="2" />
                                            </Grid>
                                            <local:FZTextBlock x:Name="FreeWithVIPText"
                                                               Text="{local:Loc Festival.IDS_PlayerHouse_FreeWithVIP}"
                                                               Style="{StaticResource A_Style_FZTextBlock_OptionText_CostValue}" />
                                        </StackPanel>
                                    </Viewbox>
                                    <Viewbox StretchDirection="DownOnly"
                                             HorizontalAlignment="Right"
                                             x:Name="LinkedEntitlementCosts"
                                             Visibility="Collapsed"
                                             Margin="5,0,0,0">
                                        <StackPanel Orientation="Horizontal" 
                                                    HorizontalAlignment="Right">
                                            <Grid HorizontalAlignment="Right">
                                                <local:FZTextBlock Text="{Binding CostCredits, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_NumUnitConverter_CreditsConverter}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_OptionText_CostValue}"/>
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_OptionText_Strikethrough}" 
                                                                  Height="2" />
                                            </Grid>

                                            <local:FZTextBlock local:MultiStringFormatter.Format="{local:Loc Festival.IDS_PlayerHouse_FreeWithFormat}"
                                                               local:MultiStringFormatter.Param0="{Binding LinkedEntitlementName, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_StringToUpper}}"
                                                               Text="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                                                               Style="{StaticResource A_Style_FZTextBlock_OptionText_CostValue}" />
                                        </StackPanel>
                                    </Viewbox>
                                </DockPanel>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.PurchaseWithoutVIP}">
                                        <Setter TargetName="VIPCosts" Property="Visibility" Value="Visible" />
                                        <Setter TargetName="CostStrikethrough" Property="Visibility" Value="Collapsed" />
                                        <Setter TargetName="FreeWithVIPText" Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.PurchaseWithVIP}">
                                        <Setter TargetName="VIPCosts" Property="Visibility" Value="Visible" />
                                        <Setter TargetName="CostText" Property="Margin" Value="0" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.UpsellToVIP}">
                                        <Setter TargetName="VIPCosts" Property="Visibility" Value="Visible" />
                                        <Setter TargetName="CostText" Property="Margin" Value="0" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.PurchaseWithLinkedEntitlement}">
                                        <Setter TargetName="LinkedEntitlementCosts" Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </local:CommonListBox.ItemTemplate>
                    </local:CommonListBox>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
