<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">435</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"/>
            <Setter Property="Margin" Value="0,0,0,4"/>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_SubHeaderBlock"
            BasedOn="{StaticResource A_Style_FZTextBlock_SubTitle}"
            TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="FontFamily" Value="Horizon_A"/>
            <Setter Property="Color" Value="{StaticResource A_Color_Header_Text}"/>
            <Setter Property="CapHeight" Value="19"/>
            <Setter Property="Margin" Value="21, 0, 21, 0"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>

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

        <Style x:Key="A_Style_Run_PerkDescription_HIGHLIGHT" 
               TargetType="{x:Type local:FZRun}">
            <Setter Property="FontFamily" Value="Horizon_C" />
            <Setter Property="Color" Value="{StaticResource A_Color_AuctionHouse_Status_Winning}"/>
        </Style>

        <MappingConverter x:Key="A_MappingConverter_PerkDescription">
            <MappingConverterEntry Key="{NoCase HIGHLIGHT}" Value="{StaticResource A_Style_Run_PerkDescription_HIGHLIGHT}" />
        </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.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_AutoScroll_BusinessDescription" BasedOn="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}" TargetType="FZTextBlock">
            <Setter Property="Margin" Value="0" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="Stretch" Value="None" />
            <Setter Property="ClipToBounds" Value="True" />
            <Setter Property="AutoScroll" Value="{StaticResource H_AutoScrollSettings_Descriptions}" />
            <Setter Property="AutoScroll.AllowScrolling" Value="True" />
        </Style>
        <AutoScrollSettings x:Key="A_Style_AutoScrollSettings_PerkDescription" 
            ScrollSeparation="50"
            ScrollOrientation="Vertical"
            Speed="20"
            InitialPause="0:0:2.0"/>
        <Style x:Key="A_Style_AutoScroll_PerkDescription" BasedOn="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}" TargetType="FZTextBlock">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
            <Setter Property="CapHeight" Value="14" />
            <Setter Property="LineAdjust" Value="-0.1" />
            <Setter Property="Stretch" Value="None" />
            <Setter Property="AutoScroll.AllowScrolling" Value="True" />
            <Setter Property="TextWrapping" Value="Wrap"/>
            <Setter Property="AutoScroll" Value="{StaticResource A_Style_AutoScrollSettings_PerkDescription}" />
        </Style>
        
        <AutoScrollSettings x:Key="A_AutoScrollSettings_HouseDescription" 
            ScrollSeparation="50"
            ScrollOrientation="Vertical"
            Speed="20"
            InitialPause="0:0:2.0"/>
        <Style x:Key="A_Style_AutoScroll_HouseDescription" BasedOn="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}" TargetType="FZTextBlock">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
            <Setter Property="CapHeight" Value="15" />
            <Setter Property="Stretch" Value="None" />
            <Setter Property="AutoScroll.AllowScrolling" Value="True" />
            <Setter Property="TextWrapping" Value="Wrap"/>
            <Setter Property="AutoScroll" Value="{StaticResource A_AutoScrollSettings_HouseDescription}" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_OptionText_CostValue"
               BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}"
               TargetType="local:FZTextBlock">
            <Setter Property="Margin" Value="0" />
        </Style>

        <Style x:Key="A_Style_FZMaterial_OptionText_Strikethrough" TargetType="local:FZMaterial">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Black}"/>
            <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"/>
    </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="PART_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="PART_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}" 
                            local:BindingProxy.A="{Binding SceneEnum, Converter={StaticResource A_MappingConverter_SceneEnumToSceneTitleImageSource}}"
                            Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                            Width="{StaticResource A_Double_PlayerHousePurchasePanelWidth}"
                            Margin="0,0,0,4"
                            Focusable="False" />
                    </StackPanel>

                    <local:FZMaterial Style="{StaticResource H_Style_Container_GlassHighBlur_Description}" 
                                      Visibility="{Binding Description, Converter={StaticResource A_StringVisConverter}}"
                                      MaxHeight="200"
                                      Margin="0,0,0,5">
                        <FZTextBlock Text="{Binding Description}"
                                     MarkupConverter="{StaticResource A_MappingConverter_PerkDescription}"
                                     Style="{StaticResource A_Style_AutoScroll_HouseDescription}"
                                     Margin="20,18"/>
                    </local:FZMaterial>
                    
                    <ContentControl Style="{StaticResource A_Style_ContentControl_SlimHeader}" HorizontalContentAlignment="Center">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_SubHeaderBlock}" FontFamily="Horizon_C"
                            Text="{Binding SceneEnum, Converter={StaticResource A_MappingConverter_SceneEnumToRewardPanelHeaderString}}" />
                    </ContentControl>
                    <local:FZMaterial Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"
                                      Margin="0,2,0,4">
                        <StackPanel Margin="16,16,16,16">
                            <ItemsControl ItemsSource="{Binding Rewards}"
                                VerticalAlignment="Bottom">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <FZMaterial Margin="0,16,0,16" x:Name="RewardSeparator" VerticalAlignment="Bottom" Style="{StaticResource H_Style_StatDivider_InfoPanel}" Visibility="{Binding RelativeSource={RelativeSource PreviousData}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                                            <DockPanel Height="85" >
                                                <local:FZMaterial DockPanel.Dock="Left"
                                                    Style="{StaticResource A_Style_FZMaterial_RewardBacking_InnerAll}">
                                                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RewardIcon}"/>
                                                </local:FZMaterial>
                                                <DockPanel VerticalAlignment="Top"
                                                    Margin="10,2,0,0">
                                                    <local:FZTextBlock DockPanel.Dock="Top" Text="{Binding Description}"
                                                        Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                                        Color="{StaticResource H_Color_Primary_White}"
                                                        CapHeight="20"/>
                                                    <Decorator Height="15" DockPanel.Dock="Top"
                                                        Visibility="{Binding PerkDescription, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"/>

                                                    <FZTextBlock Style="{StaticResource A_Style_AutoScroll_PerkDescription}"
                                                        Text="{Binding PerkDescription}"
                                                        MarkupConverter="{StaticResource A_MappingConverter_PerkDescription}"
                                                        Visibility="{Binding PerkDescription, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"
                                                    />
                                                </DockPanel>
                                            </DockPanel>
                                        </StackPanel>

                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </local:FZMaterial>

                    <ContentControl Style="{StaticResource A_Style_ContentControl_SlimHeader}" Visibility="{Binding ShowPrice, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" HorizontalContentAlignment="Stretch">
                        <Grid>
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_SubHeaderBlock}"
                                               CapHeight="19"
                                               FontFamily="Horizon_B"
                                               Text="{local:Loc Festival.IDS_PlayerHouse_Price}" />
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center"
                                        HorizontalAlignment="Right" Margin="21, 0, 21, 0">
                                <Control Style="{StaticResource H_Style_Control_CreditsIcon}" Margin="-4,-4,6,-4"/>
                                <local:FZTextBlock Text="{Binding CostCredits, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}}"
                                               Style="{StaticResource A_Style_FZTextBlock_PropertyPurchaseCost}"/>
                            </StackPanel>
                        </Grid>
                    </ContentControl>

                    <Decorator Height="8"/>

                    <local:CommonListBox Style="{StaticResource A_Style_ListBox_TextMenu_Default}"
                                         ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_Gaps}"
                                         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}" 
                                                       Margin ="21, 0, 16,0"
                                                       TextAlignment="Left" 
                                                       DockPanel.Dock="Left"
                                                       FontFamily="Horizon_B"
                                                       MaxWidth="200"/>
                                    <Viewbox DockPanel.Dock="Right"
                                             StretchDirection="DownOnly"
                                             HorizontalAlignment="Right"
                                             x:Name="VIPCosts"
                                             Visibility="Collapsed"
                                             Margin="12,0,21,0">
                                        <local:FZTextBlock x:Name="FreeWithVIPText"
                                                            HorizontalAlignment="Right"
                                                            Text="{local:Loc Festival.IDS_PlayerHouse_FreeWithVIP}"
                                                            Style="{StaticResource A_Style_FZTextBlock_OptionText_CostValue}" />
                                    </Viewbox>
                                    <Viewbox StretchDirection="DownOnly"
                                             HorizontalAlignment="Right"
                                             x:Name="LinkedEntitlementCosts"
                                             Visibility="Collapsed"
                                             Margin="5,0,0,0">
                                        <StackPanel Orientation="Horizontal" 
                                                    HorizontalAlignment="Right"
                                                    Margin="0,0,16,0">
                                            <Control Style="{StaticResource H_Style_Control_CreditsIcon}" Margin="-4,-4,6,-4"/>
                                            <Grid HorizontalAlignment="Right" Margin="0,0,16,0">
                                                <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="FreeWithVIPText" Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.PurchaseWithVIP}">
                                        <Setter TargetName="VIPCosts" Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Value}" Value="{x:Static local:XAMLPropertyOption.UpsellToVIP}">
                                        <Setter TargetName="VIPCosts" Property="Visibility" Value="Visible" />
                                    </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>
