<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_QuickUpgradeSelect"
      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>

            <DataTemplate x:Key="A_DataTemplate_Carousel_QuickUpgradeSelectContent">
                <Grid>
                    <local:FZMaterial x:Name="Icon"
                                      Stretch="Uniform"
                                      Preset="{StaticResource H_Roundtangle_Outer_2px}"
                                      ImageSource="{Binding CarImagePath}">
                    </local:FZMaterial>
                </Grid>
            </DataTemplate>

        </ResourceDictionary>
    </Page.Resources>

    <Grid>
        <!-- Background Blur -->
        <Control Style="{StaticResource A_Style_Control_ScreenBackground}"
                 Visibility="{Binding MovingBackgrounds, FallbackValue=Collapsed, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}" />
        <!-- Bars -->
        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                        local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                        local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                        Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>


        <Border x:Name="PART_LayoutRoot" Style="{StaticResource A_Style_Border_ScenePadding_Opus}">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="VisualStateGroup">
                    <VisualState x:Name="PART_DefaultState"/>
                    <VisualState x:Name="PART_NoClassSelectState">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MainContent" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <Grid x:Name="MainContent" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                VerticalAlignment="Center"
                Margin="18,0"
                Height="{StaticResource H_Height_Upgrades}">
                <Grid.RowDefinitions>
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="*" />
                </Grid.RowDefinitions>

                <ContentControl x:Name="ContentControl_SceneTitle"
                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                    Content="{local:Loc MainMenu.IDS_Easy_Upgrade}"
                    HorizontalAlignment="Left"
                    Width="{StaticResource H_Width_Upgrades}"
                    Grid.Row="0" />

                <ContentControl x:Name="Description"
                    Template="{StaticResource A_ControlTemplate_SidePanel_UpgradeCost}"
                    DataContext="{Binding SelectedItem, ElementName=PART_UpgradesList}"
                    local:BindingProxy.A="{Binding ClassID, Converter={StaticResource A_CarClassConverter}, ConverterParameter=longname}"
                    HorizontalAlignment="Left"
                    Width="{StaticResource H_Width_Upgrades}"
                    Grid.Row="2">
                    <Decorator ClipToBounds="True" Margin="24" Height="212">
                        <FZTextBlock Style="{StaticResource H_Style_Text_Description_Body_16px_Scrolling}"
                            Text="{Binding Description}"
                            CapHeight="14"
                            VerticalAlignment="Top"
                            TextAlignment="Left"
                            Margin="0,4"
                            AutoScroll="{StaticResource H_AutoScrollSettings_Descriptions}"
                            AutoScroll.AllowScrolling="True" />
                        </Decorator>
                </ContentControl>

                <DockPanel Margin="0,0,0,4"
                    HorizontalAlignment="Left"
                    Grid.Row="1">
                    <ScrollBar
                        Style="{StaticResource H_Style_ScrollBar}"
                        Margin="8,0,0,0"
                        Minimum="{Binding ScrollWindowMin, ElementName=PART_UpgradesList}"
                        Maximum="{Binding ScrollWindowMax, ElementName=PART_UpgradesList}"
                        Value="{Binding ScrollWindowValue, ElementName=PART_UpgradesList, Mode=TwoWay}"
                        ViewportSize="{Binding ScrollWindowSize, ElementName=PART_UpgradesList}"
                        DockPanel.Dock="Right">
                        <DynamicData.Data>
                            <DynamicDataItem
                                Name="ScrollBarHideWhenNotNeeded"
                                DataType="Boolean"
                                Value="True" />
                        </DynamicData.Data>
                    </ScrollBar>
                    <WrapListBox
                        x:Name="PART_UpgradesList"
                        Style="{StaticResource H_Style_UpgradeGrid_Square_3x3}"
                        ScrollOrientation="Vertical"
                        ItemsSource="{Binding Collection}"
                        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                        ItemTemplate="{StaticResource A_DataTemplate_Carousel_QuickUpgradeSelectContent}" />
                </DockPanel>
            </Grid>
        </Border>
    </Grid>
</Page>