<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_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>
            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                          Margin="-0.5">
                    <Grid Margin="7">
                    
                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangleStroke_MapBorder}"
                                  Color="#ffb4b4b4">
                            <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Rivals/CarouselGrid.png"/>
                        </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}"
                                  Color="#ff404040"
                                  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}" Width="246" Height="159"
                                                      MapView="{Binding ElementName=LoadSaveMapView}" />
                        <Grid VerticalAlignment="Bottom"
                              HorizontalAlignment="Right"
                              Margin="0,0,-0.5,-0.5" 
                              x:Name="LengthStatus">
                            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                      Margin="6,6,0.5,0.5"
                                      Color="{StaticResource A_Color_ItemStatusBackground}">
                                <local:FZTextBlock Text="{Binding Map.Distance}"
                                           Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceSmall}"
                                           Margin="8" />
                            </local:FZMaterial>
                        </Grid>
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_NewFile">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                          Margin="-0.5">
                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}" 
                                          Color="White">
                        <Grid   local:ScreenReader.Line="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}"
                                local:ScreenReader.LineType="SelectedItem"
                                local:ScreenReader.Event="OnChange"
                                local:ScreenReader.ControlType="Button">
                            
                            <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Create_New.png" 
                                              Width="{StaticResource A_Double_Carousel_7Item_Tile_Width}" 
                                              Height="{StaticResource A_Double_Carousel_7Item_Tile_Height}"/>
                            <local:FZTextBlock Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}"
                                           CapHeight="16"
                                           Color="{StaticResource A_Color_Tile_Text}"
                                           FontFamily="Horizon_B"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Bottom"
                                           Margin="23" />
                        </Grid>
                    </local:FZMaterial>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_CreateNewRoute">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                          Margin="-0.5">
                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}" 
                                          Color="White">
                            <Grid   local:ScreenReader.LineType="SelectedItem"
                                    local:ScreenReader.Event="OnChange"
                                    local:ScreenReader.ControlType="Button"
                                    local:ScreenReader.Line="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}">

                                <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Create_New.png" 
                                              Width="{StaticResource A_Double_Carousel_7Item_Tile_Width}" 
                                              Height="{StaticResource A_Double_Carousel_7Item_Tile_Height}"/>

                                <local:FZTextBlock  Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_New}"
                                           CapHeight="16"
                                           Color="{StaticResource A_Color_Tile_Text}"
                                           FontFamily="Horizon_B"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Bottom"
                                           Margin="23" />
                            </Grid>
                        </local:FZMaterial>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_DefaultRoute">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                          Margin="-0.5">
                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}" 
                                          Color="White">
                        <Grid>
                            <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_Route.png" 
                                              Width="{StaticResource A_Double_Carousel_7Item_Tile_Width}" 
                                              Height="{StaticResource A_Double_Carousel_7Item_Tile_Height}"/>
                            <local:FZTextBlock Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_Default}"
                                           CapHeight="16"
                                           Color="{StaticResource A_Color_Tile_Text}"
                                           FontFamily="Horizon_B"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Bottom"
                                           Margin="23" />
                        </Grid>
                    </local:FZMaterial>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Carousel_RouteItem_DefaultArena">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                          Margin="-0.5">
                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}" 
                                          Color="White">
                        <Grid>
                            <local:FZMaterial x:Name="ArenaIcon"
                                              ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/Horizon_Route.png" 
                                              Width="{StaticResource A_Double_Carousel_7Item_Tile_Width}" 
                                              Height="{StaticResource A_Double_Carousel_7Item_Tile_Height}"/>
                            <local:FZTextBlock x:Name="ArenaType"
                                           Text="{local:Loc EventBlueprint.IDS_RouteBlueprint_Default}"
                                           CapHeight="16"
                                           Color="{StaticResource A_Color_Tile_Text}"
                                           FontFamily="Horizon_B"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Bottom"
                                           Margin="23" />
                        </Grid>
                    </local:FZMaterial>
                </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">
                <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: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_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_VisibleIfSelectedRouteIsNotForTheActiveTrack">
                <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 SelectedItem.MediaTrack, ElementName=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/UKLarge.png"/>
                <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.ExpansionOne}" Value="/ForzaUI;component/Textures/Data_Bound/LoadSaveRouteKeyArt/ExpansionOneLarge.png"/>
            </local:MappingConverter>

            <Style x:Key="A_Style_FZMaterial_MapKeyArt_Cover" TargetType="local:FZMaterial">
                <Setter Property="ImageSource" Value="{Binding SelectedItem.MediaTrack, ElementName=ItemList, Converter={StaticResource A_Converter_MapTrack_To_KeyArt}}" />
                <Setter Property="Visibility" Value="Visible"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SelectedItem.MediaTrack, ElementName=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=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>
            
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot">
        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <!-- Help Bar -->
        <ContentControl Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="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 A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll}"
                                      Color="{StaticResource A_Color_GlassPanel_NonInteractive}"/>
                        <Grid Width="1758" Height="498">
                            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                              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=ItemList, Converter={StaticResource A_MappingConverter_HideIfCreateNew}}">
                                        <local:MapCustomRenderElement Style="{StaticResource A_Style_MapCustomRenderElement_UIMap}" DataContext="{Binding MainMap}" Width="1758" Height="498"
                                                                      MapView="{Binding ElementName=LoadSaveRouteMapView}"/>
                                    </Decorator>
                                    <Decorator Style="{StaticResource A_Style_FrameworkElement_VisibleIfSelectedRouteIsNotForTheActiveTrack}" Margin="0,0,0,-0.5">
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_MapKeyArt_Cover}"/>
                                    </Decorator>
                                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/Event_Blueprint/RouteBlueprint.png" 
                                                      Visibility="{Binding SelectedItem.RouteItemType, ElementName=ItemList, Converter={StaticResource A_MappingConverter_ShowIfCreateNew}}"/>
                                    <Grid VerticalAlignment="Top">
                                        <local:FZMaterial Color="Black" Opacity="0.4"/>
                                        <StackPanel Margin="24">
                                            <Viewbox StretchDirection="DownOnly" HorizontalAlignment="Left">
                                                <StackPanel Orientation="Horizontal">
                                                    <local:FZTextBlock Text="{Binding SelectedItem.DisplayName, ElementName=ItemList, Converter={StaticResource A_StringToUpper}}"
                                                                        Style="{StaticResource A_Style_FZTextBlock_RivalsRouteName}" />
                                                </StackPanel>
                                            </Viewbox>
                                        </StackPanel>
                                    </Grid>
                                </Grid>
                            </local:FZMaterial>
                            <Decorator Visibility="{Binding SelectedItem.RouteItemType, ElementName=ItemList, Converter={StaticResource A_MappingConverter_HideIfCreateNew}}">
                                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                                                  Margin="22,0,0,18" Visibility="{Binding MainMap.Distance, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                                                  Color="{StaticResource A_Color_ItemStatusBackground}"
                                                                  VerticalAlignment="Bottom"
                                                                  HorizontalAlignment="Left">
                                    <StackPanel Orientation="Horizontal"
                                                                Margin="12">
                                        <local:FZTextBlock Text="{local:Loc Rivals.IDS_Distance}"
                                                                           Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}"
                                                                           Margin="0,0,8,0"/>
                                        <local:FZTextBlock Text="{Binding MainMap.Distance}" Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}" />
                                    </StackPanel>
                                </local:FZMaterial>
                            </Decorator>
                        </Grid>
                    </Grid>

                    <!-- Carousel -->
                    <ContentControl Template="{StaticResource A_Template_ContentControl_SelectorContainer_PageButtons}"
                                    Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_3}"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    Margin="0,11,0,-15">
                        <local:WrapListBox x:Name="ItemList"
                                        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                        Style="{StaticResource A_Style_Carousel_7Item}"
                                        ItemTemplate="{StaticResource A_DataTemplate_Carousel_RouteItem}"
                                        ItemsSource="{Binding ItemsCollection}"
                                        local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                        Width="1758"/>
                    </ContentControl>
                </StackPanel>
            </StackPanel>
        </Border>
    </Grid>
</Page>
