<Page xmlns:local="clr-namespace:ForzaUI"
      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:System="clr-namespace:System;assembly=mscorlib"
      xmlns:devonly="http://schemas.playground-games.com/xaml/devonly"
      devonly:DevOnly="devonly"
      x:Class="ForzaUI.A_CampaignBlueprintSelect"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Margin="0">
    
    <Page.Resources>
        <ResourceDictionary>

            <!-- Event Setup ControlTemplate and Style -->
            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_ItemTile" TargetType="ContentControl">
                <ControlTemplate.Resources>
                    <Storyboard x:Key="SelectItemStory">
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0"
                                                      Value="0" />
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="0.6" />
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0"
                                                      Value="0.75" />
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0"
                                                      Value="0.75" />
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                        <Int32AnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.ZIndex)"
                                                      Storyboard.Target="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}}">
                            <EasingInt32KeyFrame KeyTime="0:0:0.3"
                                                     Value="20" />
                        </Int32AnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="DeselectItemStory">
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="0.75" />
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                                                           Storyboard.TargetName="DropShadow">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3"
                                                      Value="0.75" />
                        </DoubleAnimationUsingKeyFrames>
                        <Int32AnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.ZIndex)"
                                                          Storyboard.Target="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}}">
                            <EasingInt32KeyFrame KeyTime="0:0:0.3"
                                                     Value="0" />
                        </Int32AnimationUsingKeyFrames>
                    </Storyboard>
                </ControlTemplate.Resources>
                <Grid UseLayoutRounding="True">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Style.Triggers>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding EventInfoDataView.Show, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_True}"/>
                                        <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="{StaticResource A_Boolean_False}"/>
                                    </MultiDataTrigger.Conditions>
                                    <Setter Property="Opacity" Value="0.4"/>
                                </MultiDataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>

                    <Decorator RenderTransformOrigin="0.5,0.5">
                        <Decorator.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="{Binding Tag, ElementName=Flyer, Converter={StaticResource A_LinearTransformConverter_FlyerFlippingShadow}}" />
                            </TransformGroup>
                        </Decorator.RenderTransform>
                        <local:FZMaterial x:Name="DropShadow"
                                      Style="{StaticResource A_Style_FZMaterial_ShadowBase_ForSubgraph}"
                                      Margin="-24"
                                      RenderTransformOrigin="0.5,0.5"
                                      IsHitTestVisible="False">
                            <local:FZMaterial.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="0.75" ScaleY="0.75" />
                                    <TranslateTransform />
                                </TransformGroup>
                            </local:FZMaterial.RenderTransform>
                        </local:FZMaterial>
                    </Decorator>

                    <Grid x:Name="ScaledContainer"
                          Width="{StaticResource A_Double_CampaignEventFlyer_Carousel_Tile_Width}"
                          Height="{StaticResource A_Double_CampaignEventFlyer_Carousel_Tile_Height}"
                          RenderTransformOrigin="0.5,0.5">
                        <Grid.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="1" ScaleY="1" />
                                <TranslateTransform />
                            </TransformGroup>
                        </Grid.RenderTransform>
                        <Grid Width="442"
                              Height="708"
                              HorizontalAlignment="Center" VerticalAlignment="Center">
                            <StrokeHighlightControl
                                x:Name="FocusHighlight"
                                Style="{StaticResource H_Style_StrokeHighlight_Animated}"
                                IsEnabled="{Binding (Selector.IsSelected), FallbackValue=False, RelativeSource={RelativeSource TemplatedParent}}" />
                            <Grid>
                                <local:AudioEvent x:Name="Audio" />
                                <local:RoutedEventCommand x:Name="ClickOnMouseItem"
                                                          RoutedEvent="UIElement.MouseLeftButtonDown"/>
                                <Control x:Name="Flyer" Style="{StaticResource A_Style_Control_CampaignFlyer_Internal_BorderedWithSelectionHighlight}" />
                                <local:FZMaterial Color="#00000000"
                                                  x:Name="HitTestHelper"
                                                  local:RoutedEventCommand.Action="{Binding ElementName=ClickOnMouseItem}"/>
                            </Grid>
                        </Grid>
                    </Grid>
                    <Decorator Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}">
                        <Decorator.RenderTransform>
                            <TranslateTransform X="388"/>
                        </Decorator.RenderTransform>
                        <Grid Visibility="{Binding EventInfoDataView.Show, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}, FallbackValue=Hidden}">
                            <Control Style="{StaticResource A_Style_Event_RaceInfo_FlyerPopup}"
                                     DataContext="{Binding EventInfoDataView, RelativeSource={RelativeSource AncestorType=Page}}"/>
                        </Grid>
                    </Decorator>
                </Grid>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding (Selector.IsSelected), RelativeSource={RelativeSource Self}}"
                                     Value="True">
                        <Setter TargetName="ClickOnMouseItem" Property="Command" Value="{Binding SelectCommand, RelativeSource={RelativeSource AncestorType=Page}}"/>
                        <DataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                                         Storyboard="{StaticResource SelectItemStory}" />
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                                         Storyboard="{StaticResource DeselectItemStory}" />
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsFlyerFlipped}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                                         Storyboard="{StaticResource A_Storyboard_ShowBackOfFlyer}" />
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                                         Storyboard="{StaticResource A_Storyboard_ShowFrontOfFlyer}" />
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style x:Key="A_Style_ListBoxItem_ItemTile" TargetType="ListBoxItem">
                <!--Setter Property="Height" Value="716" />
                <Setter Property="Width" Value="494" /-->
                <Setter Property="Focusable" Value="True" />
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_ItemTile}" />
                <Setter Property="local:ZPanel.DisableClipping" Value="True" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelectable}" Value="False" >
                        <Setter Property="Focusable" Value="False" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="FZMaterial"
                   x:Key="H_Style_ScrollPageArrow_Pages"
                   BasedOn="{StaticResource H_Style_ScrollPageArrow}">
                <Setter Property="Visibility" Value="Visible" />
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding IsPC, Source={StaticResource PART_UISceneContext}}" Value="False" />
                            <Condition Binding="{Binding IsEnabled}" Value="True" />
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="H_Style_PageTabButton_Previous"
                   TargetType="{Type FZButton}"
                   BasedOn="{StaticResource H_Style_TabButton_SharedNextOrPrevious}">
                <Setter Property="IsEnabled" Value="{Binding CanSelectPrevPage}" />
                <Setter Property="Command" Value="{Binding PrevPageCommand}" />
                <Setter Property="DynamicData.Data">
                    <Setter.Value>
                        <DynamicDataSource>
                            <DynamicDataItem Name="MouseRolloverCornerRadius"
                                             DataType="CornerRadius"
                                             Value="1,0,0,1" />
                            <DynamicDataItem Name="TabArrowPath"
                                             DataType="String"
                                             Value="/ForzaUI;component/Textures/Anthem/Icons/scroll_page_arrow_left_small.png" />
                            <DynamicDataItem Name="ArrowStyle"
                                             DataType="Style"
                                             Value="{StaticResource H_Style_ScrollPageArrow_Pages}" />
                        </DynamicDataSource>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsLoading, RelativeSource={RelativeSource AncestorType=Page}}" Value="True" >
                        <Setter Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="H_Style_PageTabButton_Next"
                   TargetType="{Type FZButton}"
                   BasedOn="{StaticResource H_Style_TabButton_SharedNextOrPrevious}">
                <Setter Property="IsEnabled" Value="{Binding CanSelectNextPage}" />
                <Setter Property="Command" Value="{Binding NextPageCommand}" />
                <Setter Property="DynamicData.Data">
                    <Setter.Value>
                        <DynamicDataSource>
                            <DynamicDataItem Name="MouseRolloverCornerRadius"
                                             DataType="CornerRadius"
                                             Value="1,0,0,1" />
                            <DynamicDataItem Name="TabArrowPath"
                                             DataType="String"
                                             Value="/ForzaUI;component/Textures/Anthem/Icons/scroll_page_arrow_right_small.png" />
                            <DynamicDataItem Name="ArrowStyle"
                                             DataType="Style"
                                             Value="{StaticResource H_Style_ScrollPageArrow_Pages}" />
                        </DynamicDataSource>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsLoading}" Value="True" >
                        <Setter Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FrameworkElement_PagesTabBar" TargetType="FrameworkElement">
                <Setter Property="Visibility" Value="Collapsed" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SelectedCategory.SelectedPageIndex, Converter={StaticResource A_CompareConverter}, ConverterParameter=0}" Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding CanSelectNextPage}" Value="True">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding CanSelectPrevPage}" Value="True">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <local:MappingConverter x:Key="A_Converter_EventInfo_Toggle_Bool_To_String">
                <local:MappingConverterEntry Key="False" Value="{local:Loc HelpButtons.IDS_ViewEventInformation}"/>
                <local:MappingConverterEntry Key="True" Value="{local:Loc HelpButtons.IDS_HideEventInformation}"/>
            </local:MappingConverter>
        </ResourceDictionary>
    </Page.Resources>

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

    <Grid>
        <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />
        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />


        <PageInputHandler
            Button="RTrigger" 
            x:Name="get_share_code_input">
            <PageInputHandler.Style>
                <Style TargetType="PageInputHandler">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding EventInfoDataView.Show}" Value="True">
                            <Setter Property="Command" Value="{Binding EventInfoDataView.GetShareCodeCommand}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </PageInputHandler.Style>
        </PageInputHandler>
        <local:PageInputHandler x:Name="MoreInfoButtonInput" Button="R3"
                                Command="{Binding ToggleEventInfoCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                        Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="B"
                                            Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="{Binding Button, ElementName=MoreInfoButtonInput}"
                                            Description="{Binding EventInfoDataView.Show, Converter={StaticResource A_Converter_EventInfo_Toggle_Bool_To_String}}"
                                            Visibility="{Binding Command.Enabled, Converter={StaticResource A_FZBooleanToVisibilityConverter}, ElementName=MoreInfoButtonInput, FallbackValue=Collapsed}" />
            </local:ControllerButtonPanel>
        </ContentControl>
        <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_EventSetup}" />

        <Border x:Name="PART_LayoutRoot"
                Style="{StaticResource A_Style_Border_ScenePadding}">
            <Grid Style="{StaticResource A_Style_FrameworkElement_ScreenTilt}"
                  Margin="0,20,0,0">
                <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Center">
                        <ContentControl Content="{Binding Title}" 
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                        HorizontalAlignment="Left"/>
                        <FZButtonsSelector
                            x:Name="CategoryList"
                            ItemsSource="{Binding Categories}"
                            SelectedItem="{Binding SelectedCategory}"
                            HorizontalAlignment="Left"
                            WrapSelection="True"
                            Style="{StaticResource H_Style_TabBar_Scrolling}"
                            local:AttachedRoutedEventCommand.RoutedEvent="Selector.SelectionChanged"
                            local:AttachedRoutedEventCommand.Command="{Binding CategorySelectionChangedCommand}">
                            <FZButtonsSelector.ItemContainerStyle>
                                <Style
                                    TargetType="FZButton"
                                    BasedOn="{StaticResource H_Style_TabButton_Scrolling}">
                                    <Setter
                                        Property="Content"
                                        Value="{Binding Text, Converter={StringToUpper}}" />
                                </Style>
                            </FZButtonsSelector.ItemContainerStyle>
                        </FZButtonsSelector>
                        <Grid>
                            <local:WrapListBox x:Name="PART_ItemListBox"
                                               Style="{StaticResource A_Style_Carousel_CampaignEventFlyer}"
                                               ItemsSource="{Binding SelectedCategory.CampaignSetups}"
                                               SelectedItem="{Binding SelectedCategory.SelectedItem}"
                                               ItemContainerStyle="{StaticResource A_Style_ListBoxItem_ItemTile}"
                                               ItemTemplateSelector="{StaticResource A_EventBlueprintFlyerTemplateSelector}"
                                               PageSize="1"
                                               IsEnabled="{Binding SelectorIsEnabled}"
                                               WrapSelection="False"
                                               local:AttachedRoutedEventCommand.RoutedEvent="Selector.SelectionChanged"
                                               local:AttachedRoutedEventCommand.Command="{Binding CampaignSetupSelectionChangedCommand}"
                                               local:FocusOnPageFocusGained.SelectorSelectedItem="True">
                                <local:WrapListBox.EmptyItemStyle>
                                    <Style TargetType="Control" >
                                        <Setter Property="Focusable" Value="False"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate>
                                                    <local:FZMaterial Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"
                                                        Margin="2,0.5,2,0"/>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </local:WrapListBox.EmptyItemStyle>
                            </local:WrapListBox>
                            <Decorator Width="400"
                                       Height="400"
                                       HorizontalAlignment="Center"
                                       Tag="{Binding SelectedCategory.CampaignSetups.Count}">
                              <Decorator.Style>
                                <Style TargetType="FrameworkElement">
                                  <Setter Property="Visibility" Value="Collapsed" />
                                  <Style.Triggers>
                                    <MultiDataTrigger>
                                      <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding Tag, RelativeSource={RelativeSource Self}}">
                                          <Condition.Value>
                                            <System:Int32>0</System:Int32>
                                          </Condition.Value>
                                        </Condition>
                                        <Condition Binding="{Binding IsLoading, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}" Value="False"/>
                                      </MultiDataTrigger.Conditions>
                                      <Setter Property="Visibility" Value="Visible"/>
                                    </MultiDataTrigger>
                                  </Style.Triggers>
                                </Style>
                              </Decorator.Style>
                              <local:FZTextBlock Color="{StaticResource A_Color_SubHeader_Text}"
                                                 HorizontalAlignment="Center"
                                                 TextAlignment="Center"
                                                 Style="{StaticResource A_Style_FZTextBlock_Heading_Tight}"
                                                 Text="{local:Loc EventBlueprint.IDS_UGC_NoEventsFound}"
                                                 VerticalAlignment="Center"
                                                 TextWrapping="Wrap"/>
                            </Decorator>
                            <ProgressBar x:Name="IdleIndicator"
                                         IsIndeterminate="True"
                                         Style="{StaticResource A_Style_ProgressBar_WaitSpinner}"
                                         Height="56"
                                         Visibility="{Binding IsLoading, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                        </Grid>
                        <DockPanel Width="400"
                                   Margin="0,11,0,0"
                                   Style="{StaticResource A_Style_FrameworkElement_PagesTabBar}">
                            <FZButton DockPanel.Dock="Left"
                                      Margin="0,0,5,0"
                                      Style="{StaticResource H_Style_PageTabButton_Previous}" />
                            <FZButton DockPanel.Dock="Right"
                                      Margin="5,0,0,0"
                                      Style="{StaticResource H_Style_PageTabButton_Next}" />
                            <Grid>
                                <local:FZMaterial Preset="{StaticResource H_GlassRoundtangle_3px}"
                                                  Color="{StaticResource H_Color_Glass_Purple_20pc}"/>
                                <local:FZTextBlock Text="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}" 
                                                   local:MultiStringFormatter.Param0="{Binding SelectedCategory.SelectedPageIndex, Converter={StaticResource H_IndexToNumberConverter}}"
                                                   local:MultiStringFormatter.Format="{local:Loc EventBlueprint.IDS_PageTitle}"
                                                   Color="{StaticResource H_Color_Primary_White}"
                                                   CapHeight="{StaticResource H_CapHeight_TabBar}"
                                                   Margin="24,6"
                                                   Stretch="Uniform"
                                                   FontFamily="Horizon_A"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"/>
                            </Grid>
                        </DockPanel>
                    </StackPanel>
                </Grid>
                <devonly:FZTextBlock x:Name="DebugOnly"
                                   Text="{Binding SelectedItemId}"
                                   CapHeight="20"
                                   HorizontalAlignment="Right"
                                   VerticalAlignment="Bottom"
                                   Margin="5"
                                   Visibility="{Binding SelectedItemId, Converter={StaticResource A_StringVisConverter}}" />
            </Grid>
        </Border>
    </Grid>
</Page>
