<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:devonly="http://schemas.playground-games.com/xaml/devonly"
      devonly:DevOnly="devonly"
      x:Class="ForzaUI.A_CampaignCollectionItemInfo"
      x:Name="page"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}}">
    <Page.Resources>
        <AutoScrollSettings x:Key="A_AutoScrollSettings_Collection"
                            ScrollSeparation="100"
                            InitialPause="0:0:0.5"
                            Speed="40"
                            ScrollOrientation="Horizontal"
                            ApplyClip="True" />
        <AutoScrollSettings x:Key="A_AutoScrollSettings_CollectionInfo"
            Speed="20"
            ScrollOrientation="Vertical"
            InitialPause="0:0:5.0"
            ScrollSeparation="50"/>

        <DataTemplate x:Key="H_Template_CollectionCampaignItem">
            <Grid local:MultiStringFormatter.Format="{local:Loc Campaign.IDS_ScreenReader_Campaign_TitleAndSubtitleAndState}"
                  local:MultiStringFormatter.Param0="{Binding Title}"
                  local:MultiStringFormatter.Param1="{Binding Subtitle}"
                  local:MultiStringFormatter.Param2="{Binding (local:MultiStringFormatter.Output), ElementName=currency}"
                  local:ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                  local:ScreenReader.LineType="SelectedItem"
                  local:ScreenReader.Event="OnChange">
                <FZMaterial Color="{StaticResource H_Color_Primary_White}"
                            Preset="{Roundtangle CornerRadius=5}" />
                <DockPanel>
                    <Grid Width="372"
                          Height="210"
                          Margin="12,12,12,0"
                          DockPanel.Dock="Top">
                        <FZMaterial x:Name="icon_border" Visibility="{Binding SelectedItem.Category.Id, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource H_Converter_CollectionIconBorderVisibility}}" Color="{StaticResource H_Color_Primary_Grey_80pc}" Preset="{RoundtangleStroke Thickness=2}"/>
                        <FZMaterial ImageSource="{Binding CampaignId, ElementName=page, Converter={StaticResource H_Converter_CampaignToItemTexture}}"
                                    x:Name="icon_texture"
                                    GreedyMeasure="True"
                                    Stretch="Uniform" />
                        
                        <ContentPresenter x:Name="map_route" Content="{Binding RouteData}" Visibility="{Binding Content, RelativeSource={RelativeSource Self}, Converter={FZBooleanToVisibilityConverter}}" ContentTemplate="{StaticResource H_Template_ItemMapContent}"/>

                        <Grid x:Name="currency"
                              Height="26"
                              Margin="10"
                              VerticalAlignment="Bottom"
                              HorizontalAlignment="Left">
                            <FZMaterial Color="Black"
                                        Preset="{Roundtangle CornerRadius=13}" />
                            <StackPanel Orientation="Horizontal">
                                <FZTextBlock Margin="8,0,2,0"
                                             VerticalAlignment="Center"
                                             CapHeight="14"
                                             Text="{Binding Currency}"
                                             Color="{StaticResource H_Color_Primary_White}" />
                                <Control Style="{Binding CampaignId, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource H_Converter_CampaignToCurrencyControlStyle}}" />
                            </StackPanel>
                        </Grid>

                        <FZMaterial x:Name="rarity" 
                            Style="{StaticResource H_Style_Collection_Rarity}">
                            <FZTextBlock 
                                Text="{Binding Rarity, Converter={StaticResource A_Converter_RarityToNameString}}"
                                CapHeight="14"
                                Style="{StaticResource A_Style_FZMaterial_RarityTagText}"/>
                        </FZMaterial>
                    </Grid>
                    <StackPanel HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Margin="12,0">
                        <Decorator HorizontalAlignment="Center">
                            <FZTextBlock Text="{Binding Title}"
                                         x:Name="title"
                                         HorizontalAlignment="Stretch"
                                         Color="{StaticResource H_Color_Primary_Black}"
                                         TextTrimming="None"
                                         FontFamily="Horizon_A"
                                         Stretch="None"
                                         TextWrapping="NoWrap"
                                         AutoScroll="{StaticResource A_AutoScrollSettings_Collection}"
                                         AutoScroll.AllowScrolling="True"
                                         CapHeight="21"
                                         MarkupConverter="{StaticResource H_Converter_CollectionTitleMarkup}" />
                        </Decorator>
                        <Decorator HorizontalAlignment="Center">
                            <FZTextBlock Text="{Binding Subtitle}"
                                         x:Name="subtitle"
                                         Color="{StaticResource H_Color_Grey}"
                                         FontFamily="Horizon_A"
                                         TextTrimming="None"
                                         Stretch="None"
                                         TextWrapping="NoWrap"
                                         HorizontalAlignment="Stretch"
                                         CapHeight="15"
                                         Visibility="Collapsed"
                                         Margin="0,10,0,0"
                                         AutoScroll="{StaticResource A_AutoScrollSettings_Collection}"
                                         AutoScroll.AllowScrolling="True"
                                         MarkupConverter="{StaticResource H_Converter_CollectionTitleMarkup}" />
                        </Decorator>
                    </StackPanel>
                </DockPanel>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=(Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                             Value="True">
                    <Setter TargetName="title"
                            Property="TextTrimming"
                            Value="None" />
                    <Setter TargetName="title"
                            Property="AutoScroll.AllowScrolling"
                            Value="True" />
                    <Setter TargetName="subtitle"
                            Property="TextTrimming"
                            Value="None" />
                    <Setter TargetName="subtitle"
                            Property="AutoScroll.AllowScrolling"
                            Value="True" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Complete}"
                             Value="False">
                    <Setter TargetName="icon_border"
                            Property="Visibility"
                            Value="Collapsed" />
                    <Setter TargetName="map_route"
                            Property="Visibility"
                            Value="Collapsed" />
                    <Setter TargetName="rarity" 
                            Property="Visibility" 
                            Value="Collapsed"/>
                    <Setter TargetName="currency" Property="local:MultiStringFormatter.Format" Value="{Binding CampaignId, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource H_Converter_CampaignToScreenReadableCurrencyFormat}}"/>
                    <Setter TargetName="currency" Property="local:MultiStringFormatter.Param0" Value="{Binding Currency}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Complete}"
                             Value="True">
                    <Setter TargetName="icon_texture"
                            Property="ImageSource"
                            Value="{Binding IconPath}" />
                    <Setter TargetName="currency"
                            Property="Visibility"
                            Value="Collapsed" />
                    <Setter TargetName="currency" Property="local:MultiStringFormatter.Format" Value="{Loc Campaign.IDS_ScreenReader_Campaign_ItemState_Completed}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Subtitle, Converter={StringVisConverter}}"
                             Value="{x:Static Visibility.Visible}">
                    <Setter TargetName="title"
                            Property="CapHeight"
                            Value="19" />
                    <Setter TargetName="subtitle" 
                            Property="Visibility"
                            Value="Visible"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <Style x:Key="H_Run_InfoDescriptionHighlight"
               TargetType="FZRun">
            <Setter Property="Color"
                    Value="{StaticResource H_Color_Primary_Yellow}" />
        </Style>
        <MappingConverter x:Key="H_Converter_InfoDescription">
            <MappingConverterEntry Key="{NoCase highlight}"
                                   Value="{StaticResource H_Run_InfoDescriptionHighlight}" />
        </MappingConverter>
        <Thickness x:Key="H_Thickness_Invert">-1</Thickness>
        <ControlTemplate x:Key="H_Template_LeftRightButton"
                         TargetType="FZButton">
            <Grid Width="56"
                  Height="56">
                <Viewbox Margin="-5"
                         x:Name="stroke"
                         Visibility="Collapsed"
                         IsHitTestVisible="False">
                    <FZMaterial Width="56"
                                Height="56"
                                Preset="{RoundtangleStroke CornerRadius=28, Thickness=6}"
                                Color="{StaticResource H_Color_Primary_White}" />
                </Viewbox>
                <FZMaterial Color="{Binding CampaignId, Converter={StaticResource H_Converter_CampaignToColour}}"
                            ImageSource="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Arrow_Icon.png" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver"
                         Value="True">
                    <Setter TargetName="stroke"
                            Property="Visibility"
                            Value="Visible" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <MappingConverter x:Key="H_Converter_CampaignToBackground"
                          Default="">
            <MappingConverterEntry Key="{StaticResource H_Id_DiscoverCampaign}"
                                   Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Info_Background_Discover.png" />
            <MappingConverterEntry Key="{StaticResource H_Id_FestivalCampaign}"
                                   Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Info_Background.png" />
        </MappingConverter>

        <DataTemplate x:Key="H_Template_Info_Icon">
            <Decorator MaxHeight="56"
                       MinHeight="19"
                       Width="56"
                       VerticalAlignment="Top"
                       HorizontalAlignment="Left">
                <FZMaterial Stretch="Uniform"
                            Width="56"
                            Height="56"
                            VerticalAlignment="Center"
                            ImageSource="{Binding}" />
            </Decorator>
        </DataTemplate>

        <Style x:Key="H_Style_InfoText" TargetType="FZTextBlock">
            <Setter Property="MarkupConverter" Value="{StaticResource H_Converter_InfoDescription}" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="80,0,0,0" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="LineAdjust" Value="-0.5" />
            <Setter Property="FontFamily" Value="Horizon_D" />
            <Setter Property="CapHeight" Value="19" />
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
        </Style>

        <MappingConverter x:Key="H_Converter_SwappingModeToSwapButton" Default="X">
            <MappingConverterEntry Key="True" Value="A"/>
        </MappingConverter>

    </Page.Resources>
    <UIPageTransitionManager.TransitionManager>
        <UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}" />
    </UIPageTransitionManager.TransitionManager>
    <Grid>
        <!--PageInputHandler x:Name="lb_button"
                          Button="LBumper"
                          Command="{Binding ScrollPagePrevCommand, ElementName=tab_bar}" />
        <PageInputHandler x:Name="rb_button"
                          Button="RBumper"
                          Command="{Binding ScrollPageNextCommand, ElementName=tab_bar}" /-->
        <FZMaterialGlassCapture />
        <FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}" />
        <FZMaterial Color="#000"
                    Opacity="0.4" />
        <FZMaterialGlassCapture />
        <!--PageInputHandler x:Name="a_button"
                          Button="A"
                          Command="{Binding SelectCommand}" /-->
        <PageInputHandler x:Name="b_button"
                          Button="B"
                          Command="{Binding BackCommand}" />
        <PageInputHandler x:Name="swap_button"
                          Button="{Binding SwappingMode, Converter={StaticResource H_Converter_SwappingModeToSwapButton}}"
                          Command="{Binding SelectCommand}" />
        <PageInputHandler x:Name="purchase_button"
                          Button="Start"
                          Command="{Binding PurchaseCommand}" />
        <ContentControl x:Name="BottomBar"
                        Panel.ZIndex="10"
                        Style="{StaticResource A_Style_ButtonBar}">
            <ControllerButtonPanel x:Name="PART_HelpPanel"
                                   Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <ControllerButtonControl Button="DPadLeft"
                                         Description="{Loc HelpButtons.IDS_Previous}"
                                         Command="{Binding LeftCommand}" />
                <ControllerButtonControl Button="DPadRight"
                                         Description="{Loc HelpButtons.IDS_Next}"
                                         Command="{Binding RightCommand}" />
                <ControllerButtonControl Button="{Binding Button, ElementName=b_button}"
                                         Description="{Loc HelpButtons.IDS_Back}"
                                         Visibility="{Binding Command.Enabled, FallbackValue=Collapsed, Converter={FZBooleanToVisibilityConverter}, ElementName=b_button}" />
                <ControllerButtonControl Button="{Binding Button, ElementName=swap_button}"
                                         Description="{Binding Command.Name, ElementName=swap_button}"
                                         Visibility="{Binding Command.Enabled, FallbackValue=Collapsed, Converter={FZBooleanToVisibilityConverter}, ElementName=swap_button}" />
                <ControllerButtonControl Button="{Binding Button, ElementName=purchase_button}"
                                         Description="{Loc HelpButtons.IDS_Purchase}"
                                         Visibility="{Binding Command.Enabled, FallbackValue=Collapsed, Converter={FZBooleanToVisibilityConverter}, ElementName=purchase_button}" />
                <!--ControllerButtonControl
                    Button="{Binding Button, ElementName=lb_button}"
                    Description="xPrev milestone"
                    Visibility="{Binding Command, FallbackValue=Collapsed, Converter={CompareConverter Value={x:Null}, Equal={x:Static Visibility.Collapsed}, NotEqual={x:Static Visibility.Visible}}, ElementName=lb_button}" />
                <ControllerButtonControl
                    Button="{Binding Button, ElementName=rb_button}"
                    Description="xNext milestone"
                    Visibility="{Binding Command, FallbackValue=Collapsed, Converter={CompareConverter Value={x:Null}, Equal={x:Static Visibility.Collapsed}, NotEqual={x:Static Visibility.Visible}}, ElementName=rb_button}" /-->
            </ControllerButtonPanel>
        </ContentControl>
        <Border Style="{StaticResource A_Style_Border_ScenePadding_Opus}"
                SnapsToDevicePixels="True"
                UseLayoutRounding="True"
                x:Name="root">
            <Grid HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  Width="1074"
                  Height="500"
                  Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                  UIPageTransitionManager.TransitionIndex="0">
                <FZMaterial x:Name="background"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            GetSizeFromTexture="True"
                            ImageSource="{Binding CampaignId, Converter={StaticResource H_Converter_CampaignToBackground}}" />
                <Grid HorizontalAlignment="Left"
                      VerticalAlignment="Top">
                    <Decorator.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="-1" />
                        </TransformGroup>
                    </Decorator.RenderTransform>
                    <FZButton Template="{StaticResource H_Template_LeftRightButton}"
                              Margin="46,72"
                              RenderTransformOrigin="0.5,0.5"
                              Command="{Binding LeftCommand}">
                        <FZButton.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="-1" />
                            </TransformGroup>
                        </FZButton.RenderTransform>
                    </FZButton>
                </Grid>
                <Grid HorizontalAlignment="Right"
                      VerticalAlignment="Top"
                      RenderTransformOrigin="1,0.5">
                    <Decorator.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="-1" />
                        </TransformGroup>
                    </Decorator.RenderTransform>
                    <FZButton Template="{StaticResource H_Template_LeftRightButton}"
                              Margin="46,72"
                              Command="{Binding RightCommand}"></FZButton>
                </Grid>
                <DockPanel Margin="50,0">
                    <Grid DockPanel.Dock="Top">
                        <FZMaterial ImageSource="{Binding SelectedItem.Category.IconPath}"
                                    Width="138"
                                    Margin="0,-80,0,0"
                                    Stretch="UniformToFill"
                                    VerticalAlignment="Top" />
                        <StackPanel Margin="0,44,0,0">
                            <FZTextBlock HorizontalAlignment="Center"
                                         Text="{Binding SelectedItem.Category.Name}"
                                         FontFamily="Horizon_C"
                                         CapHeight="27"
                                         Color="{StaticResource H_Color_Primary_White}" />
                            <Decorator Height="16" />
                            <StackPanel Orientation="Horizontal"
                                        HorizontalAlignment="Center">
                                <FZTextBlock FontFamily="Horizon_C"
                                             CapHeight="21"
                                             Color="{StaticResource H_Color_Primary_Yellow}"
                                             VerticalAlignment="Center">
                                    <FZRun Text="{Binding SelectedItem.Category.Progress, Converter={NumUnitConverter FractionDigits=0}}" />
                                    <FZRun Text="/" />
                                    <FZRun Text="{Binding SelectedItem.Category.Total, Converter={NumUnitConverter FractionDigits=0}}" />
                                </FZTextBlock>
                                <Control Height="25"
                                         VerticalAlignment="Center"
                                         Style="{Binding CampaignId, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource H_Converter_CampaignToCurrencyControlStyle}}" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                    <ContentPresenter DockPanel.Dock="Left"
                                      Width="398"
                                      Height="300"
                                      x:Name="item"
                                      Content="{Binding SelectedItem.Item}"
                                      ContentTemplate="{StaticResource H_Template_CollectionCampaignItem}" />
                    <DockPanel VerticalAlignment="Center"
                                MaxHeight="347"
                                Margin="62,20,0,20"
                                local:MultiStringFormatter.Format="{local:Loc Campaign.IDS_ScreenReader_Format_ItemDetails}"
                                local:MultiStringFormatter.Param0="{Binding Description}"
                                local:MultiStringFormatter.Param1="{Binding HowToFind}"
                                local:MultiStringFormatter.Param2="{Binding FunFact}"
                                local:ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                local:ScreenReader.LineType="ItemDescription"
                                local:ScreenReader.Event="OnChange">
                        <Decorator DockPanel.Dock="Top" MinHeight="56" Margin="0,0,0,10" Visibility="{Binding Description, Converter={StringVisConverter}}">
                            <Grid VerticalAlignment="Center">
                                <ContentPresenter ContentTemplate="{StaticResource H_Template_Info_Icon}"
                                    Content="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Info_Info_Icon.png" />
                                
                                <FZTextBlock Style="{StaticResource H_Style_InfoText}"
                                             Text="{Binding Description}" />
                            </Grid>
                        </Decorator>
                        <Decorator DockPanel.Dock="Top" MinHeight="56" Margin="0,10,0,10" Visibility="{Binding HowToFind, Converter={StringVisConverter}}">
                            <Grid VerticalAlignment="Center">
                                <ContentPresenter ContentTemplate="{StaticResource H_Template_Info_Icon}"
                                    Content="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Info_Lock_Icon.png" />
                                
                                <FZTextBlock Style="{StaticResource H_Style_InfoText}"
                                             Text="{Binding HowToFind}" />
                            </Grid>
                        </Decorator>
                        <Decorator MinHeight="56" Margin="0,10,0,0" Visibility="{Binding FunFact, Converter={StringVisConverter}}">
                            <Grid VerticalAlignment="Center">
                                <ContentPresenter ContentTemplate="{StaticResource H_Template_Info_Icon}"
                                    Content="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Info_Fact_Icon.png" />
                                
                                <FZTextBlock Style="{StaticResource H_Style_InfoText}"
                                             Text="{Binding FunFact}" 
                                             Stretch="None"
                                             AutoScroll="{StaticResource A_AutoScrollSettings_CollectionInfo}"/>
                            </Grid>
                        </Decorator>
                    </DockPanel>
                </DockPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
