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

    <Page.Resources>
        <ResourceDictionary>

            <!-- BucketList info Style -->
            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_ItemTile_Bucketlist" 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>
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Style.Triggers>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding SetupItem.ShowAdditionalInfo, 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>

                    <Decorator x:Name="ScaledContainer"
                          Width="{StaticResource A_Double_BucketList_TileItem_Width}"
                          Height="{StaticResource A_Double_BucketList_TileItem_Height}"
                          RenderTransformOrigin="0.5,0.5">
                        <Decorator.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="1" ScaleY="1" />
                                <TranslateTransform />
                            </TransformGroup>
                        </Decorator.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 Name="Flyer" Style="{StaticResource A_Style_Control_CampaignFlyer_Internal_BorderedWithSelectionHighlight}"
                                         Template="{StaticResource A_ControlTemplate_Control_BucketListFlyer_Internal}"
                                         DataContext="{Binding SetupItem}" />
                                <local:FZMaterial Color="#00000000"
                                                  x:Name="HitTestHelper"
                                                  local:RoutedEventCommand.Action="{Binding ElementName=ClickOnMouseItem}"/>
                            </Grid>
                        </Grid>
                    </Decorator>
                    <Decorator Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}">
                        <Decorator.RenderTransform>
                            <TranslateTransform X="388"/>
                        </Decorator.RenderTransform>
                        <Grid Visibility="{Binding SetupItem.ShowAdditionalInfo, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}, FallbackValue=Hidden}">
                            <Control Style="{StaticResource A_Style_Event_BucketListInfo_FlyerPopup}"
                                     DataContext="{Binding SetupItem}"/>
                        </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>

                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding SetupItem.IsFlyerFlipped}" Value="True" />
                            <Condition Binding="{Binding SetupItem.AllowFlipAnimation}" Value="True" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                             Storyboard="{StaticResource A_Storyboard_ShowFrontOfFlyer_Bucketlist}" />
                        </MultiDataTrigger.EnterActions>
                    </MultiDataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding SetupItem.IsFlyerFlipped}" Value="False" />
                            <Condition Binding="{Binding SetupItem.AllowFlipAnimation}" Value="True" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                             Storyboard="{StaticResource A_Storyboard_ShowBackOfFlyer_Bucketlist}" />
                        </MultiDataTrigger.EnterActions>
                    </MultiDataTrigger>

                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding SetupItem.IsFlyerFlipped}" Value="True" />
                            <Condition Binding="{Binding SetupItem.AllowFlipAnimation}" Value="False" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                             Storyboard="{StaticResource A_Storyboard_ShowFrontOfFlyer_Bucketlist_Instant}" />
                        </MultiDataTrigger.EnterActions>
                    </MultiDataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding SetupItem.IsFlyerFlipped}" Value="False" />
                            <Condition Binding="{Binding SetupItem.AllowFlipAnimation}" Value="False" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                             Storyboard="{StaticResource A_Storyboard_ShowBackOfFlyer_Bucketlist_Instant}" />
                        </MultiDataTrigger.EnterActions>
                    </MultiDataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style x:Key="A_Style_ListBoxItem_BucketlistItemTile" TargetType="ListBoxItem">
                <Setter Property="Focusable" Value="True" />
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_ItemTile_Bucketlist}" />
                <Setter Property="local:ZPanel.DisableClipping" Value="True" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelectable}" Value="False" >
                        <Setter Property="Focusable" Value="False" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </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}" />

        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Select}"
                                               Visibility="{Binding SelectedItem, FallbackValue=Collapsed, ElementName=PART_ListBox_Challenges, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                <local:ControllerButtonControl Button="B"
                                               Description="{local:Loc HelpButtons.IDS_Back}"/>
                <local:ControllerButtonControl Button="Y"
                                               Description="{local:Loc HelpButtons.IDS_BucketListBlueprintOptions}"
                                               Visibility="{Binding CanViewChallengeOptions, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                <local:ControllerButtonControl Button="RBumper"
                                               Description="{local:Loc HelpButtons.IDS_HighStakeBurn}"
                                               Visibility="{Binding ShowBurnButton, FallbackValue=Collapsed, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                <local:ControllerButtonControl Button="Start"
                                               Description="{local:Loc HelpButtons.IDS_Abandon_Super7 }"
                                               Visibility="{Binding IsSuper7ModeActive, FallbackValue=Collapsed, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
            </local:ControllerButtonPanel>
        </ContentControl>
        <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_BucketListSetup}" />

        <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 x:Name="ContentControl_SceneTitle"
                                        Content="{local:Loc ScreenTitles.IDS_CommunityChallenges}"
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                        HorizontalAlignment="Left"/>
                        <FZButtonsSelector
                                x:Name="CategoryList"
                                ItemsSource="{Binding Categories}"
                                SelectedItem="{Binding SelectedCategory}"
                                HorizontalAlignment="Left"
                                Margin="0,0,0,8"
                                WrapSelection="True"
                                Style="{StaticResource H_Style_TabBar_Scrolling}"
                                PageSize="1"
                                Visibility="{Binding Categories.Count, Converter={StaticResource A_Converter_Categories_CountToVisibility}, FallbackValue=Collapsed}"
                                local:AttachedRoutedEventCommand.RoutedEvent="Selector.SelectionChanged"
                                local:AttachedRoutedEventCommand.Command="{Binding CategorySelectionChangedCommand}" />
                        <Grid>
                            <local:WrapListBox x:Name="PART_ListBox_Challenges"
                                               Style="{StaticResource A_Style_Carousel_CampaignEventFlyer}"
                                               ItemsSource="{Binding SelectedCategory.Challenges}"
                                               SelectedItem="{Binding SelectedCategory.SelectedItem}"
                                               ItemContainerStyle="{StaticResource A_Style_ListBoxItem_BucketlistItemTile}"
                                               PageSize="1"
                                               IsEnabled="True"
                                               local:AttachedRoutedEventCommand.RoutedEvent="Selector.SelectionChanged"
                                               local:AttachedRoutedEventCommand.Command="{Binding ItemSelectionChangedCommand}"
                                               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 HorizontalAlignment="Center"
                                       Tag="{Binding SelectedCategory.Challenges.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 SelectedCategory.IsLoading}" 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 BucketListBlueprint.IDS_UGC_NoChallengesFound}"
                                                 VerticalAlignment="Center"
                                                 TextWrapping="Wrap"/>
                            </Decorator>
                            <ProgressBar x:Name="IdleIndicator"
                                                 IsIndeterminate="True"
                                                 Style="{StaticResource A_Style_ProgressBar_WaitSpinner}"
                                                 Height="56"
                                                 Visibility="{Binding SelectedCategory.IsLoading, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
                        </Grid>
                    </StackPanel>
                </Grid>
            </Grid>
        </Border>

        <devonly:FZTextBlock x:Name="DebugOnly"
                     CapHeight="30"
                     VerticalAlignment="Bottom"
                     Text="{Binding DebugChallengeDetails, RelativeSource={RelativeSource AncestorType=Page}}"
                     Visibility="{Binding DebugChallengeDetails, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}" />
    </Grid>
</Page>
