<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"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

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

    <Page.Resources>
        <Double x:Key="A_Double_ListItem_Width">398</Double>
        <Double x:Key="A_Double_ListItem_Height">520</Double>
        <Thickness x:Key="A_Margin_ListItem">4,0</Thickness>

        <ItemsPanelTemplate x:Key="A_ItemsPanel_LabyrinthMode">
            <StackPanel IsItemsHost="True"
                        Orientation="Horizontal"
                        Margin="{Convert {StaticResource A_Margin_ListItem}, Converter={StaticResource H_InvertConverter}}"/>
        </ItemsPanelTemplate>

        <Style x:Key="A_Style_FZMaterial_ShadowBase_Dynamic"
               TargetType="{Type FZMaterial}"
               BasedOn="{StaticResource A_Style_FZMaterial_ShadowBase_Dynamic}">
            <Setter Property="Margin" Value="-10"/>
        </Style>

        <Style x:Key="A_Style_FrameworkElement_CarouselSelectionScale_Dynamic"
               TargetType="FrameworkElement">
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <ScaleTransform />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding (Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                             Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard HandoffBehavior="SnapshotAndReplace">
                            <BeginStoryboard.Storyboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                                Value="1.04" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleY)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                                Value="1.04" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard.Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <BeginStoryboard HandoffBehavior="SnapshotAndReplace">
                            <BeginStoryboard.Storyboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleX)">
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                          Value="1.0"
                                                          EasingFunction="{local:CircleEasing}" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(ScaleTransform.ScaleY)">
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                              Value="1.0"
                                                              EasingFunction="{local:CircleEasing}" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard.Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>

         <Style x:Key="A_Style_ContentControl_LabyrinthMode_ContainerStyle"
                TargetType="ContentControl"
                BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_SelectOnMouseHover}">
            <Style.Resources>
                <CornerRadius x:Key="A_CornerRadius_Dynamic_CarouselTile">3</CornerRadius>
                <Style x:Key="H_Style_TemplatedElement_MouseRollover"
                       BasedOn="{StaticResource A_Style_Control_CarouselItem_MouseRollover_AlwaysSelectWhenClicked}"
                       TargetType="{x:Type Control}">
                    <Setter Property="DynamicData.Data">
                        <Setter.Value>
                            <DynamicDataSource>
                                <DynamicDataItem Name="MouseRolloverCornerRadius"
                                                 DataType="CornerRadius"
                                                 Value="3" />
                                <DynamicDataItem Name="MouseRolloverDisableWhenSelected"
                                                 DataType="Boolean"
                                                 Value="False" />
                            </DynamicDataSource>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="Margin" Value="{StaticResource A_Margin_ListItem}"/>
         </Style>

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

        <Style x:Key="A_Style_FZRun_Title_YELLOW" TargetType="local:FZRun">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Yellow}" />
            <Style.Triggers>
                <DataTrigger LogicalOp="NotEquals" Binding="{Binding OnSelect.DeniedCommand}" Value="{x:Null}">
                    <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <MappingConverter x:Key="A_LabyrinthModeToBackgroundPathConverter">
            <MappingConverterEntry Key="{Static XAMLLabyrinthModeType.Free}" Value="game:\media\UI\Textures\Data_Bound\Labyrinth\ModeSelect\FreeMode.png" />
            <MappingConverterEntry Key="{Static XAMLLabyrinthModeType.Skill}" Value="game:\media\UI\Textures\Data_Bound\Labyrinth\ModeSelect\SkillMode.png" />
        </MappingConverter>

        <MappingConverter x:Key="A_LabyrinthModeToTitleConverter">
            <MappingConverterEntry Key="{Static XAMLLabyrinthModeType.Free}" Value="{Loc Lobby.IDS_Labyrinth_ModeSelect_FreeMode_Title}" />
            <MappingConverterEntry Key="{Static XAMLLabyrinthModeType.Skill}" Value="{Loc Lobby.IDS_Labyrinth_ModeSelect_SkillMode_Title}" />
        </MappingConverter>

        <Style x:Key="A_Style_FZMaterial_LabyrinthMode_Background" TargetType="{Type FZMaterial}">
            <Setter Property="ImageSource" Value="{Binding Mode, Converter={StaticResource A_LabyrinthModeToBackgroundPathConverter}}"/>
            <Style.Triggers>
                <DataTrigger LogicalOp="NotEquals" Binding="{Binding OnSelect.DeniedCommand}" Value="{x:Null}">
                    <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_Desaturated}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <DataTemplate x:Key="A_DataTemplate_LabyrinthModeItem">
            <Grid Width="{StaticResource A_Double_ListItem_Width}"
                  Height="{StaticResource A_Double_ListItem_Height}"
                  Margin="4"
                  IsHitTestVisible="False">
                <FZMaterial Style="{StaticResource A_Style_FZMaterial_LabyrinthMode_Background}"/>
                <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding Mode, Converter={StaticResource A_LabyrinthModeToTitleConverter}}"
                                   local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_Title_"
                                   LineAdjust="-0.65"
                                   CapHeight="46"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Top"
                                   TextAlignment="Center"
                                   Color="{StaticResource A_Color_White}"
                                   Margin="0,56,0,0"/>
            </Grid>
        </DataTemplate>
    </Page.Resources>

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

        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" Focusable="False" />
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}"
                Focusable="False" />
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <DockPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Bottom"
                       Margin="0,0,0,74">
                <ContentControl Content="{Loc ScreenTitles.IDS_Labyrinth_SelectMode}"
                                Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                HorizontalAlignment="Left"
                                DockPanel.Dock="Top"/>
                <FZMaterial x:Name="DescriptionPanel" DataContext="{Binding SelectedItem, ElementName=PART_ItemListBox}"
                            Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"
                            Height="88" Margin="0,12,0,0"
                            Width="{Binding ActualWidth, ElementName=PART_ItemListBox}"
                            DockPanel.Dock="Bottom">
                    <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding Description}"
                                       local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_Description_"
                                       Style="{StaticResource A_Style_FZTextBlock_Description}"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Top"
                                       Margin="24,18"
                                       CapHeight="17"
                                       TextWrapping="Wrap"
                                       Color="{StaticResource A_Color_White}"
                                       local:ScreenReader.Event="OnChange"
                                       local:ScreenReader.ControlType="None"
                                       local:ScreenReader.Line="{Binding DescriptionScreenReader, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                       local:ScreenReader.LineType="ItemDescription"/>
                </FZMaterial>
                <CommonListBox x:Name="PART_ItemListBox"
                               ItemsPanel="{StaticResource A_ItemsPanel_LabyrinthMode}"
                               ItemContainerStyle="{StaticResource A_Style_ContentControl_LabyrinthMode_ContainerStyle}"
                               ItemTemplate="{StaticResource A_DataTemplate_LabyrinthModeItem}"
                               ItemsSource="{Binding Items}"
                               local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                               SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
                    <CommonListBox.Template>
                        <ControlTemplate TargetType="ItemsControl">
                            <ItemsPresenter/>
                        </ControlTemplate>
                    </CommonListBox.Template>
                </CommonListBox>
            </DockPanel>
        </Border>
    </Grid>
</Page>
