<Page
    xmlns:local="clr-namespace:ForzaUI;assembly="
    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"
    x:Class="ForzaUI.A_PopupPickCarManufacturerColor"
    mc:Ignorable="d"
    Style="{StaticResource A_Style_Page_Generic}"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Page.Resources>
        <ResourceDictionary>
            <local:LinearTransformConverter x:Key="A_LinearTransformConverter_RowsToHeight"
                                            CeilInput="True"
                                            Scale="55" />
            <System:Double x:Key="A_Double_Carousel_ItemsPerRow">2</System:Double>
            
            <DataTemplate x:Key="A_ControlTemplate_LargeColorItem">
                <Grid x:Name="Grid_Color"
                          RenderTransformOrigin="0.5,0.5">
                    <Grid Visibility="{Binding PreviewImage, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                        <Border BorderThickness="3" Visibility="{Binding IsClearColor, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                            <Border.BorderBrush>
                                <LinearGradientBrush StartPoint="0,0.5"
                                             EndPoint="1,0.5">
                                    <GradientStop Color="{Binding PrimaryColor}"
                                          Offset="0" />
                                    <GradientStop Color="{Binding SecondaryColor}"
                                          Offset="1" />
                                </LinearGradientBrush>
                            </Border.BorderBrush>
                            <Rectangle Margin="-1">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,0.5"
                                             EndPoint="1,0.5">
                                        <GradientStop Color="{Binding PrimaryColor}"
                                          Offset="0" />
                                        <GradientStop Color="{Binding SecondaryColor}"
                                          Offset="1" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                        </Border>
                    </Grid>

                    <local:FZMaterial Margin="36,0,0,0" Width="10" HorizontalAlignment="Left"
                                          Preset="{StaticResource A_FZMaterialPreset_Unlit}"
                                          Color="{Binding StripeColor}"
                                          Visibility="{Binding HasStripe, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />

                    <local:FZMaterial ImageSource="{Binding PreviewImage}"
                              Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                              Visibility="{Binding PreviewImage, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" >
                        <local:FZMaterial.LayoutTransform>
                            <RotateTransform Angle="90"/>
                        </local:FZMaterial.LayoutTransform>
                    </local:FZMaterial>

                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/NoColorItem.png"
                              Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                              Visibility="{Binding IsClearColor, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" >
                        <local:FZMaterial.LayoutTransform>
                            <RotateTransform Angle="90"/>
                        </local:FZMaterial.LayoutTransform>
                    </local:FZMaterial>
                </Grid>
            </DataTemplate>

            <Style x:Key="A_Style_ListBoxItem_ColorItem" TargetType="ListBoxItem"
                   BasedOn="{StaticResource H_Style_ContentControl_Carousel_ContainerStyle}">
                <Setter Property="Focusable" Value="True" />
                <Setter Property="Margin" Value="4,0,0,4" />
            </Style>

            <Style BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}"
                   TargetType="ListBoxItem"
                   x:Key="A_Style_ListBoxItem_Color_Empty">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_20pc}" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Height" Value="56" />
                <Setter Property="Width" Value="320" />
                <Setter Property="Focusable" Value="False" />
            </Style>

            <Style TargetType="WrapListBox"
                   x:Key="H_Style_ColorsCollection"
                   BasedOn="{StaticResource {Type WrapListBox}}">
                <Setter Property="Template" Value="{StaticResource H_ControlTemplate_TextMenu_Default}" />
                <Setter Property="ItemContainerStyle" Value="{StaticResource A_Style_ListBoxItem_ColorItem}" />
                <Setter Property="EmptyItemStyle" Value="{StaticResource A_Style_ListBoxItem_Color_Empty}" />
                <Setter Property="Width" Value="640" />
                <Setter Property="ItemWidth" Value="320" />
                <Setter Property="ItemHeight" Value="56" />
            </Style>

            <Style x:Key="A_Style_NetworkCountdownControl_PickColorCustom"
                   TargetType="{x:Type local:NetworkCountdownControl}"
                   BasedOn="{StaticResource A_Style_NetworkCountdownControl_Base}">
                <Setter Property="TimerDisplayName" Value="{local:Loc Lobby.IDS_SelectYourCar_Countdown}" />
            </Style>
        </ResourceDictionary>
    </Page.Resources>

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

    <Grid>
        <!-- Background Blur -->
        <local:FZMaterialGlassCapture />
        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"
                          MinWidth="{Binding ActualWidth, ElementName=MainContent}"
                          MinHeight="{Binding ActualHeight, ElementName=MainContent}"/>
        <!-- Help Panel -->
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                          Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_PickColorCustom}"
                                       AudioEnabled="True"
                                       WarningSeconds="0" />

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}"
              Focusable="False">
            <StackPanel x:Name="MainContent"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Width="636"
                    Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                <ContentControl Content="{Loc ScreenTitles.IDS_VehicleColour}"
                                Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"
                                Width="636"/>
                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}">
                    <local:FZTextBlock Text="{Loc HideSeek.IDS_VehicleColourPopup_Desc}"
                                       Style="{StaticResource A_Style_FZTextBlock_PopupText}"/>
                </ContentControl>
                <local:WrapListBox x:Name="ColorPicks"
                                   Style="{StaticResource H_Style_ColorsCollection}"
                                   ItemTemplate="{StaticResource A_ControlTemplate_LargeColorItem}"
                                   ItemsSource="{Binding ColorsCollection}" 
                                   SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                   Focusable="False"
                                   FocusOnPageFocusGained.SelectorSelectedItem="True"
                                   SelectedIndex="0"
                                   MultiDataConversion.Converter="{MathOperationConverter Operation=Divide}"
                                   MultiDataConversion.TargetType="{Type Double}"
                                   MultiDataConversion.Value="{Binding ColorsCollection.Count}"
                                   MultiDataConversion.Parameter="{StaticResource A_Double_Carousel_ItemsPerRow}"
                                   Height="{Binding (MultiDataConversion.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_LinearTransformConverter_RowsToHeight}}"
                                   ScrollOrientation="Vertical"
                                   Margin="-4,0,0,0"/>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
