<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="
      x:Class="ForzaUI.A_CollectionRoot"
      x:Name="Page"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}}">
    <Page.Resources>

        <Style x:Key="A_Style_FZMaterial_RaiseFocusItemBackground_Dynamic"
               BasedOn="{StaticResource A_Style_FZMaterial_RaiseFocusItemBackground_Dynamic}"
               TargetType="local:FZMaterial">
            <Setter Property="Panel.ZIndex" Value="10"/>
        </Style>

        <CornerRadius x:Key="A_CornerRadius_Dynamic_CarouselTile">8</CornerRadius>

        <Style x:Key="H_Style_RootMilestonePip"
            TargetType="Control"
            BasedOn="{StaticResource H_Style_MilestonePip}">
            <Setter Property="RenderTransform" Value="{ScaleTransform ScaleX=0.91, ScaleY=0.91}" />
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
        </Style>

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

        <AutoScrollSettings x:Key="A_AutoScrollSettings_WristbandSubtitle"
            Speed="40"
            ScrollOrientation="Horizontal"
            InitialPause="0:0:0.75"
            ScrollSeparation="50"/>

        <ControlTemplate x:Key="H_Template_Blocked_Button">
            <Grid>
                <FZMaterialGlassCapture/>
                <DockPanel Height="50" HorizontalAlignment="Center">
                    <ControllerButtonControl HideBackground="True" Visibility="Visible" Button="Back" DockPanel.Dock="Left"
                        Command="{Binding MapCommand, RelativeSource={RelativeSource AncestorType=Page}}"/>
                    <Decorator Width="10" DockPanel.Dock="Left" />
                    <FZTextBlock TextAlignment="Center"
                                 VerticalAlignment="Center"
                                 CapHeight="20"
                                 Color="{StaticResource H_Color_Primary_White}"
                                 FontFamily="Horizon_B"
                                 Text="{Loc Campaign.IDS_Journal_ViewMilestone_Prompt}" />
                </DockPanel>
            </Grid>
        </ControlTemplate>

        <DataTemplate x:Key="H_Template_CollectionCampaignItem">
            <FZMaterial x:Name="material_root" Color="#0000" Margin="-1">
            <Grid Margin="1">
            <Grid
                local:ManualPassthroughProperty.Input="{Binding Id, Converter={StaticResource H_Converter_CampaignToScreenReadableName}}"
                local:ManualPassthroughProperty.Allowed="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                local:ScreenReader.LineType="SelectedItem"
                local:ScreenReader.Event="OnChange"
                local:ScreenReader.ControlType="Button"
                local:ScreenReader.SelectedNumber="{Binding (VirtualizingWrapPanel.ItemIndex), FallbackValue=0, RelativeSource={RelativeSource AncestorType={Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}}"
                local:ScreenReader.SelectedCount="{Binding Items.Count, FallbackValue=0, RelativeSource={RelativeSource AncestorType={Type Selector}}}">
                    <Grid
                    local:ManualPassthroughProperty.Input="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                    local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                    local:ScreenReader.LineType="ItemDescription"
                    local:ScreenReader.Event="OnChange">
                    <Grid.Style>
                        <Style TargetType="{x:Type Grid}">
                            <Setter Property="local:ManualPassthroughProperty.Allowed" Value="{StaticResource A_Boolean_False}"/>
                            <Style.Triggers>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="{StaticResource A_Boolean_True}"/>
                                        <Condition Binding="{Binding Visibility, RelativeSource={RelativeSource Self}}" Value="{x:Static Visibility.Visible}"/>
                                    </MultiDataTrigger.Conditions>
                                    <Setter Property="local:ManualPassthroughProperty.Allowed" Value="{StaticResource A_Boolean_True}"/>
                                </MultiDataTrigger>
                                <DataTrigger Binding="{Binding SelectedMilestone.Blocked}" Value="True">
                                    <Setter Property="local:MultiStringFormatter.Format" Value="{local:Loc Campaign.IDS_MilestoneReached}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding SelectedMilestone.Blocked}" Value="False">
                                    <Setter Property="local:MultiStringFormatter.Format" Value="{Binding Id, Converter={StaticResource H_Converter_CampaignToScreenReadableProgressToMilestoneFormat}}"/>
                                    <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding SelectedMilestone.Progress}"/>
                                    <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding SelectedMilestone.Total}"/>
                                </DataTrigger>
                                </Style.Triggers>
                        </Style>
                    </Grid.Style>
                    <FZMaterial GetSizeFromTexture="True" Stretch="UniformToFill" VerticalAlignment="Bottom" ImageSource="{Binding Id, Converter={StaticResource H_Converter_CampaignToJournalTitleBlock}}"
                                    x:Name="image" />

                    <!--this thing isn't quite the same dimensions as the one in the categories screen but the structure of it is the same :(-->
                    <ProgressBar DataContext="{Binding SelectedMilestone}" Template="{StaticResource H_Template_Milestone}" Maximum="{Binding Total, Converter={LinearTransformConverter}}" Value="{Binding Progress, Converter={LinearTransformConverter}}"
                        Margin="25,0,25,160" VerticalAlignment="Bottom">
                        <DynamicData.Data>
                            <DynamicDataSource>
                                <DynamicDataItem Name="Thickness" Value="36" DataType="Double" />
                                <DynamicDataItem Name="CapHeight" Value="18" DataType="Double" />
                            </DynamicDataSource>
                        </DynamicData.Data>
                    </ProgressBar>
                </Grid>

                <StackPanel VerticalAlignment="Bottom"
                    local:MultiStringFormatter.Format="{local:Loc Campaign.IDS_ScreenReader_Format_Banner}"
                    local:MultiStringFormatter.Param0="{Binding Text, ElementName=wristband_name}"
                    local:MultiStringFormatter.Param1="{Binding Text, ElementName=wristband_subtitle}"
                    local:MultiStringFormatter.Param2="{Binding Progress}"
                    local:MultiStringFormatter.Param3="{Binding Total}"
                    local:ManualPassthroughProperty.Allowed="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                    local:ManualPassthroughProperty.Input="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                    local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                    local:ScreenReader.LineType="ItemState"
                    local:ScreenReader.Event="OnChange">
                    <Grid Margin="28,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="41" />
                            <RowDefinition Height="37" />
                            <RowDefinition Height="18" />
                            <RowDefinition Height="18" />
                            <RowDefinition Height="32" />
                        </Grid.RowDefinitions>
                        <DockPanel
                            Grid.Row="1">
                            <FZTextBlock Color="{Binding Id, Converter={StaticResource H_Converter_CampaignToBodyColour}}"
                                Grid.Row="1"
                                CapHeight="32"
                                DockPanel.Dock="Right"
                                FontFamily="Horizon_C">
                                <FZRun Text="{Binding Progress}"/>
                                <FZRun Text="/"/>
                                <FZRun Text="{Binding Total}"/>
                            </FZTextBlock>
                            <FZTextBlock x:Name="wristband_name" Color="{Binding Id, Converter={StaticResource H_Converter_CampaignToBodyColour}}"
                                CapHeight="32"
                                FontFamily="Horizon_C"
                                VerticalAlignment="Center"
                                Text="{Binding SelectedMilestone.Id, Converter={StaticResource H_Converter_ObjectiveToName}}" />
                        </DockPanel>
                        <!-- autoscrolling so that long wristband access strings with large fonts don't have to be crushed. usually this will not scroll except at 150% size (125% in english is zero scroll) -->
                        <FZTextBlock x:Name="wristband_subtitle" Color="{Binding Id, Converter={StaticResource H_Converter_CampaignToBodyColour}}"
                            Grid.Row="3"
                            CapHeight="14"
                            FontFamily="Horizon_C"
                            TrackingAdjust="0.3"
                            Text="{Binding SelectedMilestone.Id, Converter={StaticResource H_Converter_ObjectiveToUpperSubtitle}}" 
                            AutoScroll="{StaticResource A_AutoScrollSettings_WristbandSubtitle}"
                            AutoScroll.AllowScrolling="True" />
                    </Grid>
                </StackPanel>

                <Viewbox 
                    Margin="20,14"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Height="48"
                    Width="48">
                    <ContentControl x:Name="Breadcrumb"
                        Style="{StaticResource H_Style_NotificationBadge_NarrationPassthrough}"
                        Visibility="{Binding TotalPendingRewards, Converter={CompareConverter Value=0, GreaterThan=Visible, LessThanOrEqual=Collapsed}}"
                        Content="{Binding TotalPendingRewards}"
                        local:MultiStringFormatter.Format="{local:Loc Campaign.IDS_ScreenReader_CampaignCollection_UnclaimedRewardsBreadcrumb}"
                        local:MultiStringFormatter.Param0="{Binding TotalPendingRewards}"
                        local:ManualPassthroughProperty.Input="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                        local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                        local:ScreenReader.LineType="SelectedDetails"
                        local:ScreenReader.Event="OnChange" />
                </Viewbox>
            </Grid>

            <Grid x:Name="blocked_info"
                  Visibility="Collapsed"
                   Margin="37,144,37,240">
                <DockPanel>

                    <Control x:Name="blocked_button" 
                        DockPanel.Dock="Bottom"
                        Margin="0,25,0,10"
                        Template="{StaticResource H_Template_Blocked_Button}"
                        Visibility="{Binding IsInPlayerHouse, FallbackValue=Collapsed, Source={StaticResource PART_UISceneContext}, Converter={FZBooleanToVisibilityConverter InvertResult=True, UseHidden=True}}"/>

                    <DockPanel>
                        <FZMaterial Stretch="Uniform"
                                    DockPanel.Dock="Top"
                                    GetSizeFromTexture="True"
                                    x:Name="blocked_icon" />
                        <FZTextBlock TextAlignment="Center"
                                     FontFamily="Horizon_D"
                                     VerticalAlignment="Center"
                                     TextWrapping="Wrap"
                                     Margin="0,20,0,0"
                                     LineAdjust="-0.5"
                                     CapHeight="16"
                                     Stretch="None"
                                     x:Name="blocked_text"
                                     Color="{StaticResource H_Color_Primary_White}"
                                     MarkupConverter="{StaticResource H_MarkupConverter_BlockedDesc}"
                                     local:ManualPassthroughProperty.Input="{Binding Text, ElementName=blocked_text}"
                                     local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                     local:ScreenReader.LineType="NotificationTitle"
                                     local:ScreenReader.Event="OnChange">
                            <FZTextBlock.Style>
                                <Style TargetType="FZTextBlock">
                                    <Setter Property="local:ManualPassthroughProperty.Allowed" Value="False"/>
                                    <Style.Triggers>
                                        <MultiDataTrigger>
                                            <MultiDataTrigger.Conditions>
                                                <Condition Binding="{Binding IsKeyboardFocusWithin, ElementName=list}" Value="True"/>
                                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="True"/>
                                            </MultiDataTrigger.Conditions>
                                            <Setter Property="local:ManualPassthroughProperty.Allowed" Value="True"/>
                                        </MultiDataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </FZTextBlock.Style>
                        </FZTextBlock>
                    </DockPanel>
                </DockPanel>
            </Grid>
            </Grid>
            </FZMaterial>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Locked}" Value="True">
                    <Setter TargetName="material_root" Property="CaptureSubgraph" Value="True"/>
                    <Setter TargetName="material_root" Property="Color" Value="#ffff"/>
                    <Setter TargetName="material_root" Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_Desaturated}"/>
                    <Setter TargetName="wristband_name" Property="Text" Value="{Loc Campaign.IDS_Accolades_Locked}"/>

                    <Setter TargetName="image" Property="ImageSource" Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\DJ_Journal_Header_Locked.png"/>
                    <Setter TargetName="blocked_icon" Property="ImageSource" Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Journal_Lock.png"/>
                    <Setter TargetName="blocked_icon" Property="Margin" Value="0,45,0,0"/>
                    <Setter TargetName="blocked_info" Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding SelectedMilestone.Index}" Value="-1"/>
                        <Condition Binding="{Binding Id}" Value="{StaticResource H_Id_FestivalCampaign}"/>
                    </MultiDataTrigger.Conditions>
                    <Setter TargetName="image" Property="ImageSource" Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Journal_Progress_Blocked_Image.png"/>
                    <Setter TargetName="blocked_icon" Property="ImageSource" Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\objective_icon.png"/>
                    <Setter TargetName="blocked_icon" Property="Margin" Value="0,70,0,0"/>
                    <Setter TargetName="blocked_text" Property="Text" Value="{Loc Campaign.IDS_Qualifiers_Desc}"/>
                    <Setter TargetName="blocked_info" Property="Visibility" Value="Visible"/>
                </MultiDataTrigger>
                <DataTrigger Binding="{Binding SelectedMilestone.Blocked}" Value="True">
                    <Setter TargetName="image" Property="ImageSource" Value="game:\Media\UI\Textures\Data_Bound\CollectionCampaign\Journal_Progress_Blocked_Image.png"/>
                    <Setter TargetName="blocked_info" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="blocked_icon" Property="ImageSource" Value="{Binding SelectedMilestone.Id, Converter={StaticResource H_MilestoneIdToBlockedIcon}}"/>
                    <Setter TargetName="blocked_icon" Property="Margin" Value="0"/>
                    <Setter TargetName="blocked_text" Property="Text" Value="{Binding SelectedMilestone.Id, Converter={StaticResource H_MilestoneIdToBlockedText}}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding MapCommand, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_TrueIfNotNull}}" Value="False">
                    <Setter TargetName="blocked_button" Property="Visibility" Value="Hidden"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding SelectedMilestone.Blocked}" Value="False">
                    <Setter TargetName="blocked_button" Property="Visibility" Value="Hidden"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <Style x:Key="H_ContainerStyle_CollectionRoot"
            BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_SelectOnMouseHover}"
            TargetType="{x:Type ListBoxItem}">
            <Setter Property="AttachedRoutedEventCommand.Enabled"
                    Value="True" />
            <Setter Property="ZPanel.DisableClipping"
                    Value="True" />
            <Setter Property="Margin"
                    Value="9,0" />

            <Setter Property="MarkAsHandled.RoutedEvent"
                    Value="UIElement.MouseLeftButtonDown" />
            <Setter Property="AttachedRoutedEventCommand.Enabled"
                    Value="{Binding (Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}" />
            <Setter Property="AttachedRoutedEventCommand.Command"
                    Value="{Binding SelectCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
            <Setter Property="AttachedRoutedEventCommand.RoutedEvent"
                    Value="UIElement.MouseLeftButtonUp" />
            <Setter Property="IsEnabled"
                    Value="{Binding Locked, Converter={StaticResource A_Converter_Boolean_Invert}}"/>
            <Setter Property="BindingProxy.A">
                <Setter.Value>
                    <Boolean>False</Boolean>
                </Setter.Value>
            </Setter>
        </Style>

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

        <MappingConverter x:Key="H_Converter_CampaignToJournalHighlight"
                          Default="">
            <MappingConverterEntry Key="{StaticResource H_Id_DiscoverCampaign}"
                                   Value="{StaticResource A_Color_Campaign_Discover_Body}" />
            <MappingConverterEntry Key="{StaticResource H_Id_FestivalCampaign}"
                                   Value="{StaticResource A_Color_Campaign_Festival}" />
        </MappingConverter>


        <Style x:Key="H_Style_MapCommand"
            TargetType="{x:Type PageInputHandler}">
            <Setter Property="Command" Value="{Binding MapCommand}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsInPlayerHouse, FallbackValue=False, Source={StaticResource PART_UISceneContext}}" Value="True">
                    <Setter Property="Command" Value="{x:Null}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </Page.Resources>
    <UIPageTransitionManager.TransitionManager>
        <UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}" />
    </UIPageTransitionManager.TransitionManager>
    <Grid>
        <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <PageInputHandler x:Name="a_button"
                          Button="A"
                          Command="{Binding SelectCommand}" />
        <PageInputHandler x:Name="b_button"
                          Button="B"
                          Command="{Binding BackCommand}" />
        <PageInputHandler x:Name="map_button" 
                          Button="Back"
                          Style="{StaticResource H_Style_MapCommand}"/>
        <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="{Binding Button, ElementName=a_button}"
                                         Description="{Loc HelpButtons.IDS_Select}"
                                         Visibility="{Binding Command.Enabled, FallbackValue=Collapsed, Converter={FZBooleanToVisibilityConverter}, ElementName=a_button}" />
                <ControllerButtonControl Button="{Binding Button, ElementName=b_button}"
                                         Description="{Loc HelpButtons.IDS_Back}"
                                         Visibility="{Binding Command.Enabled, FallbackValue=Collapsed, Converter={FZBooleanToVisibilityConverter}, ElementName=b_button}" />
            </ControllerButtonPanel>
        </ContentControl>
        <Border Style="{StaticResource A_Style_Border_ScenePadding_Opus}">
            <StackPanel VerticalAlignment="Bottom" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" Margin="0,0,0,35">
                <WrapListBox x:Name="list" ItemsSource="{Binding Items}"
                             Width="1154"
                             Height="750"
                             HorizontalAlignment="Center"
                             EnableUnselectableItems="True"
                             Template="{StaticResource A_ControlTemplate_Carousel_Default}"
                             ItemContainerStyle="{StaticResource H_ContainerStyle_CollectionRoot}"
                             EmptyItemStyle="{StaticResource H_Style_TemplatedElement_Empty}"
                             ItemTemplate="{StaticResource H_Template_CollectionCampaignItem}"
                             ItemWidth="577"
                             ItemHeight="750"
                             SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                             FocusOnPageFocusGained.SelectorSelectedItem="True">
                    <WrapListBox.Resources>
                        <CornerRadius x:Key="A_CornerRadius_Dynamic_CarouselTile">6</CornerRadius>
                            <Style x:Key="H_Dynamic_Style_StrokeHighlight_Carousel"
                                   TargetType="{Type StrokeHighlightControl}"
                                   BasedOn="{StaticResource H_Style_StrokeHighlight_Animated_TiledMenu}"/>
                        <Thickness x:Key="H_Dynamic_CarouselInnerClip">36</Thickness>
                        <Thickness x:Key="H_Dynamic_CarouselOuterClip">36</Thickness>
                        <Style
                            x:Key="A_Style_FZMaterial_ShadowBase_Dynamic"
                            TargetType="{Type local:FZMaterial}"
                            BasedOn="{StaticResource A_Style_FZMaterial_ShadowBase}">
                            <Setter
                                Property="Preset">
                                <Setter.Value>
                                    <FZMaterialPresetRoundtangle
                                        Softness="36"
                                        CornerRadius="36" />
                                </Setter.Value>
                            </Setter>
                            <Setter
                                Property="Margin"
                                Value="-36" />
                            <Setter
                                Property="Color"
                                Value="{StaticResource A_Color_UISelfShadow}" />
                        </Style>
        
                    </WrapListBox.Resources>
                </WrapListBox>
            </StackPanel>
        </Border>
    </Grid>
</Page>
