<Page 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:local="clr-namespace:ForzaUI"
      mc:Ignorable="d"
      x:Class="ForzaUI.Scenes.Anthem.A_OnlineAdventureFlyerView"
      Style="{StaticResource A_Style_Page_Generic}"
      FlowDirection="LeftToRight"
      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_Converter_HUDSceneToCountdownType" Default="Any">
                <local:MappingConverterEntry Key="{x:Static local:SceneEntryEnum.HorizonTourFlyerView}" Value="EventFlyerActivation" />
            </local:MappingConverter>
            <Style x:Key="A_Style_NetworkCountdownControl_CarSelectCustom"
                   TargetType="{x:Type local:NetworkCountdownControl}"
                   BasedOn="{StaticResource A_Style_NetworkCountdownControl_Base}">
                <Setter Property="HorizontalAlignment" Value="Left" />
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_MultiplayerCountdown}" />
                <Setter Property="TimerDisplayName" Value="{local:Loc Lobby.IDS_SelectYourCar_Countdown}" />
                <Setter Property="CountdownType" Value="{Binding SceneEnum, Converter={StaticResource A_Converter_HUDSceneToCountdownType}}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding CampaignSetup.IsTour, FallbackValue={StaticResource A_Boolean_False}}" Value="True">
                        <Setter Property="TimerDisplayName" Value="{Binding Source={local:Loc ForzaEvents.IDS_TimeRemaining}, Converter={StaticResource A_StringToUpper}}" />
                        <Setter Property="CountdownType" Value="EventFlyerActivation"/>
                        <Setter Property="Visibility"
                                Value="Visible" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsCarSelected, FallbackValue={StaticResource A_Boolean_False}}" Value="True">
                        <Setter Property="TimerDisplayName" Value="{local:Loc Lobby.IDS_AdventureStart_Countdown}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_CompositeVisiblityWrapper" TargetType="{x:Type Decorator}">
                <Setter Property="Visibility" Value="Collapsed" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ShowCountdown}" Value="True">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <local:FZMaterialPresetGlassRoundtangle x:Key="A_FZMaterialPreset_RaceInfo_EventIndex"
                                               BasedOn="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_Base}"
                                               CornerRadius="1"/>
            
            <Style x:Key="A_Style_WrapListBoxItem_RaceItemContainer" TargetType="ContentControl" BasedOn="{StaticResource H_Style_ContentControl_Carousel_ContainerStyle}">
                <Setter Property="Margin" Value="0,2,0,2"/>
                <Setter Property="Focusable" Value="False" />
                <Setter Property="local:BindingProxy.A" Value="{Binding CampaignSetup, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Page}}}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <DockPanel VerticalAlignment="Stretch">
                                <local:FZMaterial Margin="0,0,4,0" DockPanel.Dock="Left" Width="50"
                                                  Preset="{StaticResource A_FZMaterialPreset_RaceInfo_EventIndex}"
                                                  Color="{Binding CompletionState, Converter={StaticResource A_MappingConverter_RaceCompletionState_To_ItemBackgroundColor}}">
                                    <local:FZTextBlock Text="{Binding EventIndex, Converter={StaticResource A_NumUnitConverter_Min2Digits_0dp}}" FontFamily="Horizon_C" 
                                                       VerticalAlignment="Center" HorizontalAlignment="Center"
                                                       Color="{Binding CompletionState, Converter={StaticResource A_MappingConverter_RaceCompletionState_To_ItemTextColor}}" 
                                                       CapHeight="18" />
                                </local:FZMaterial>
                                <Grid>
                                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPreset_RaceInfo_EventIndex}" Color="{Binding CompletionState, Converter={StaticResource A_MappingConverter_RaceCompletionState_To_ItemBackgroundColor}}"/>
                                    <ContentPresenter />
                                </Grid>
                            </DockPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="A_Style_Control_RaceInfo" TargetType="Control">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Control">
                            <StackPanel Orientation="Vertical">
                                <Grid Margin="54,0,0,0">
                                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPreset_RaceInfo_Header}" Color="{StaticResource H_Color_Primary_Green}" Width="auto" Height="50" Margin="0,0,18,0"/>
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="15,15,0,0">
                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonPlayHeader}" 
                                                           HorizontalAlignment="Left"/>
                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HorizonPlayHeader_Distance}" 
                                                           HorizontalAlignment="Left"/>
                                    </StackPanel>
                                </Grid>
                                <DockPanel VerticalAlignment="Top">
                                    <Grid>
                                        <DockPanel Margin="0,3,0,0">
                                            <WrapListBox x:Name="PART_RaceList"
                                                 Width="822"
                                                 Template="{StaticResource H_ControlTemplate_TextMenu_Default}"
                                                 ScrollOrientation="Vertical"
                                                 Height="656"
                                                 ItemHeight="132"
                                                 Margin="0,0,0,0"
                                                 ItemWidth="804"
                                                 AlternationCount="10000"
                                                 HorizontalAlignment="Center"
                                                 ItemsSource="{Binding RaceSetups}"
                                                 ItemContainerStyle="{StaticResource A_Style_WrapListBoxItem_RaceItemContainer}"
                                                 EmptyItemStyle="{StaticResource A_Style_Control_EmptyItemStyle}"
                                                 ItemTemplate="{StaticResource A_DataTemplate_RaceSetupItem}" />
                                        </DockPanel>
                                    </Grid>
                                </DockPanel>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <local:MappingConverter x:Key="A_Converter_InverseVisibility" Default="Hidden">
                <local:MappingConverterEntry Key="{x:Static Visibility.Collapsed}" Value="{x:Static Visibility.Visible}"/>
                <local:MappingConverterEntry Key="{x:Static Visibility.Visible}" Value="{x:Static Visibility.Collapsed}"/>
            </local:MappingConverter>
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="PART_LayoutRoot" Visibility="{Binding FlyerLoaded, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
        <ContentControl x:Name="BottomBar"
                        Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <Grid>
                <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,48,0,0">
                    <StackPanel Orientation="Horizontal" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                        <ContentControl x:Name="TitleBlock"
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                        Tag="{local:Loc ScreenTitles.IDS_EventSignup}" Content="{local:Loc ScreenTitles.IDS_EventSignup}" 
                                        Margin="54,0,0,0"/>
                    </StackPanel>

                    <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" HorizontalAlignment="Center" Margin="0,10,0,0">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding CampaignSetup}">
                            <Control Style="{StaticResource A_Style_Control_RaceInfo}"/>
                            <ContentControl Margin="-10,0,0,0" Style="{StaticResource A_Style_ContentControl_CampaignFlyerFront}"/>
                        </StackPanel>
                    </StackPanel>    
                </StackPanel>
                <Decorator x:Name="PART_TimerVisibility" Style="{StaticResource A_Style_CompositeVisiblityWrapper}" HorizontalAlignment="Right" Margin="0,0,-29,-39">
                    <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_CarSelectCustom}" UseColonFormat="True"/>
                </Decorator>
            </Grid>
        </Border>

        <Decorator Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}" Margin="0,70,0,0"
              Visibility="{Binding Path=Visibility, ElementName=PART_TimerVisibility, Converter={StaticResource A_Converter_InverseVisibility}}">
            <ContentControl Style="{StaticResource A_Style_ContentControl_LoadingSpinnerWithMessage}"
                            Visibility="{Binding AdventureStatusMessage, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"
                            Content="{Binding AdventureStatusMessage}"/>
        </Decorator>
    </Grid>
</Page>