<Page x:Class="ForzaUI.Scenes.Anthem.A_LabyrinthSelectMenu"
      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"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      mc:Ignorable="d"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

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

    <Page.Resources>
        <System:Double x:Key="A_Double_LabyrinthSelectMenu_Tile_Width">425</System:Double>
        <System:Double x:Key="A_Double_LabyrinthSelectMenu_Tile_Width_withSpacing">431</System:Double>

        <Style x:Key="A_Style_FZRun_Title_YELLOW" TargetType="local:FZRun">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Yellow}" />
        </Style>

        <System:String x:Key="A_String_BackgroundPath_FormatString">/ForzaUI;component/Textures/Data_Bound/Labyrinth/SelectMenu/{0}.png</System:String>

        <Style x:Key="A_Style_FZMaterial_TileBackground_Labyrinth" TargetType="local:FZMaterial"
             BasedOn="{StaticResource A_Style_FZMaterial_TileBackground}">
            <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding UITheme}" />
            <Style.Triggers>
                  <DataTrigger Binding="{Binding UITheme}" Value="">
                        <Setter Property="local:MultiStringFormatter.Param0" Value="default" />
                  </DataTrigger>
                  <DataTrigger LogicalOp="NotEquals" Binding="{Binding OnSelectCommand.DeniedCommand}" Value="{x:Null}">
                        <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_Desaturated}"/>
                  </DataTrigger>
            </Style.Triggers>
        </Style>

        <local:MappingConverter x:Key="A_Converter_ItemStateToVisibility_Score" Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:LabyrinthSelectMenuItemState.Loaded}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_Converter_ItemStateToVisibility_Spinner" Default="{x:Static Visibility.Collapsed}">
            <local:MappingConverterEntry Key="{x:Static local:LabyrinthSelectMenuItemState.Loading}" Value="{x:Static Visibility.Visible}" />
        </local:MappingConverter>

        <Double x:Key="A_Double_LabyrinthEventItem_Title_LineAdjust">-0.35</Double>
        <Double x:Key="A_Double_LabyrinthEventItem_Title_LineAdjust_JP">-0.3</Double>
        <Double x:Key="A_Double_LabyrinthEventItem_Title_LineAdjust_EN">-0.65</Double>
        <Double x:Key="A_Double_LabyrinthEventItem_Title_LineAdjust_GB">-0.65</Double>
        
        <DataTemplate DataType="{x:Type local:LabyrinthEventItem}">
            <Grid>
                <local:FZMaterial x:Name="TileImage" Style="{StaticResource A_Style_FZMaterial_TileBackground_Labyrinth}"
                  local:MultiStringFormatter.Format="{StaticResource A_String_BackgroundPath_FormatString}"
                  ImageSource="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                  Height="704"
                  VerticalAlignment="Top">
                    <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding Title, Converter={StaticResource A_StringToUpper}}"
                       local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_Title_"
                       LineAdjust="{local:LocalizedResource A_Double_LabyrinthEventItem_Title_LineAdjust}"
                       CapHeight="46"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Top"
                       TextAlignment="Center"
                       TextWrapping="WrapWithOverflow"
                       Stretch="Uniform"
                       StretchDirection="DownOnly"
                       Color="{StaticResource A_Color_White}"
                       Margin="20,56,20,0"/>
                </local:FZMaterial>
                <StackPanel VerticalAlignment="Bottom">
                    <local:FZMaterial x:Name="YellowBanner" Color="{StaticResource H_Color_Primary_Yellow}" 
                      Height="37">
                        <local:FZTextBlock Text="{Loc Lobby.IDS_Labyrinth_SelectMenu_SkillScore}"
                           CapHeight="17"
                           TextAlignment="Center"
                           VerticalAlignment="Center"
                           Color="{StaticResource H_Color_Primary_Purple}" />
                    </local:FZMaterial>
                    <local:FZMaterial x:Name="PurpleBanner" Color="{StaticResource H_Color_Primary_Purple}"
                                      Height="66"
                                      VerticalAlignment="Bottom">
                        <Grid VerticalAlignment="Center"
                              HorizontalAlignment="Center">
                            <local:FZTextBlock Text="{Binding HighestScore}"
                                               CapHeight="42"
                                               TextAlignment="Center"
                                               VerticalAlignment="Center"
                                               Color="{StaticResource H_Color_Primary_Yellow}"
                                               Visibility="{Binding ItemState, Converter={StaticResource A_Converter_ItemStateToVisibility_Score}}" />
                            <ProgressBar x:Name="Spinner" Style="{StaticResource A_Style_Progressbar_Loading_SmallSpinner}"
                                         Height="50"
                                         Width="50"
                                         Visibility="{Binding ItemState, Converter={StaticResource A_Converter_ItemStateToVisibility_Spinner}}"/>
                        </Grid>
                    </local:FZMaterial>
                </StackPanel>
            </Grid>
            
        </DataTemplate>

        <Style x:Key="A_Style_ListBoxItem_ContainerStyle"
               TargetType="{x:Type ListBoxItem}"
               BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_CampaignEventFlyer}">
            <Style.Resources>
                <Style x:Key="H_Style_TemplatedElement_MouseRollover"
                       BasedOn="{StaticResource H_Style_TemplatedElement_MouseRollover}"
                       TargetType="{Type Control}">
                    <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="SelectorSelectedItem.SelectAncestorOnRoutedEvent"
                            Value="UIElement.MouseLeftButtonUp" />
                </Style>
            </Style.Resources>
        </Style>
    </Page.Resources>

    <Grid>
        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />
        <ContentControl Style="{StaticResource A_Style_ButtonBar}">
                <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Select}" />
                <local:ControllerButtonControl Button="B"
                                               Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="X"
                                               Description="{local:Loc HelpButtons.IDS_ViewLeaderboard}" />                               
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <Grid x:Name="LayoutRoot"
                  KeyboardNavigation.DirectionalNavigation="Contained">
                <Grid Style="{StaticResource A_Style_FrameworkElement_ScreenTilt}" Margin="0,0,0,0">
                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <StackPanel Orientation="Horizontal" Margin="9,0,0,0" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                            <ContentControl Content="{Loc ScreenTitles.IDS_Labyrinth_HorizonWorldRemix}" Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}" />
                        </StackPanel>
                        <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                            <local:WrapListBox x:Name="PART_Collection"  
                                               Style="{StaticResource A_Style_Carousel_CampaignEventFlyer}"
                                               ItemContainerStyle="{StaticResource A_Style_ListBoxItem_ContainerStyle}"
                                               ItemsSource="{Binding LabyrinthItems}"
                                               SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                               ItemWidth="{StaticResource A_Double_LabyrinthSelectMenu_Tile_Width_withSpacing}"
                                               PageSize="1"
                                               local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                               SelectionLimitTop="575"
                                               SelectionLimitBottom="575">
                                <local:WrapListBox.Resources>
                                    <Style x:Key="A_Style_Control_Carousel_EmptyItemStyle_Dynamic"
                                           TargetType="Control" >
                                        <Setter Property="Visibility" Value="Hidden"/>
                                    </Style>
                                </local:WrapListBox.Resources>
                            </local:WrapListBox>
                        </Grid>
                    </StackPanel>
                </Grid>
            </Grid>
        </Border>
    </Grid>
</Page>
