<PopupLoadSaveRoute 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_LoadSaveRoute"
      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>
            <local:MappingConverter x:Key="A_MappingConverter_CustomIcon_VisibilityFromRouteItemType" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.SavedFile}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.UnsavedRoute}"
                                             Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <Style x:Key="A_Style_MapCustomRenderElement_UIMap_Route" 
                   TargetType="local:MapCustomRenderElement"
                   BasedOn="{StaticResource A_Style_MapCustomRenderElement_UIMap}">
                <Setter Property="IsEnabled" Value="False" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=(Selector.IsSelected), RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Value="True">
                        <Setter Property="IsEnabled" Value="True" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem">
                <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_3px}">
                    <Grid Margin="10">
                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangleStroke_MapBorder}"
                                  Color="#c6bfc6">
                            <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Rivals/CarouselGrid.png" Color="#000"/>
                        </local:FZMaterial>

                        <!-- This is used to blank out the grid near the route length status box, but the map route should draw on top of it -->
                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_RivalsDistanceGap}"
                                  VerticalAlignment="Bottom"
                                  HorizontalAlignment="Right"
                                  Margin="0,0,-0.5,-0.5"
                                  Width="{Binding ActualWidth, ElementName=LengthStatus}"
                                  Height="{Binding ActualHeight, ElementName=LengthStatus}" />
                        <local:MapViewControllerWindowed x:Name="LoadSaveMapView"
                                                         DataContext="{Binding Map}"
                                                         Style="{StaticResource A_Style_MapViewController_UIMap}" />
                        <local:MapCustomRenderElement Style="{StaticResource A_Style_MapCustomRenderElement_UIMap}" DataContext="{Binding Map}"
                                                      MapView="{Binding ElementName=LoadSaveMapView}" />
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/CustomRouteFile_Icon.png" VerticalAlignment="Top" HorizontalAlignment="Right"
                                          Height="30" Width="30"
                                          Visibility="{Binding RouteItemType, Converter={StaticResource A_MappingConverter_CustomIcon_VisibilityFromRouteItemType}, FallbackValue=Collapsed}"/>
                        <Grid VerticalAlignment="Bottom"
                              HorizontalAlignment="Right"
                              Margin="0,0,-0.5,-0.5" 
                              x:Name="LengthStatus">
                            <Decorator Margin="8,8,0.5,0.5">
                                <local:FZTextBlock Text="{Binding Map.Distance}"
                                           Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceSmall}"
                                           Color="{StaticResource H_Color_Primary_Black}" />
                            </Decorator>
                        </Grid>
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_NewFile">
                <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_3px}"
                          Margin="-0.5">
                    <Grid>
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Create_New.png" 
                                      Width="55" 
                                      Height="55"
                                      Margin="0,30,0,0"
                                      VerticalAlignment="Top"
                                      Color="{StaticResource H_Color_Primary_Black}"/>
                        <local:FZTextBlock Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}"
                                       CapHeight="16"
                                       Color="{StaticResource H_Color_Primary_Black}"
                                       FontFamily="Horizon_B"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Bottom"
                                       Margin="0,0,0,32" />
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_CreateNewRoute">
                <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_3px}">
                    <Grid>
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Create_New.png" 
                                      Width="55" 
                                      Height="55"
                                      Margin="0,30,0,0"
                                      VerticalAlignment="Top"
                                      Color="{StaticResource H_Color_Primary_Black}"/>
                        <local:FZTextBlock Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}"
                                   CapHeight="16"
                                   Color="{StaticResource H_Color_Primary_Black}"
                                   FontFamily="Horizon_B"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Bottom"
                                   Margin="0,0,0,32" />
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_DefaultRoute">
                <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_3px}">
                    <Grid>
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_Route.png" 
                                      Width="55" 
                                      Height="55"
                                      Margin="0,30,0,0"
                                      VerticalAlignment="Top"
                                      Color="{StaticResource H_Color_Primary_Black}"/>
                        <local:FZTextBlock Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_Default}"
                                       CapHeight="16"
                                       Color="{StaticResource H_Color_Primary_Black}"
                                       FontFamily="Horizon_B"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Bottom"
                                       Margin="0,0,0,32" />
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_DefaultArena">
                <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_3px}">
                    <Grid>
                        <local:FZMaterial x:Name="ArenaIcon"
                                          ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_Route.png" 
                                      Width="55" 
                                      Height="55"
                                      Margin="0,30,0,0"
                                      VerticalAlignment="Top"
                                      Color="{StaticResource H_Color_Primary_Black}"/>
                        <local:FZTextBlock x:Name="ArenaType"
                                       Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_Default}"
                                       CapHeight="16"
                                       Color="{StaticResource H_Color_Primary_Black}"
                                       FontFamily="Horizon_B"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Bottom"
                                       Margin="0,0,0,32" />
                    </Grid>
                </local:FZMaterial>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding GameMode}" Value="{x:Static local:RaceMode.TeamKing}">
                        <Setter TargetName="ArenaIcon" Property="ImageSource" Value="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_TeamKing.png"/>
                        <Setter TargetName="ArenaType" Property="Text" Value="{local:Loc PlaygroundGames.IDS_TeamKing_Title}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding GameMode}" Value="{x:Static local:RaceMode.TeamInfected}">
                        <Setter TargetName="ArenaIcon" Property="ImageSource" Value="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_TeamInfected.png"/>
                        <Setter TargetName="ArenaType" Property="Text" Value="{local:Loc PlaygroundGames.IDS_Survival_Title}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding GameMode}" Value="{x:Static local:RaceMode.TeamFlagRush}">
                        <Setter TargetName="ArenaIcon" Property="ImageSource" Value="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_TeamFlagRush.png"/>
                        <Setter TargetName="ArenaType" Property="Text" Value="{local:Loc PlaygroundGames.IDS_TeamFlagRush_Title}"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <local:MappingConverter x:Key="A_MappingConverter_ControlTemplate_Carousel_FromRouteItemType" CheckEnumKey="RouteItemType">
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.SavedFile}" Value="{StaticResource A_ControlTemplate_Carousel_RouteItem}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.DefaultArena}" Value="{StaticResource A_ControlTemplate_Carousel_RouteItem_DefaultArena}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.DefaultRoute}" Value="{StaticResource A_ControlTemplate_Carousel_RouteItem_DefaultRoute}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.CreateRoute}" Value="{StaticResource A_ControlTemplate_Carousel_RouteItem_CreateNewRoute}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.NewFile}" Value="{StaticResource A_ControlTemplate_Carousel_RouteItem_NewFile}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.UnsavedRoute}"
                                             Value="{StaticResource A_ControlTemplate_Carousel_RouteItem}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.DynamicRoute}"
                                             Value="{StaticResource A_ControlTemplate_Carousel_RouteItem}" />
            </local:MappingConverter>

            <DataTemplate x:Key="A_DataTemplate_Carousel_RouteItem">
                <Control Template="{Binding RouteItemType, Converter={StaticResource A_MappingConverter_ControlTemplate_Carousel_FromRouteItemType}}"/>
            </DataTemplate>

            <local:MappingConverter x:Key="A_MappingConverter_HideIfCreateNew" Default="{x:Static Visibility.Visible}">
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.CreateRoute}" Value="{x:Static Visibility.Collapsed}" />
            </local:MappingConverter>
            <local:MappingConverter x:Key="A_MappingConverter_DistancePrefix" Default="{local:Loc Rivals.IDS_Distance}">
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.SavedFile}" Value="{local:Loc Rivals.IDS_CustomDistance}" />
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.UnsavedRoute}"
                                             Value="{local:Loc Rivals.IDS_CustomDistance}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_ShowIfCreateNew" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:RouteItemType.CreateRoute}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <Style TargetType="FrameworkElement" x:Key="A_Style_FrameworkElement_VisibleIfSelectedRouteIsNotForCampaignSlotMediaTrack">
                <Setter Property="local:MultiDataConversion.TargetType" Value="{x:Type Int32}" />
                <Setter Property="local:MultiDataConversion.Value" Value="{Binding CampaignSlotMediaTrack, RelativeSource={RelativeSource AncestorType=Page}}" />
                <Setter Property="local:MultiDataConversion.Parameter" Value="{Binding SelectedItem.MediaTrack, ElementName=PART_ItemList}" />
                <Setter Property="local:MultiDataConversion.Converter" Value="{StaticResource A_CompareConverter}" />
                <Setter Property="Visibility" Value="Visible" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding (local:MultiDataConversion.Output), RelativeSource={RelativeSource Self}}" Value="0">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <local:MappingConverter x:Key="A_Converter_MapTrack_To_KeyArt">
                <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.Default}" Value="/ForzaUI;component/Textures/Data_Bound/LoadSaveRouteKeyArt/DefaultLarge.png"/>
                <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.ExpansionOne}" Value="/ForzaUI;component/Textures/Data_Bound/LoadSaveRouteKeyArt/ExpansionOneLarge.png"/>
                <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.ExpansionTwo}" Value="/ForzaUI;component/Textures/Data_Bound/LoadSaveRouteKeyArt/ExpansionTwoLarge.png"/>
            </local:MappingConverter>

            <Style x:Key="A_Style_FZMaterial_MapKeyArt_Cover" TargetType="local:FZMaterial">
                <Setter Property="ImageSource" Value="{Binding SelectedItem.MediaTrack, ElementName=PART_ItemList, Converter={StaticResource A_Converter_MapTrack_To_KeyArt}}" />
                <Setter Property="Visibility" Value="Visible"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SelectedItem.MediaTrack, ElementName=PART_ItemList}" Value="{x:Static local:XAMLTrack.Invalid}">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                 </Style.Triggers>
            </Style>
            
            <Style BasedOn="{StaticResource A_Style_MapViewController_UIMap}" x:Key="A_Style_MapViewController_UIMap_CustomInterpolation"
           TargetType="{x:Type local:MapViewControllerWindowed}">
                <Setter Property="local:PropertyChangeHistory.Input" Value="{Binding SelectedItem.MediaTrack, ElementName=PART_ItemList}"/>
                <Setter Property="local:MultiDataConversion.TargetType" Value="{x:Type Int32}" />
                <Setter Property="local:MultiDataConversion.Value" Value="{Binding ActiveTrack, RelativeSource={RelativeSource AncestorType=Page}}" />
                <Setter Property="local:MultiDataConversion.Parameter" Value="{Binding (local:PropertyChangeHistory.Previous), RelativeSource={RelativeSource Self}}" />
                <Setter Property="local:MultiDataConversion.Converter" Value="{StaticResource A_CompareConverter}" />
                <Setter Property="InterpolationTime" Value="0" />
                <Style.Triggers>
                    <!-- Can interpolate if the previous route we will interpolate from was on the active track-->
                    <DataTrigger Binding="{Binding (local:MultiDataConversion.Output), RelativeSource={RelativeSource Self}}" Value="0">
                        <Setter Property="InterpolationTime" Value="1.0" />
                    </DataTrigger>
                    <!-- Can interpolate if the track for the route is not set, which is something that happens for non-custom route saves being used in this scene-->
                    <DataTrigger Binding="{Binding (local:PropertyChangeHistory.Previous), RelativeSource={RelativeSource Self}}" Value="{x:Static local:XAMLTrack.Invalid}">
                        <Setter Property="InterpolationTime" Value="1.0" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="ListBoxItem"
                   x:Key="H_Style_LoadSaveRoute_Carousel_ContainerStyle"
                   BasedOn="{StaticResource H_Style_ContentControl_Carousel_ContainerStyle}">
                <Style.Resources>
                    <CornerRadius x:Key="A_StrokeHighlight_ContentRadius">2</CornerRadius>
                </Style.Resources>
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="PART_LayoutRoot">
        <MappingConverterResourcePreloader Converter="{StaticResource A_Converter_MapTrack_To_KeyArt}" ValueType="{Type BitmapImage}"/>
        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <!-- Help Bar -->
        <ContentControl Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel" Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                                      local:UIPageTransitionManager.TransitionIndex="1">
                    <ContentControl x:Name="TitleBlock"
                                                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                                    local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Blueprint.png"
                                                    Content="{Binding Title}"
                                                    HorizontalAlignment="Left" />
                </Grid>
                <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                            local:UIPageTransitionManager.TransitionIndex="0">
                    <Grid>
                        <local:FZMaterial Preset="{StaticResource H_GlassRoundtangle_1px}" Color="{StaticResource H_Color_Glass_Purple_20pc}"/>
                        <Grid Width="1676" Height="456">
                            <local:FZMaterial Preset="{StaticResource H_Roundtangle_Outer_1px}"
                                              CaptureSubgraph="True">
                                <Grid Background="#ff0A0E1A">
                                    <local:MapViewControllerWindowed x:Name="LoadSaveRouteMapView"
                                                                        DataContext="{Binding MainMap}"
                                                                        Style="{StaticResource A_Style_MapViewController_UIMap_CustomInterpolation}" />
                                    <Decorator Visibility="{Binding SelectedItem.RouteItemType, ElementName=PART_ItemList, Converter={StaticResource A_MappingConverter_HideIfCreateNew}}">
                                        <local:MapCustomRenderElement Style="{StaticResource A_Style_MapCustomRenderElement_UIMap_Route}" DataContext="{Binding MainMap}" Width="1676" Height="456"
                                                                        MapView="{Binding ElementName=LoadSaveRouteMapView}"
                                                                        x:Name="PART_MapCustomRenderElement"/>
                                    </Decorator>
                                    <Decorator Style="{StaticResource A_Style_FrameworkElement_VisibleIfSelectedRouteIsNotForCampaignSlotMediaTrack}" Margin="0,0,0,-0.5">
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_MapKeyArt_Cover}"/>
                                    </Decorator>
                                </Grid>
                            </local:FZMaterial>
                            <FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/RouteBlueprint.png" 
                                        Visibility="{Binding SelectedItem.RouteItemType, ElementName=PART_ItemList, Converter={StaticResource A_MappingConverter_ShowIfCreateNew}}"/>
                                <FZMaterial x:Name="RouteShadowGradient" Height="190" VerticalAlignment="Bottom" >
                                    <FZMaterial.Preset>
                                        <FZMaterialPresetRoundtangle GradientColorA="#D8000000"
                                                                     GradientColorB="#00000000" />
                                    </FZMaterial.Preset>
                                </FZMaterial>
                            <Grid VerticalAlignment="Bottom" 
                                    HorizontalAlignment="Left">
                                <StackPanel Margin="25">
                                    <Viewbox StretchDirection="DownOnly" 
                                                HorizontalAlignment="Left">
                                            <FZTextBlock Text="{Binding SelectedItem.DisplayName, ElementName=PART_ItemList}"
                                                Style="{StaticResource A_Style_FZTextBlock_HorizonC}"
                                                CapHeight="65"
                                                Color="{StaticResource H_Color_Primary_White}" />
                                    </Viewbox>
                                    <Decorator Visibility="{Binding SelectedItem.RouteItemType, ElementName=PART_ItemList, Converter={StaticResource A_MappingConverter_HideIfCreateNew}}">
                                        <Decorator  Visibility="{Binding MainMap.Distance, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                                                            VerticalAlignment="Bottom"
                                                                            HorizontalAlignment="Left">
                                            <StackPanel Orientation="Horizontal" Margin="0,31,0,0">
                                                <local:FZTextBlock Text="{Binding SelectedItem.RouteItemType, ElementName=PART_ItemList, Converter={StaticResource A_MappingConverter_DistancePrefix} }"
                                                    CapHeight="18"
                                                    FontFamily="Horizon_A"
                                                    Color="{StaticResource H_Color_Primary_White}"
                                                    Margin="0,0,8,0"/>
                                                <local:FZTextBlock Text="{Binding MainMap.Distance}"
                                                    CapHeight="18"
                                                    FontFamily="Horizon_A"
                                                    Color="{StaticResource H_Color_Primary_Green}" />
                                            </StackPanel>
                                        </Decorator>
                                    </Decorator>
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </Grid>

                    <!-- Carousel -->
                    <ContentControl Template="{StaticResource A_Template_ContentControl_SelectorContainer_PageButtons}"
                                    Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_3}"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    Margin="0,8,0,-15">
                        <local:WrapListBox x:Name="PART_ItemList"
                                        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                        Style="{StaticResource H_Style_Carousel_Rectangular_7Items}"
                                        ItemTemplate="{StaticResource A_DataTemplate_Carousel_RouteItem}"
                                        ItemsSource="{Binding ItemsCollection}"
                                        ItemContainerStyle="{StaticResource H_Style_LoadSaveRoute_Carousel_ContainerStyle}"
                                        local:FocusOnPageFocusGained.SelectorSelectedItem="True"/>
                    </ContentControl>
                </StackPanel>
            </StackPanel>
        </Border>
    </Grid>
</PopupLoadSaveRoute>
