<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"  
      x:Class="ForzaUI.A_LoadSave"
      mc:Ignorable="d"
      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>
        <ResourceDictionary>



            <Style x:Key="A_Style_ContentControl_Carousel_ContainerStyle_Livery"
                   TargetType="{x:Type ContentControl}"
                   BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_Internal}">
                <Style.Resources>
                    <local:FZMaterialPresetRoundtangleStroke x:Key="A_FZMaterialPresetRoundtangleStroke_CarouselContainerHighlight"
                                                             BasedOn="{StaticResource A_FZMaterialPresetRoundtangleStroke_Rollover}"
                                                             CornerRadius="14"
                                                             Thickness="8,8,8,48" />
                    <Style x:Key="A_FZMaterial_CarouselContainerHighlight_Dynamic"
                           TargetType="{x:Type local:FZMaterial}">
                        <Setter Property="GreedyMeasure" Value="True" />
                        <Setter Property="Margin" Value="-6,-6,-6,-46" />
                        <Setter Property="local:ZPanel.DisableClipping" Value="True" />
                        <Setter Property="IsHitTestVisible" Value="False" />
                        <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangleStroke_CarouselContainerHighlight}" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsSavingMode, RelativeSource={RelativeSource AncestorType=Page}}"
                                         Value="False">
                                <Setter Property="Margin"
                                        Value="-6" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Style.Resources>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_Carousel_VinylItem">
                <ContentControl Template="{StaticResource A_ControlTemplate_CarouselItemContent_WithBottomHighlightTag}"
                                Tag="{local:Loc Livery.IDS_SaveDesign}"
                                IsEnabled="{Binding IsSavingMode, RelativeSource={RelativeSource AncestorType=Page}}">
                    <Grid Height="213">
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Icons/Livery/VinylGroups_Checkerboard.png"/>
                        <local:FZMaterial x:Name="Icon"
                                          ImageSource="{Binding Thumbnail}"
                                          Stretch="Uniform"
                                          Margin="8" />
                        <local:FZMaterial Color="#80000000"
                                          Height="46"
                                          VerticalAlignment="Bottom"
                                          Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterBottomOnly}">
                              <DockPanel Margin="6,0">
                                <StackPanel Orientation="Horizontal"
                                    VerticalAlignment="Center"
                                    Height="34"
                                    DockPanel.Dock="Right">
                                    <local:FZMaterial Color="{StaticResource A_Color_Header_Background}"
                                        Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerLeftOnly}"
                                        Width="34">
                                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Icons/Livery/Vinyl_Layers.png"/>
                                    </local:FZMaterial>
                                    <local:FZMaterial Color="{StaticResource A_Color_Tile_Background}"
                                        Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerRightOnly}"
                                        MinWidth="34">
                                        <local:FZTextBlock Text="{Binding CurrentLayerCount, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}}"
                                            Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                            Color="{StaticResource A_Color_Tile_Text}"
                                            CapHeight="16"
                                            Margin="12, 0"
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"/>
                                    </local:FZMaterial>
                                </StackPanel>
                                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                   CapHeight="16"
                                   Color="{StaticResource A_Color_Body_Text}"
                                   Text="{Binding DisplayName, Converter={StaticResource A_StringToUpper}}"
                                   Margin="8,0"
                                   VerticalAlignment="Center"
                                   DockPanel.Dock="Left" />
                              </DockPanel>
                            </local:FZMaterial>
                    </Grid>
                </ContentControl>
            </DataTemplate>

            <DataTemplate x:Key="A_DataTemplate_Carousel_LockableCarItem_Livery">
                <ContentControl Template="{StaticResource A_ControlTemplate_CarouselItemContent_WithBottomHighlightTag}"
                                Tag="{local:Loc Livery.IDS_SaveDesign}"
                                IsEnabled="{Binding IsSavingMode, RelativeSource={RelativeSource AncestorType=Page}}">
                    <Grid>
                        <Grid Height="213"
                              Visibility="{Binding IsNewItem, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                            <local:FZMaterial ImageSource="{Binding BigThumbnail}"
                                              Style="{StaticResource A_Style_FrameworkElement_CarSelectItemForeground}"
                                              Margin="0,0,0,0" />
                            <Grid VerticalAlignment="Top"
                                  HorizontalAlignment="Center">
                                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterTopOnly}"
                                                  Style="{StaticResource A_Style_FZMaterial_CarSelectCarouselItem_ItemTitleBackground}"
                                                  Width="342"
                                                  Height="78">
                                    <Grid Margin="15">
                                        <Decorator Margin="0,-6,0,0">
                                            <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_CarSelectCarTitle}"
                                                                   Orientation="Horizontal"
                                                                   VerticalAlignment="Top"
                                                                   HorizontalAlignment="Center"
                                                                   Height="40"
                                                                   Width="312"/>
                                        </Decorator>
                                        <Viewbox StretchDirection="DownOnly"
                                                 VerticalAlignment="Bottom">
                                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_CarSelectCarousel_Manufacturer}"
                                                               Text="{Binding UserProfile.FormattedGamertag, FallbackValue=-}" />
                                        </Viewbox>
                                    </Grid>
                                </local:FZMaterial>
                            </Grid>
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_CarSelectCarouselItem_StatusIconBackground}"
                                              Visibility="{Binding IsLocked, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue={x:Static Visibility.Collapsed}}"
                                              VerticalAlignment="Bottom"
                                              HorizontalAlignment="Right"
                                              Margin="8">
                                <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Icons/Livery/VinylGroup_Lock.png"
                                                  Style="{StaticResource A_Style_FZMaterial_CarSelectCarouselItem_StatusIcon}"
                                                  Height="25"
                                                  Stretch="Uniform"/>
                            </local:FZMaterial>
                        </Grid>
                        <Decorator Height="213"
                                   Visibility="{Binding IsNewItem, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <Grid Margin="8">
                                <local:FZMaterial ImageSource="{Binding Thumbnail}"
                                                  Stretch="Uniform" />
                                <local:FZMaterial Color="#80000000"
                                                  Height="46"
                                                  VerticalAlignment="Bottom"
                                                  Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerBottomOnly}">
                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                                       CapHeight="18"
                                                       Color="{StaticResource A_Color_Body_Text}"
                                                       Text="{Binding DisplayName, Converter={StaticResource A_StringToUpper}}"
                                                       Margin="16,0"
                                                       VerticalAlignment="Center" />
                                </local:FZMaterial>
                            </Grid>
                        </Decorator>
                    </Grid>
                </ContentControl>
            </DataTemplate>

            <Style x:Key="A_Style_FrameworkElement_CollapseIfNoCategories"
                   BasedOn="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                   TargetType="{x:Type FrameworkElement}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=(ItemsControl.Items).(ItemCollection.Count), ElementName=CategoryList, Converter={StaticResource A_CompareConverter}, ConverterParameter=2}"
                                 Value="-1">
                        <Setter Property="Visibility"
                                Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Size x:Key="A_Size_GamerPicSizeParams">342,342</Size>

            <Style TargetType="{x:Type local:ItemsSelector}"
                x:Key="A_Style_ItemsSelector_LiveryPopupTabBar"
                BasedOn="{StaticResource A_Style_ItemsSelector_UGCPopupTabBar}">
                <Style.Resources>
                    <System:Double x:Key="A_Double_UGCPopupItemWidth_Dynamic">262.66</System:Double>
                    <Thickness x:Key="A_Thickness_UGCPopupItemPadding_Dynamic">262.66,0,0,0</Thickness>
                </Style.Resources>
                <Setter Property="Width"
                        Value="1734"/>
                <Setter Property="Margin"
                        Value="0,0,0,12"/>
            </Style>

        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="TypeStateGroup">
                <VisualState x:Name="LiveryCatalogState">
                    <Storyboard>
                        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="ContentControl_SceneTitle">
                            <DiscreteStringKeyFrame KeyTime="0" Value="{local:Loc Livery.IDS_DesignCatalog}"/>
                        </StringAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate" Storyboard.TargetName="ItemList">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource A_DataTemplate_Carousel_LockableCarItem_Livery}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="LiveryCatalogState_Save">
                    <Storyboard>
                        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="ContentControl_SceneTitle">
                            <DiscreteStringKeyFrame KeyTime="0" Value="{local:Loc Livery.IDS_SaveDesign}"/>
                        </StringAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate" Storyboard.TargetName="ItemList">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource A_DataTemplate_Carousel_LockableCarItem_Livery}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="LiveryGroupState">
                    <Storyboard>
                        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="ContentControl_SceneTitle">
                            <DiscreteStringKeyFrame KeyTime="0"
                                                    Value="{local:Loc Livery.IDS_VinylGroupCatalog}"/>
                        </StringAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate"
                                                       Storyboard.TargetName="ItemList">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource A_DataTemplate_Carousel_VinylItem}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="LiveryGroupState_Save">
                    <Storyboard>
                        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="ContentControl_SceneTitle">
                            <DiscreteStringKeyFrame KeyTime="0"
                                                    Value="{local:Loc Livery.IDS_SaveLayerGroup_Title}"/>
                        </StringAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate"
                                                       Storyboard.TargetName="ItemList">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource A_DataTemplate_Carousel_VinylItem}" />
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid>
            <!-- Help Panel -->
            <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
                <ContentControl x:Name="DefaultHelpPanel"
                                Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>

            <Border Style="{StaticResource A_Style_Border_ScenePadding}">
                <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                            Margin="15,85,0,55"
                            VerticalAlignment="Center">
                    <!-- ContentControl_SceneTitle's Content is always overridden by the visual state animations, but we still 
                    need a default value to circumvent a crash when the animations are evaluated before the Title binding is 
                    set -->
                    <ContentControl x:Name="ContentControl_SceneTitle"
                                    Content="{local:Loc Livery.IDS_DesignCatalog}"
                                    local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Car.png"
                                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                    HorizontalAlignment="Left"/>

                    <Grid Style="{StaticResource A_Style_FrameworkElement_CollapseIfNoCategories}" HorizontalAlignment="Left">
                        <local:ItemsSelector x:Name="CategoryList"
                                             ItemsSource="{Binding Categories}"
                                             Style="{StaticResource A_Style_ItemsSelector_LiveryPopupTabBar}"
                                             Focusable="False"/>
                    </Grid>

                    <Grid>
                        <local:WrapListBox Style="{StaticResource A_Style_CommonListBox_FullScreenCarousel}"
                                             ItemTemplate="{StaticResource A_DataTemplate_Carousel_LockableCarItem_Livery}"
                                             ItemContainerStyle="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_Livery}"
                                             x:Name="ItemList" />
                        <DockPanel LastChildFill="False"
                                   Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                                   HorizontalAlignment="Left">
                            <local:FZMaterialGlassCapture />
                            <ContentControl DockPanel.Dock="Left"
                                            Style="{StaticResource A_Style_FrameworkElement_FullScreenCarousel_SidePanel}"
                                            Template="{StaticResource A_ControlTemplate_SidePanel}"
                                            x:Name="InformationPanel"
                                            Tag="{Binding Source={local:Loc Livery.IDS_CreatorInfo}, Converter={StaticResource A_StringToUpper}}">
                                <DockPanel DataContext="{Binding SelectedItem, ElementName=ItemList}">
                                    <Grid x:Name="CreatorInfo"
                                          DockPanel.Dock="Top">
                                        <local:FZMaterial x:Name="GamerPicMaterial"
                                            ImageSource="{Binding UserProfile, Converter={StaticResource A_GamerPicConverter}, ConverterParameter={StaticResource A_Size_GamerPicSizeParams}}"
                                            Height="342"
                                            Visibility="{Binding Downloaded, RelativeSource={RelativeSource Self}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}" />
                                        <ProgressBar Style="{StaticResource A_Style_ProgressBar_WaitSpinner}"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Visibility="{Binding Downloaded, ElementName=GamerPicMaterial, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}"/>
                                        <local:FZMaterial VerticalAlignment="Bottom"
                                                          Height="96"
                                                          Color="#80000000">
                                            <local:FZTextBlock Text="{Binding UserProfile.FormattedGamertag, FallbackValue=-}"
                                                               Style="{StaticResource A_Style_FZTextBlock_CreatorInfo_Gamertag}" />
                                        </local:FZMaterial>
                                    </Grid>
                                    <local:FZMaterial x:Name="FooterPanel"
                                                      Style="{StaticResource A_Style_FZMaterial_FlatPanel_FooterPanel}"
                                                      Height="72"
                                                      DockPanel.Dock="Bottom">
                                        <DockPanel x:Name="DateInfo_Panel"
                                                   Margin="30,0">
                                            <local:FZTextBlock Text="{local:Loc Storefront.IDS_LabelDate}"
                                                               Style="{StaticResource A_Style_FZTextBlock_CreatorInfo_CreatedDate}"
                                                               MaxWidth="140"
                                                               DockPanel.Dock="Left" />
                                            <local:FZTextBlock Text="{Binding DateCreated, FallbackValue=-}"
                                                               Style="{StaticResource A_Style_FZTextBlock_CreatorInfo_CreatedDate}"
                                                               HorizontalAlignment="Right" />
                                        </DockPanel>
                                    </local:FZMaterial>
                                    <Grid x:Name="PopularityInfo_Panel">
                                        <StackPanel Margin="30"
                                                    VerticalAlignment="Top">
                                            <StackPanel Orientation="Vertical" Visibility="{Binding IsLocalFile, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                                <Grid Margin="0,0,0,20">
                                                    <local:FZTextBlock Text="{Binding Source={local:Loc Storefront.IDS_NumberLikes}, Converter={StaticResource A_StringToUpper}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_InfoLabel}"
                                                                   Margin="0,0,15,0" />
                                                    <local:FZTextBlock Text="{Binding LikeCount, FallbackValue=-}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_InfoValue}" />
                                                </Grid>
                                                <Grid Margin="0,0,0,20">
                                                    <local:FZTextBlock Text="{Binding Source={local:Loc Storefront.IDS_NumberDownloads}, Converter={StaticResource A_StringToUpper}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_InfoLabel}"
                                                                   Margin="0,0,15,0" />
                                                    <local:FZTextBlock Text="{Binding DownloadCount, FallbackValue=-}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_InfoValue}" />
                                                </Grid>
                                            </StackPanel>
                                            <Grid>
                                                <local:FZTextBlock Text="{Binding Source={local:Loc Storefront.IDS_LabelPopularity}, Converter={StaticResource A_StringToUpper}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_InfoLabel}"
                                                                   Margin="0,0,15,0" />
                                                <Viewbox Width="106"
                                                         Height="18"
                                                         HorizontalAlignment="Right">
                                                    <local:DeltaProgressBar Style="{StaticResource A_Style_DeltaProgressBar_Popularity}"
                                                                            BaseValue="{Binding Popularity}"
                                                                            NewValue="{Binding Popularity}" />
                                                </Viewbox>
                                            </Grid>
                                        </StackPanel>
                                    </Grid>
                                </DockPanel>
                            </ContentControl>
                        </DockPanel>

                        <local:NavigationArrows Style="{StaticResource A_Style_Control_NavigationArrows}"
                                                Margin="-40,0,-20,0"
                                                CanSelectPrev="{Binding CanSelectPrev, ElementName=ItemList}"
                                                CanSelectNext="{Binding CanSelectNext, ElementName=ItemList}"
                                                ScrollPagePrevCommand="{Binding ScrollPagePrevCommand, ElementName=ItemList}"
                                                ScrollPageNextCommand="{Binding ScrollPageNextCommand, ElementName=ItemList}"/>
                    </Grid>

                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</Page>
