<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:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      x:Class="ForzaUI.Scenes.Anthem.UserContentGarageLayout"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

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

    <Page.Resources>
        <ResourceDictionary>

            <DataTemplate x:Key="A_DataTemplate_Carousel_GarageLayoutItem">
                <Grid>
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Style.Triggers>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding IsAPosterInfoOpen, 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>
                    <ContentControl x:Name="PART_Flyer"
                        Visibility="{Binding IsNewItem, Converter={FZBooleanToVisibilityConverter InvertResult=True}, FallbackValue=Visible}"
                        DataContext="{Binding Poster}"
                        Style="{StaticResource A_Style_Control_CampaignFlyer}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        DockPanel.Dock="Left"
                        Margin="0,0,4,0"/>
                    <Grid Visibility="{Binding Poster.Show, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}, FallbackValue=Hidden}">
                        <Grid.RenderTransform>
                            <TranslateTransform X="381.5"/>
                        </Grid.RenderTransform>
                        <Control Style="{StaticResource A_Style_Event_UGCLocation_FlyerPopup}"
                                 DataContext="{Binding Poster}"/>
                    </Grid>
                    <local:FZMaterial x:Name="FavoritedIcon"
                                      Width="23" Height="23"
                                      Color="{StaticResource H_Color_Primary_Pink}"
                                      Visibility="{Binding IsFavorite, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                      ImageSource="/ForzaUI;component/Textures/Data_Bound/CreativeHub/FollowedHeart.png"
                                      HorizontalAlignment="Right"
                                      VerticalAlignment="Bottom"
                                      Margin="8"/>
                </Grid>
            </DataTemplate>
            
            <Style x:Key="A_Style_CarouselText_NoGarageLayoutsFound"
                   TargetType="FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_Heading_Tight}">
                <Setter Property="Visibility" Value="{x:Static Visibility.Collapsed}"/>
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding SelectedCategory.Collection.CountState}" Value="{x:Static local:AsyncItemsCountState.Error}"/>
                            <Condition Binding="{Binding IsDownloading, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}" Value="False"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Visibility" Value="{x:Static Visibility.Visible}"/>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot">
        <PageInputHandler
            Button="RTrigger" 
            x:Name="get_share_code_input">
            <PageInputHandler.Style>
                <Style TargetType="PageInputHandler">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectedGarageLayout.Poster.Show}" Value="True">
                            <Setter Property="Command" Value="{Binding SelectedGarageLayout.Poster.GetShareCodeCommand}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </PageInputHandler.Style>
        </PageInputHandler>
        <!-- Background Blur -->
        <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl x:Name="TopBar"
                                Style="{StaticResource A_Style_PlayerBarControl_WithTokens}" />

        <ContentControl x:Name="BottomBar"
                        Style="{StaticResource A_Style_ButtonBar}">
            <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                         HorizontalAlignment="Left"
                                         VerticalAlignment="Bottom"
                                         Background="{x:Null}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Download}"
                                               Visibility="{Binding GarageLayoutCollectionDataSource.IsDownloading, Converter={StaticResource A_Converter_BoolToVis}}" />
                <local:ControllerButtonControl Button="B"
                                               Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="X"
                                               Description="{local:Loc HelpButtons.IDS_GarageLayoutOptions}" />
                <local:ControllerButtonControl Button="Back"
                                               Description="{local:Loc HelpButtons.IDS_Search}" />
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding_Opus}">
            <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">
                <StackPanel Margin="15,0,0,0">
                    <ContentControl 
                        x:Name="ContentControl_SceneTitle"
                        Content="{Binding Title}"
                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                        HorizontalAlignment="Left" />
                    <FZTabButtonsSelector
                        x:Name="PART_GarageLayoutCategoryList"
                        ItemsSource="{Binding GarageLayoutCategories, RelativeSource={RelativeSource AncestorType=Page}}"
                        Style="{StaticResource H_Style_TabBar}"
                        SelectedItem="{Binding SelectedCategory}"
                        HorizontalAlignment="Left"/>

                </StackPanel>
                <Grid Margin="15,0,0,0">
                    <local:WrapListBox Style="{StaticResource A_Style_Carousel_CreationPosters}"
                                       ItemTemplate="{StaticResource A_DataTemplate_Carousel_GarageLayoutItem}"
                                       ItemsSource="{Binding GarageLayoutCollectionDataSource, RelativeSource={RelativeSource AncestorType=Page}}"
                                       Margin="-18,0,0,0"
                                       SelectionLimitTop="310"
                                       ItemContainerStyle="{StaticResource A_Style_ListBoxItem_CreationPoster_Base}"
                                       x:Name="PART_ItemList" />
                    <ContentControl Template="{StaticResource A_ControlTemplate_UserContent_SidePanel}" 
                                    DataContext="{Binding SelectedItem, ElementName=PART_ItemList}"
                                    VerticalAlignment="Top"
                                    Height="708">
                        <StackPanel x:Name="PopularityInfo_Panel"
                                    Orientation="Vertical"
                                    VerticalAlignment="Top"
                                    Margin="14,0"
                                    DataContext="{Binding SelectedItem, ElementName=PART_ItemList}">
                            <HeaderedContentControl Header="{Loc Storefront.IDS_Rank}"
                                                    Style="{StaticResource H_Style_UserContent_SidePanelItemWithHeader}"
                                                    Content="{Binding CreatorRank, Converter={NumUnitConverter FractionDigits=0}, FallbackValue=-}"/>
                            <FZMaterial Style="{StaticResource H_Style_StatDivider_InfoPanel}"/>
                             <HeaderedContentControl Style="{StaticResource H_Style_UserContent_SidePanelItemWithHeader}"
                                                    Header="{Loc Storefront.IDS_Downloads}"
                                                    Content="{Binding DownloadCount, Converter={NumUnitConverter FractionDigits=0}, FallbackValue=-}"/>
                            <FZMaterial Style="{StaticResource H_Style_StatDivider_InfoPanel}" />
                            <HeaderedContentControl Style="{StaticResource H_Style_UserContent_SidePanelItemWithHeader}"
                                                    Header="{Loc Storefront.IDS_Likes}"
                                                    Content="{Binding LikeCount, Converter={NumUnitConverter FractionDigits=0}, FallbackValue=-}"/>
                            <FZMaterial Style="{StaticResource H_Style_StatDivider_InfoPanel}" />
                            <StackPanel Visibility="{Binding UserProfile.IsLocalPlayer, Converter={StaticResource A_Converter_BoolToVis_Inverted}}">
                                <HeaderedContentControl Style="{StaticResource H_Style_UserContent_SidePanelItemFollower}"
                                                        Header="{Loc Storefront.IDS_LabelCreatorNotFollowed }"
                                                        Content="/ForzaUI;component/Textures/Data_Bound/CreativeHub/FollowedHeart.png"/>
                                <FZMaterial Style="{StaticResource H_Style_StatDivider_InfoPanel}" />
                            </StackPanel>
                        </StackPanel>
                    </ContentControl>

                    <local:NavigationArrows Style="{StaticResource A_Style_Control_NavigationArrows}"
                                            Template="{StaticResource A_ControlTemplate_NavigationArrows_FullscreenCarousel}"
                                            Height="205"
                                            Margin="290,0,0,80"
                                            VerticalAlignment="Center"
                                            CanSelectPrev="{Binding CanSelectPrev, ElementName=PART_ItemList}"
                                            CanSelectNext="{Binding CanSelectNext, ElementName=PART_ItemList}"
                                            ScrollPagePrevCommand="{Binding ScrollPagePrevCommand, ElementName=PART_ItemList}"
                                            ScrollPageNextCommand="{Binding ScrollPageNextCommand, ElementName=PART_ItemList}" />
                    <local:FZTextBlock Color="{StaticResource A_Color_SubHeader_Text}"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       TextAlignment="Center"
                                       Style="{StaticResource A_Style_CarouselText_NoGarageLayoutsFound}"
                                       Text="{local:Loc GarageLayout.IDS_UserContentGarageLayout_NoGarageLayoutsFound}"
                                       TextWrapping="Wrap"/>
                    <ProgressBar x:Name="IdleIndicator"
                                 IsIndeterminate="True"
                                 Style="{StaticResource A_Style_ProgressBar_WaitSpinner}"
                                 Height="56"
                                 Visibility="{Binding IsDownloading, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                </Grid>
            </StackPanel>
        </Border>
    </Grid>
</Page>
