<Page x:Name="Page"
    x:Class="ForzaUI.A_LiveryLayerSelect"
    xmlns:local="clr-namespace:ForzaUI"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:x="http://schemas.microsoft.com/winfx/2006/xaml"
    mc:Ignorable="d"
    Style="{StaticResource A_Style_Page_Generic}"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
    
    <Page.Resources>
        <ResourceDictionary>
            <System:Double x:Key="A_Double_ZOffset_Selected">-5</System:Double>
            <System:Double x:Key="A_Double_Layer_Size">216</System:Double>
            <System:Double x:Key="A_Double_LiveryImageSize">150</System:Double>

            <Color x:Key="A_Color_LayerNumberText">#FF444444</Color>
            <Color x:Key="A_Color_Text_CurrentLayers">#FF00B592</Color>
            <Color x:Key="A_Color_Text_MaxLayers">#FF969696</Color>
            <Color x:Key="A_Color_Livery_IconBackground">#FF00B592</Color>

            <Style x:Key="A_Style_FZMaterial_FlatPanel_IconBackground"
           TargetType="{x:Type local:FZMaterial}"
           BasedOn="{StaticResource A_Style_FZMaterial_FlatPanel_Tile}">
                <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"/>
                <Setter Property="Color" Value="{StaticResource A_Color_Livery_IconBackground}"/>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_Layer">
                <Grid x:Name="Grid_Container">
                    <Grid RenderTransformOrigin="0.5,0.5" local:ZPanel.ZOffset="0">
                        <Grid Visibility="{Binding IsCreateNew, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                            <local:FZMaterial x:Name="Checkerboard" ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Checkerboard.png" Opacity="0.15" Color="Black" Style="{StaticResource A_Style_FZMaterial_FlatPanel_Tile}"/>
                        </Grid>

                        <Grid Visibility="{Binding IsLayer, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <local:FZMaterial x:Name="FzMaterial_LiveryShape"
                                          Margin="24">
                                <local:FZMaterial.Effect>
                                    <local:LinearToSRGBEffect>
                                        <local:LinearToSRGBEffect.Input>
                                            <ImageBrush ImageSource="{Binding LiveryImage}"/>
                                        </local:LinearToSRGBEffect.Input>
                                    </local:LinearToSRGBEffect>
                                </local:FZMaterial.Effect>
                            </local:FZMaterial>

                            <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
                                <local:FZMaterial Margin="4,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"  Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}" Visibility="{Binding IsGroup, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                    <local:FZMaterial Width="32" Height="32"
                                                    ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Layer_Grouped_Icon.png"/>
                                </local:FZMaterial>
                                <local:FZTextBlock  Margin="4,0,0,0" Text="{Binding LayerCount}"
                                                   Color="{StaticResource A_Color_LayerNumberText}"
                                                   Style="{StaticResource A_Style_FZTextBlock_Heading_Minimum}"
                                                   TextWrapping="NoWrap" />
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                                <local:FZMaterial Margin="0,0,4,4" Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}" Visibility="{Binding IsMask, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                    <local:FZMaterial Width="32" Height="32"
                                                      ImageSource="game:\media\ui\textures\data_bound\series8\paintshop\layer_mask_icon.png" />
                                </local:FZMaterial>

                                <local:FZMaterial Margin="0,0,4,4" Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}" Visibility="{Binding IsLocked, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                    <local:FZMaterial Width="32" Height="32" ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Lock.png" />
                                </local:FZMaterial>
                            </StackPanel>

                            <Path x:Name="Path_Selected" HorizontalAlignment="Right" Data="M0,0 l25,0 0,25 z" 
                                Visibility="{Binding IsMultiSelected, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                <Path.Fill>
                                    <SolidColorBrush Color="{StaticResource A_Color_Tile_Selected}" />
                                </Path.Fill>
                            </Path>
                        </Grid>
                        <Grid Visibility="{Binding IsCreateNew, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <local:FZMaterial Width="{StaticResource A_Double_LiveryImageSize}" Height="{StaticResource A_Double_LiveryImageSize}" 
                                                ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Layer_Select_Add_Icon.png" />
                        </Grid>
                    </Grid>
                </Grid>
            </DataTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_ClipboardItem">
                <Grid Height="193" Width="193">
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_GlassPanel_NonInteractive}"  Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll}"/>

                    <local:FZMaterial x:Name="Checkerboard"
                                      ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Checkerboard.png"
                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                      Opacity="0.2" />

                    <local:FZMaterial x:Name="FzMaterial_LiveryShape" Margin="30">
                        <local:FZMaterial.Effect>
                            <local:LinearToSRGBEffect>
                                <local:LinearToSRGBEffect.Input>
                                    <ImageBrush ImageSource="{Binding LiveryImage}"/>
                                </local:LinearToSRGBEffect.Input>
                            </local:LinearToSRGBEffect>
                        </local:FZMaterial.Effect>
                    </local:FZMaterial>

                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,4">
                        <local:FZMaterial Margin="0,0,4,0" Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}">
                            <local:FZMaterial Width="32" Height="32" ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Lock.png"
                                                    Visibility="{Binding IsLocked, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                        </local:FZMaterial>
                        <local:FZMaterial Margin="0,0,4,0"  Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}">
                            <local:FZMaterial Width="32" Height="32"
                                                    ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/Layer_Grouped_Icon.png"
                                                    Visibility="{Binding IsGroup, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                        </local:FZMaterial>
                        <local:FZMaterial Margin="0,0,4,0" Style="{StaticResource A_Style_FZMaterial_FlatPanel_IconBackground}" Visibility="{Binding IsMask, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <local:FZMaterial Width="32" Height="32"
                                              ImageSource="game:\media\ui\textures\data_bound\series8\paintshop\layer_mask_icon.png" />
                        </local:FZMaterial>
                    </StackPanel>
                </Grid>
            </ControlTemplate>

            <Style x:Key="A_Style_FZTextBlock_LayerCount" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_HeaderBlock}">
                <Setter Property="Color" Value="{StaticResource A_Color_Text_CurrentLayers}" />
                <Setter Property="Margin" Value="0" />
                <Setter Property="CapHeight" Value="32"/>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_LayerMaxCount" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_LayerCount}">
                <Setter Property="Color" Value="{StaticResource A_Color_Text_MaxLayers}" />
            </Style>

        </ResourceDictionary>
    </Page.Resources>

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

    <Grid>
        <local:RoutedEventCommand x:Name="ClearMultiSelectStateRoutedEventCommandUp"
                                  RoutedEvent="UIElement.MouseLeftButtonUp"
                                  Command="{Binding ClearMultiSelectState, RelativeSource={RelativeSource AncestorType=Page}}" />
        <local:RoutedEventCommand x:Name="ClearMultiSelectStateRoutedEventCommandLeave"
                                  RoutedEvent="UIElement.MouseLeave"
                                  Command="{Binding ClearMultiSelectState, RelativeSource={RelativeSource AncestorType=Page}}" />
        <local:RoutedEventCommand x:Name="StartMultiSelectRoutedEventCommand"
                                  RoutedEvent="UIElement.MouseLeftButtonDown"
                                  Command="{Binding StartMultiSelect, RelativeSource={RelativeSource AncestorType=Page}}" />
        <local:FZMaterialGlassCapture />

        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <local:ControllerButtonPanel x:Name="HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_OK}" />
                <local:ControllerButtonControl Button="B"
                                               Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="X"
                                               Description="{local:Loc HelpButtons.IDS_Cut}" />
                <local:ControllerButtonControl Button="Y"
                                               Description="{local:Loc HelpButtons.IDS_Insert}" />
                <local:ControllerButtonControl Button="R3"
                                               Description="{local:Loc HelpButtons.IDS_ToggleBackground}" />
                <local:ControllerButtonControl Button="RTrigger"
                                               Description="{local:Loc HelpButtons.IDS_ToggleLayerSel}"
                                               Style="{StaticResource A_Style_ControllerButtonControl_Default_ShowAlways}"
                                               local:RoutedEventCommand.Action3="{Binding ElementName=StartMultiSelectRoutedEventCommand}"
                                               local:RoutedEventCommand.Action="{Binding ElementName=ClearMultiSelectStateRoutedEventCommandUp}"
                                               local:RoutedEventCommand.Action2="{Binding ElementName=ClearMultiSelectStateRoutedEventCommandLeave}" />
                <local:ControllerButtonControl Button="Back"
                                               Description="{local:Loc HelpButtons.IDS_Save}" />
                <local:ControllerButtonControl Button="DPadVertical"
                                               Description="{local:Loc HelpButtons.IDS_Skip}"
                                               Visibility="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border x:Name="LayoutRoot" Style="{StaticResource A_Style_Border_ScenePadding_Opus_BottomAnchor}" >
            <Grid>
                <!--<StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" HorizontalAlignment="Left">
                    <ContentControl Content="{local:Loc Livery.IDS_LayerSelectTitle}"
                                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}" 
                                    Focusable="False" Tag="{local:Loc ScreenTitles.IDS_LiveryEditor}"
                                    local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Layers.png" />
                </StackPanel-->

                <StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
                    <Grid x:Name="Grid_Clipboard" Margin="0,0,15,20" HorizontalAlignment="Right" VerticalAlignment="Bottom" DataContext="{Binding LiveryClipboard}"
                            Visibility="{Binding IsVisible, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                            Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_1}">
                        <Control x:Name="ClipboardElement" Template="{StaticResource A_ControlTemplate_ClipboardItem}"/>
                    </Grid>
                
                    <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_1}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MaxWidth="1403"/>
                            <ColumnDefinition Width="14"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Grid x:Name="PART_CategoryRibbon" VerticalAlignment="Bottom" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_1}"
                            Margin="15,0,0,0"
                            Visibility="{Binding IsMultiSection, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <Viewbox MaxWidth="1450" Stretch="Fill" StretchDirection="DownOnly">
                                <local:ItemsSelector x:Name="PART_LayerSectionList"
                                                     Style="{StaticResource A_Style_TextTabMenuList}"
                                                     Focusable="False"
                                                     SelectedItem="{Binding SelectedSection, Mode=TwoWay}"  ItemsSource="{Binding MenuItems}" PageSize="1"/>
                            </Viewbox>
                        </Grid>

                        <DockPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="2"
                                            MinWidth="276" Height="66" Margin="0,0,15,0">

                            <local:FZMaterial x:Name="Icon" 
                                          Width="66" Height="66"
                                          DockPanel.Dock="Left" 
                                               Panel.ZIndex="10"
                                          Style="{StaticResource A_Style_FZMaterial_ScreenTitleBlockIcon}" 
                                          local:BindingProxy.B="{Binding (local:BindingProxy.B), RelativeSource={RelativeSource TemplatedParent}}">
                                <local:FZMaterial Height="66" Width="66"  ImageSource="/ForzaUI;component/Textures/Anthem/Paintshop/LayerCountIcon.png" />
                            </local:FZMaterial>

                            <local:FZMaterial x:Name="FZ_Material_Background" Style="{StaticResource A_Style_FZMaterial_ScreenTitleBlockBacking}">
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="20,0,20,0">
                                    <local:FZTextBlock Text="{Binding CurrentLayerCount}" Style="{StaticResource A_Style_FZTextBlock_LayerCount}" />
                                    <local:FZTextBlock Text="/" Style="{StaticResource A_Style_FZTextBlock_LayerMaxCount}" Margin="4,0,4,0" />
                                    <local:FZTextBlock Text="{Binding MaxLayerCount}" Style="{StaticResource A_Style_FZTextBlock_LayerMaxCount}" />
                                </StackPanel>
                            </local:FZMaterial>
                        </DockPanel> 
                    </Grid>

                    <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_2}" VerticalAlignment="Bottom"
                          HorizontalAlignment="Center"
                          KeyboardNavigation.DirectionalNavigation="Contained"
                          Width="{StaticResource A_Double_Carousel_Square_10Item_Total_Width}"
                          Margin="0,20">
                        <ContentControl Template="{StaticResource A_Template_ContentControl_SelectorContainer_PageButtons}">
                            <local:WrapListBox x:Name="PART_LayerItemList"
                                               Focusable="False"
                                               Style="{StaticResource A_Style_Carousel_Square_10Item}"
                                               ItemTemplate="{StaticResource A_DataTemplate_Layer}"
                                               SelectedIndex="0"
                                               ItemsSource="{Binding SelectedItem, ElementName=PART_LayerSectionList}"
                                               SelectedItem="{Binding SelectedItem.SelectedItem, ElementName=PART_LayerSectionList, Mode=TwoWay}"
                                               local:RoutedEventCommand.Action="{Binding ElementName=ButtonBarDisableMouseCursorMovement}"
                                               local:RoutedEventCommand.Action2="{Binding ElementName=ButtonBarEnableMouseCursorMovement}" />
                        </ContentControl>
                    </Grid>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
