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

    <Page.Resources>
        <ResourceDictionary>

            <local:MappingConverter x:Key="A_Converter_MapFilterCategoryToIcon"
                                    Default="all">
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.All}" Value="all" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.New}" Value="new" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.SeasonEvents}" Value="seasonevents" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.SeasonPRStunts}" Value="seasonprstunts" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.AsphaltSeries}" Value="asphaltseries" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.MixedSurfaceSeries}" Value="mixedsurfaceseries" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.CrossCountrySeries}" Value="crosscountryseries" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.StreetRacing}" Value="streetracing" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.DragStrip}" Value="dragstrip" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.ShowcaseEvents}" Value="showcaseevents" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.PlaygroundGames}" Value="playgroundgames" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.SpeedTraps}" Value="speedtraps" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.SpeedZones}" Value="speedzones" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.DangerSigns}" Value="dangersigns" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.DriftZones}" Value="driftzones" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.Trailblazer}" Value="trailblazer" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.TreasureHunt}" Value="treasurehunt" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.RewardBoards}" Value="rewardboards" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.ConditionalCollectables}" Value="conditionalcollectables" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.BarnFinds}" Value="barnfinds" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.HorizonStories}" Value="horizonstories" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.FestivalSites}" Value="festivalsites" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.PlayerHouses}" Value="playerhouses" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.BeautySpots}" Value="beautyspots" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.CommunityChallenges}" Value="communitychallenges" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.OnlineFriends}" Value="onlinefriends" />
                <local:MappingConverterEntry Key="{x:Static local:XAMLMapFilterCategory.AllOnlinePlayers}" Value="allonlineplayers" />
            </local:MappingConverter>

            <Style x:Key="A_Style_FZMaterial_FilterIcon"
                   TargetType="local:FZMaterial">
                <Setter Property="local:MultiStringFormatter.Format" Value="{0}{1}.png" />
                <Setter Property="ImageSource" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}" />
                <Setter Property="Visibility" Value="Collapsed" />
                <Setter Property="Width" Value="42" />
                <Setter Property="Height" Value="42" />
                <Setter Property="Margin" Value="8,3,3,3" />
                <Setter Property="Color" Value="#FFFFFF" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding CategoryIconSet, RelativeSource={RelativeSource AncestorType=Page}}"
                                 Value="map">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding ActiveTrack, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_ActiveTrackToMapFilterIconLocation}}" />
                        <Setter Property="local:MultiStringFormatter.Param1"
                                Value="{Binding Category, Converter={StaticResource A_Converter_MapFilterCategoryToIcon}}" />
                        <Setter Property="Visibility"
                                Value="Visible" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Category}"
                                       Value="{x:Static local:XAMLMapFilterCategory.All}" />
                            <Condition Binding="{Binding CategoryIconSet, RelativeSource={RelativeSource AncestorType=Page}}"
                                       Value="map" />
                            <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                       Value="False" />
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Color" Value="{StaticResource A_Color_Tile_FloatingIcon_Background}" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_ListBoxItem_CarFilterItem" BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_Default}" TargetType="ListBoxItem">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsToggle}" Value="False">
                        <Setter Property="Focusable"
                                Value="False" />
                        <Setter Property="Tag"
                                Value="GroupHeader" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <System:Double x:Key="A_Double_TextMenu_Height_Large">68</System:Double>

            <local:MappingConverter x:Key="A_Converter_CategoryIconSetToListBoxItemHeight"
                                    Default="{StaticResource A_Double_TextMenu_Height_Large}">
                <local:MappingConverterEntry Key="" Value="{StaticResource A_Double_TextMenu_Height_Default}" />
            </local:MappingConverter>

            <System:Double x:Key="A_Double_ListBox_Height_Normal">663</System:Double>
            <System:Double x:Key="A_Double_ListBox_Height_Large">710</System:Double>

            <local:MappingConverter x:Key="A_Converter_CategoryIconSetToListBoxMaxHeight"
                                    Default="{StaticResource A_Double_ListBox_Height_Large}">
                <local:MappingConverterEntry Key="" Value="{StaticResource A_Double_ListBox_Height_Normal}" />
            </local:MappingConverter>

            <System:Double x:Key="A_Double_ListBox_Width_Normal">552</System:Double>
            <System:Double x:Key="A_Double_ListBox_Width_Large">642</System:Double>

            <local:MappingConverter x:Key="A_Converter_CategoryIconSetToListBoxWidth"
                                    Default="{StaticResource A_Double_ListBox_Width_Large}">
                <local:MappingConverterEntry Key="" Value="{StaticResource A_Double_ListBox_Width_Normal}" />
            </local:MappingConverter>

            <DataTemplate x:Key="A_DataTemplate_ListBoxItem_CarFilterItem">
                <Grid IsHitTestVisible="False"
                      Height="{Binding CategoryIconSet, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_CategoryIconSetToListBoxItemHeight}}">
                    <DockPanel HorizontalAlignment="Left">
                        <local:FZMaterial DockPanel.Dock="Left"
                                          Style="{StaticResource A_Style_FZMaterial_FilterIcon}" />
                        <local:FZTextBlock x:Name="Text" DockPanel.Dock="Right" Text="{Binding Text, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_OptionText}" />
                    </DockPanel>
                    <StackPanel HorizontalAlignment="Right" Visibility="{Binding IsToggle, Converter={StaticResource A_Converter_BoolToVis}}" Orientation="Horizontal">
                        <Control x:Name="CheckBox" VerticalAlignment="Center" Style="{StaticResource A_Style_Control_Checkbox}" Tag="{Binding Value}" />
                    </StackPanel>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Focusable, RelativeSource={RelativeSource TemplatedParent}}"
                             Value="False">
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsToggle}"
                             Value="False">
                        <Setter TargetName="Text"
                                Property="TextAlignment"
                                Value="Center" />
                        <Setter TargetName="Text"
                                Property="FontFamily"
                                Value="Horizon_C" />
                        <Setter TargetName="Text"
                                Property="Color"
                                Value="{StaticResource A_Color_TextMenu_Text_Highlighted}" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <ControlTemplate TargetType="{x:Type ListBox}"
                  x:Key="A_Template_ListBox_FilterPopup">
                <Border Background="{x:Null}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ValidationStates">
                            <VisualState x:Name="Valid" />
                            <VisualState x:Name="InvalidFocused" />
                            <VisualState x:Name="InvalidUnfocused" />
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <local:FZScrollViewer Template="{StaticResource A_ControlTemplate_ScrollViewer_Popup_ExternalRightPosition}"
                                          CanContentScroll="True"
                                          Margin="-18,0"
                                          HorizontalScrollBarVisibility="Disabled"
                                          VerticalScrollBarVisibility="{Binding Path=(ScrollViewer.VerticalScrollBarVisibility), RelativeSource={RelativeSource TemplatedParent}}"
                                          local:FZScrollViewer.IsAtTop="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:FZScrollViewer.IsAtTop), Mode=OneWayToSource}"
                                          local:FZScrollViewer.IsAtBottom="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:FZScrollViewer.IsAtBottom), Mode=OneWayToSource}"
                                          Focusable="False"
                                          KeepSelectionOnScreen="True">
                        <VirtualizingStackPanel Orientation="Vertical"
                                                Margin="18,0"
                                                IsItemsHost="True"
                                                VirtualizingStackPanel.VirtualizationMode="Recycling"
                                                Focusable="False" />
                    </local:FZScrollViewer>
                </Border>
            </ControlTemplate>
        </ResourceDictionary>
    </Page.Resources>

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

    <Grid>
        <Grid>
          <local:FZMaterialGlassCapture />
          <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}" 
                            MinWidth="{Binding ActualWidth, ElementName=MainContent}"
                            MinHeight="{Binding ActualHeight, ElementName=MainContent}" />

            <ContentControl x:Name="BottomBar"
                            Style="{StaticResource A_Style_ButtonBar}">
                <ContentControl x:Name="DefaultHelpPanel"
                                local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Toggle}"
                                local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                                local:ControllerButtonPanel.XDescription="{local:Loc HelpButtons.IDS_ClearAll}"
                                Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>
        </Grid>

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}"
              Focusable="False">
            <StackPanel x:Name="MainContent"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                
                <ContentControl Content="{Binding Title, Converter={StaticResource A_StringToUpper}}"
                        Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"/>

                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}"
                                Tag="/ForzaUI;component/Textures/Anthem/Icons/Titles/PopupSettings.png">
                    <local:CommonListBox x:Name="Menu"
                                         Style="{StaticResource A_Style_ListBox_TextMenu_Default}"
                                         ItemContainerStyle="{StaticResource A_Style_ListBoxItem_CarFilterItem}"
                                         ItemTemplate="{StaticResource A_DataTemplate_ListBoxItem_CarFilterItem}"
                                         ItemsSource="{Binding Collection}"
                                         Width="{Binding CategoryIconSet, Converter={StaticResource A_Converter_CategoryIconSetToListBoxWidth}}"
                                         MaxHeight="{Binding CategoryIconSet, Converter={StaticResource A_Converter_CategoryIconSetToListBoxMaxHeight}}"
                                         Template="{StaticResource A_Template_ListBox_FilterPopup}"
                                         SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
                    </local:CommonListBox>
                </ContentControl>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
