<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:vwp="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
                    xmlns:vm="clr-namespace:FModel.ViewModels"
                    xmlns:controls="clr-namespace:FModel.Views.Resources.Controls"
                    xmlns:tiledExplorer="clr-namespace:FModel.Views.Resources.Controls.TiledExplorer"
                    xmlns:listExplorer="clr-namespace:FModel.Views.Resources.Controls.ListExplorer"
                    xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
                    xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
                    xmlns:adonisConverters="clr-namespace:AdonisUI.Converters;assembly=AdonisUI"
                    x:Class="FModel.Views.Resources.Controls.TiledExplorer.ResourcesDictionary">
    <controls:TypeDataTemplateSelector x:Key="TiledExplorerTemplateSelector"
                                       FolderTemplateKey="TiledFolderDataTemplate"
                                       FileTemplateKey="TiledFileDataTemplate" />
    <controls:TypeDataTemplateSelector x:Key="ListExplorerTemplateSelector"
                                       FolderTemplateKey="ListFolderDataTemplate"
                                       FileTemplateKey="ListFileDataTemplate" />

    <Style x:Key="TiledExplorer" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="tiledExplorer:SmoothScroll.IsEnabled" Value="True" />
        <Setter Property="tiledExplorer:SmoothScroll.Factor" Value="1.25" />
        <Setter Property="SelectionMode" Value="Extended" />
        <Setter Property="ContextMenu" Value="{StaticResource FileContextMenu}" />
        <Setter Property="VirtualizingPanel.IsVirtualizing" Value="True" />
        <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="True" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="BorderThickness" Value="0" />

        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=OneWay}" />
                    <Setter Property="Margin" Value="5" />
                    <Setter Property="Padding" Value="5" />
                    <Setter Property="BorderThickness" Value="1.5" />
                    <Setter Property="Cursor" Value="Hand" />
                    <Setter Property="controls:ListBoxItemBehavior.IsBroughtIntoViewWhenSelected" Value="True" />
                    <Setter Property="Background" Value="{DynamicResource {x:Static adonisUi:Brushes.Layer0BackgroundBrush}}" />

                    <EventSetter Event="MouseDoubleClick" Handler="OnMouseDoubleClick" />
                    <EventSetter Event="PreviewMouseRightButtonDown" Handler="OnPreviewMouseRightButtonDown" />

                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Grid>
                                    <Border x:Name="Border"
                                            Background="{TemplateBinding Background}"
                                            BorderBrush="{TemplateBinding BorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            CornerRadius="{TemplateBinding adonisExtensions:CornerRadiusExtension.CornerRadius}">
                                        <ContentPresenter />
                                    </Border>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>

        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <vwp:VirtualizingWrapPanel Orientation="Horizontal" SpacingMode="Uniform" ScrollUnit="Pixel" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <ContentControl Content="{Binding}"
                                    ContentTemplateSelector="{StaticResource TiledExplorerTemplateSelector}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Grid>
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ScrollViewer Focusable="False"
                                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding ItemsSource, RelativeSource={RelativeSource Self}, Converter={x:Static adonisConverters:IsNullToBoolConverter.Instance}}" Value="False" />
                    <Condition Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}, FallbackValue=0}" Value="0" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <TextBlock Text="No folders or packages found" FontWeight="SemiBold" TextAlignment="Center"
                                           Foreground="{DynamicResource {x:Static adonisUi:Brushes.ErrorBrush}}" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>

    <GridLength x:Key="ExplorerNameColumn">3*</GridLength>
    <GridLength x:Key="ExplorerTypeColumn">1*</GridLength>
    <GridLength x:Key="ExplorerDetailsColumn">1.2*</GridLength>

    <Style x:Key="ListExplorer"
           TargetType="ListBox"
           BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="tiledExplorer:SmoothScroll.IsEnabled"
                Value="True" />
        <Setter Property="tiledExplorer:SmoothScroll.Factor"
                Value="0.1" />
        <Setter Property="SelectionMode"
                Value="Extended" />
        <Setter Property="ContextMenu"
                Value="{StaticResource FileContextMenu}" />
        <Setter Property="VirtualizingPanel.IsVirtualizing"
                Value="True" />
        <Setter Property="VirtualizingPanel.VirtualizationMode"
                Value="Recycling" />
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="True" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Visible" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Disabled" />
        <Setter Property="BorderThickness"
                Value="0" />
        <Setter Property="Margin"
                Value="0 4 0 0" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}"
                       BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <Setter Property="IsSelected"
                            Value="{Binding IsSelected, Mode=OneWay}" />
                    <Setter Property="HorizontalContentAlignment"
                            Value="Stretch" />
                    <Setter Property="Padding"
                            Value="0" />
                    <Setter Property="Margin"
                            Value="0" />
                    <Setter Property="Cursor"
                            Value="Hand" />
                    <Setter Property="controls:ListBoxItemBehavior.IsBroughtIntoViewWhenSelected"
                            Value="True" />
                    <EventSetter Event="MouseDoubleClick"
                                 Handler="OnMouseDoubleClick" />
                    <EventSetter Event="PreviewMouseRightButtonDown"
                                 Handler="OnPreviewMouseRightButtonDown" />
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <ContentControl Content="{Binding}"
                                    ContentTemplateSelector="{StaticResource ListExplorerTemplateSelector}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <ScrollViewer Focusable="False"
                                  VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                  HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}">
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate x:Key="TiledFileDataTemplate" DataType="{x:Type vm:GameFileViewModel}">
        <tiledExplorer:FileButton />
    </DataTemplate>

    <DataTemplate x:Key="TiledFolderDataTemplate" DataType="{x:Type vm:TreeItem}">
        <tiledExplorer:FolderButton ContextMenu="{StaticResource FolderContextMenu}" />
    </DataTemplate>

    <DataTemplate x:Key="ListFileDataTemplate"
                  DataType="{x:Type vm:GameFileViewModel}">
        <listExplorer:FileRow />
    </DataTemplate>

    <DataTemplate x:Key="ListFolderDataTemplate"
                  DataType="{x:Type vm:TreeItem}">
        <listExplorer:FolderRow ContextMenu="{StaticResource FolderContextMenu}" />
    </DataTemplate>

    <DataTemplate x:Key="TextureNumTemplate">
        <Border VerticalAlignment="Top"
                HorizontalAlignment="Right"
                Margin="4"
                Padding="6,2"
                CornerRadius="3"
                Opacity="0.85"
                Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding}"
                           Foreground="White"
                           FontSize="11"
                           FontWeight="SemiBold"
                           VerticalAlignment="Center"
                           Margin="0,0,5,0" />
                <Path Data="{StaticResource TextureIcon}"
                      Fill="White"
                      Width="12"
                      Height="12"
                      Stretch="Uniform"
                      VerticalAlignment="Center" />
            </StackPanel>
        </Border>
    </DataTemplate>

    <Style x:Key="AssetsListBox"
           TargetType="ListBox"
           BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="ItemsSource"
                Value="{Binding SelectedItem.AssetsList.AssetsView, ElementName=AssetsFolderName, IsAsync=True}" />
        <Setter Property="SelectionMode"
                Value="Extended" />
        <Setter Property="ContextMenu"
                Value="{StaticResource FileContextMenu}" />
        <Setter Property="VirtualizingPanel.IsVirtualizing"
                Value="True" />
        <Setter Property="VirtualizingPanel.VirtualizationMode"
                Value="Recycling" />
        <Setter Property="adonisExtensions:ScrollViewerExtension.VerticalScrollBarExpansionMode"
                Value="NeverExpand" />
        <Setter Property="adonisExtensions:ScrollViewerExtension.VerticalScrollBarPlacement"
                Value="Docked" />
        <Setter Property="adonisExtensions:ScrollViewerExtension.HorizontalScrollBarExpansionMode"
                Value="NeverExpand" />
        <Setter Property="adonisExtensions:ScrollViewerExtension.HorizontalScrollBarPlacement"
                Value="Docked" />
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Image x:Name="ListImage"
                               Source="/FModel;component/Resources/unknown_asset.png"
                               Width="16"
                               Height="16"
                               HorizontalAlignment="Center"
                               Margin="0 0 3 0" />
                        <TextBlock Grid.Column="1"
                                   HorizontalAlignment="Left"
                                   Text="{Binding Asset.Name}" />
                    </Grid>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Asset.Extension}"
                                     Value="uasset">
                            <Setter TargetName="ListImage"
                                    Property="Source"
                                    Value="/FModel;component/Resources/asset.png" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Asset.Extension}"
                                     Value="ini">
                            <Setter TargetName="ListImage"
                                    Property="Source"
                                    Value="/FModel;component/Resources/asset_ini.png" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Asset.Extension}"
                                     Value="png">
                            <Setter TargetName="ListImage"
                                    Property="Source"
                                    Value="/FModel;component/Resources/asset_png.png" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Asset.Extension}"
                                     Value="psd">
                            <Setter TargetName="ListImage"
                                    Property="Source"
                                    Value="/FModel;component/Resources/asset_psd.png" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}"
                       BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <Setter Property="HorizontalContentAlignment"
                            Value="Stretch" />
                    <Setter Property="Padding"
                            Value="5 3" />
                    <Setter Property="IsSelected"
                            Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="controls:ListBoxItemBehavior.IsBroughtIntoViewWhenSelected"
                            Value="True" />

                    <EventSetter Event="PreviewMouseRightButtonDown"
                                 Handler="OnPreviewMouseRightButtonDown" />
                </Style>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}, FallbackValue=0}"
                         Value="0">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <TextBlock Text="No packages found in folder"
                                           FontWeight="SemiBold"
                                           TextAlignment="Center"
                                           Foreground="{DynamicResource {x:Static adonisUi:Brushes.ErrorBrush}}" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>
