<views:View x:TypeArguments="viewModels:ModListViewModel"
            xmlns="https://github.com/avaloniaui"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:models="clr-namespace:Lumafly.Models"
            xmlns:viewModels="clr-namespace:Lumafly.ViewModels"
            xmlns:views="clr-namespace:Lumafly.Views"
            xmlns:pages="clr-namespace:Lumafly.Views.Pages"
            xmlns:enums="clr-namespace:Lumafly.Enums"
            xmlns:utils="clr-namespace:Lumafly.Util"
            xmlns:customControls="clr-namespace:Lumafly.Views.Controls"
            xmlns:ext="clr-namespace:Lumafly.Extensions"
            xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
            xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
            mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="550"
            x:Class="Lumafly.Views.Pages.ModListView"
            x:DataType="viewModels:ModListViewModel"
            x:CompileBindings="True"
            Name="UserControl"
            KeyDown="OnKeyDown">
    <SplitView
        DisplayMode="CompactOverlay"
        OpenPaneLength="{Binding PaneWidth}"
        CompactPaneLength="35"
        PaneBackground="{DynamicResource RegionColor}"
        Background="{DynamicResource RegionColor}"
        IsPaneOpen="{Binding PaneOpen, Mode=TwoWay}"
        PanePlacement="Left">
        <!-- Sidebar -->
        <SplitView.Pane>
            <Border
                PointerEntered="OpenPane"
                PointerExited="ClosePane"
                Background="{DynamicResource BackgroundColor}"
                BorderBrush="#a9a9a9"
                BorderThickness="0 1 0 0">
                <StackPanel
                    Margin="2 0 0 4"
                    HorizontalAlignment="Stretch"
                    Orientation="Vertical"
                    VerticalAlignment="Bottom">
                    <StackPanel.Styles>
                        <Style Selector="Button">
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="BorderThickness" Value="0" />
                            <Setter Property="HorizontalAlignment" Value="Stretch" />
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                            <Setter Property="ToolTip.ShowDelay" Value="0" />
                            <Setter Property="Margin" Value=" 0 5 0 0" />
                        </Style>
                        <Style Selector="PathIcon">
                            <Setter Property="Height" Value="20" />
                            <Setter Property="Width" Value="20" />
                            <Setter Property="Margin" Value="2 0 20 0" />
                        </Style>
                        <Style Selector="StackPanel">
                            <Setter Property="Orientation" Value="Horizontal" />
                        </Style>
                    </StackPanel.Styles>
                    <Button
                        Command="{Binding UninstallAll}"
                        IsEnabled="{Binding CanUninstallAll}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource delete_regular}" />
                            <TextBlock Text="{ext:Localize XAML_Uninstall_All}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding ToggleAll}"
                        IsEnabled="{Binding CanToggleAll}">
                        <StackPanel ToolTip.Tip="{ext:Localize XAML_Toggle_All_Tooltip}" ToolTip.ShowDelay="0">
                            <PathIcon Data="{StaticResource toggle_right_regular}" />
                            <TextBlock Text="{ext:Localize XAML_Toggle_All}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding UpdateUnupdated}"
                        IsEnabled="{Binding CanUpdateAll}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource arrow_sync_regular}" />
                            <TextBlock Text="{ext:Localize XAML_ModsFilter_OutOfDate_Update}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding ToggleApi}">
                        <StackPanel ToolTip.Tip="{ext:Localize ToggleAPI_Explanation}" ToolTip.ShowDelay="0">
                            <PathIcon Data="{StaticResource options_regular}" />
                            <TextBlock Text="{Binding ApiButtonText}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding OpenSavesDirectory}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource folder_zip_regular}" />
                            <TextBlock Text="{ext:Localize XAML_SavesFolder}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding OpenModsDirectory}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource folder_regular}" />
                            <TextBlock Text="{ext:Localize XAML_OpenMods}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding OpenModlog}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource book_database_regular}" />
                            <TextBlock Text="{ext:Localize XAML_Modlog}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="{Binding ManuallyInstallMod}">
                        <StackPanel>
                            <PathIcon Data="{StaticResource arrow_download_regular}" />
                            <TextBlock Text="{ext:Localize XAML_Manual_Install}" />
                        </StackPanel>
                    </Button>
                </StackPanel>
            </Border>
        </SplitView.Pane>
    <DockPanel>
    
    <ProgressBar
        DockPanel.Dock="Bottom"

        MaxHeight="8"
        MinHeight="8"
            
        Margin="0 0 0 1"

        Name="Bar"

        IsVisible="{Binding ProgressBarVisible}"

        IsIndeterminate="{Binding ProgressBarIndeterminate}"

        Minimum="0"
        Maximum="100"
        Value="{Binding Progress}" />
    
    <Border
        BorderBrush="#a9a9a9"
        BorderThickness="0 0 0 1"
        DockPanel.Dock="Top">
        <DockPanel>
            <Menu 
                DockPanel.Dock="{Binding ModFilterDocking}" 
                HorizontalAlignment="Stretch">
                
                <Menu.Styles>
                    <Style Selector="MenuItem">
                        <Setter Property="Padding" Value="6 0" />
                    </Style>
                </Menu.Styles>

                <!-- The PointerPressed un highlights all the filter buttons except the one that's pressed
                    the name prefix "ModFilter_" helps find all buttons in code behind. The All button is 
                    highlighted by default on app open-->
                <MenuItem
                    IsEnabled="False"
                    Header="{ext:Localize XAML_FilterMods}" />

                <MenuItem
                    Name="ModFilter_All"
                    IsVisible="{Binding IsInOnlineMode}"
                    Header="{ext:Localize XAML_ModsFilter_All}"
                    Command="{Binding SelectModsWithFilter}"
                    CommandParameter="{x:Static enums:ModFilterState.All}" />

                <MenuItem
                    Name="ModFilter_Installed"
                    Header="{ext:Localize XAML_ModsFilter_Installed}"
                    Command="{Binding SelectModsWithFilter}"
                    CommandParameter="{x:Static enums:ModFilterState.Installed}" />

                <MenuItem
                    Name="ModFilter_Enabled"
                    Header="{ext:Localize XAML_ModsFilter_Enabled}"
                    Command="{Binding SelectModsWithFilter}"
                    CommandParameter="{x:Static enums:ModFilterState.Enabled}" />

                <MenuItem
                    Name="ModFilter_OutOfDate"
                    IsVisible="{Binding IsInOnlineMode}"
                    Header="{ext:Localize XAML_ModsFilter_OutOfDate}"
                    Command="{Binding SelectModsWithFilter}"
                    CommandParameter="{x:Static enums:ModFilterState.OutOfDate}" />

                <MenuItem
                    Name="ModFilter_WhatsNew"
                    IsVisible="{Binding ShouldShowWhatsNew}"
                    Header="{ext:Localize XAML_ModsFilter_WhatsNew}"
                    Command="{Binding SelectModsWithFilter}"
                    CommandParameter="{x:Static enums:ModFilterState.WhatsNew}" />
            </Menu>
            <StackPanel>
                <Border
                    BorderBrush="#a9a9a9"
                    BorderThickness="0 1 0 0">
                    <Grid
                        ColumnDefinitions="Auto Auto Auto"
                        RowDefinitions="Auto Auto"
                        IsVisible="{Binding IsInWhatsNew}">
                        <Grid.Styles>
                            <Style Selector="CheckBox, RadioButton">
                                <Setter Property="Margin" Value="10 0 0 0"/>
                                <Setter Property="HorizontalAlignment" Value="Left" />
                                <Setter Property="VerticalAlignment" Value="Center" />
                            </Style>
                            <Style Selector="TextBlock">
                                <Setter Property="Foreground" Value="{DynamicResource DisabledColor}"/>
                                <Setter Property="Margin" Value="6 0 0 0"/>
                                <Setter Property="IsEnabled" Value="False" />
                                <Setter Property="VerticalAlignment" Value="Center" />
                            </Style>
                        </Grid.Styles>
                        <Grid.Resources>
                            <utils:HowRecentEnumToBoolConvertor x:Key="HowRecentEnumConvertor" />
                        </Grid.Resources>
                        <TextBlock
                            Grid.Column="0" Grid.Row="0"
                            Text="How Recent:"/>
                        <RadioButton
                            Grid.Column="1" Grid.Row="0"
                            IsChecked="{Binding HowRecentModChanged, 
                            Converter={StaticResource HowRecentEnumConvertor},
                            ConverterParameter={x:Static enums:HowRecentModChanged.Week}}"
                            GroupName="Recent"
                            Content="{ext:Localize XAML_LastWeek}" />
                        <RadioButton
                            Grid.Column="2" Grid.Row="0"
                            IsChecked="{Binding HowRecentModChanged, 
                            Converter={StaticResource HowRecentEnumConvertor},
                            ConverterParameter={x:Static enums:HowRecentModChanged.Month}}"
                            GroupName="Recent"
                            Content="{ext:Localize XAML_LastMonth}" />
                        <TextBlock
                            Grid.Column="0" Grid.Row="1"
                            Text="Recent Type:"/>
                        <CheckBox
                            Grid.Column="1" Grid.Row="1"
                            IsChecked="{Binding WhatsNew_NewMods}"
                            Content="{ext:Localize XAML_NewMods}" />
                        <CheckBox
                            Grid.Column="2" Grid.Row="1"
                            IsChecked="{Binding WhatsNew_UpdatedMods}"
                            Content="{ext:Localize XAML_UpdatedMods}" />
                    </Grid>
                </Border>
                <Grid
                    IsVisible="{Binding !IsInWhatsNew}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" MinWidth="400" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" MinWidth="75" />
                    </Grid.ColumnDefinitions>

                    <TextBox
                        Grid.Column="0"
                        x:Name="Search"
                        Name="Search"
                        IsVisible="{ReflectionBinding $parent[pages:ModListView].DataContext.IsNormalSearch}"
                        PlaceholderText="{ext:Localize XAML_SearchMark}"
                        BorderThickness="0"
                        Margin="6 6"
                        Text="{Binding Search}" />

                    <AutoCompleteBox
                        Grid.Column="0"
                        IsVisible="{ReflectionBinding $parent[pages:ModListView].DataContext.IsDependencyAndIntegrationSearch}"
                        BorderThickness="0"
                        Margin="6 6"
                        SelectedItem="{Binding DependencySearchItem}"
                        ItemsSource="{Binding ModNames}" />

                    <AutoCompleteBox
                        Grid.Column="0"
                        IsVisible="{ReflectionBinding $parent[pages:ModListView].DataContext.IsIntegrationSearch}"
                        BorderThickness="0"
                        Margin="6 6"
                        SelectedItem="{Binding DependencySearchItem}"
                        ItemsSource="{Binding ModNames}" />

                    <Button
                        Grid.Column="1"
                        Background="Transparent"
                        HorizontalAlignment="Right"
                        BorderThickness="0"
                        IsVisible="{Binding ClearSearchVisible}"
                        Command="{Binding ClearSearch}"
                        Margin="0 0 0 0">
                        <PathIcon
                            Data="{StaticResource presence_offline_regular}"
                            Width="15" Height="15" />
                    </Button>

                    <customControls:TextButtonFlyout
                        FlyoutPlacement="BottomEdgeAlignedRight"
                        FlyoutShowMode="Transient"
                        Padding="6 0 0 0"
                        Margin="0 0 5 0"
                        Header="{ext:Localize XAML_Search_Options}"
                        Background="{DynamicResource RegionColor}"
                        OnHoverColor="{DynamicResource DefaultButtonColor}"
                        Grid.Column="2">

                        <pages:SearchOptionsMenu />
                        
                    </customControls:TextButtonFlyout>
                </Grid>
            </StackPanel>
        </DockPanel>
    </Border>
    
    <TextBlock
        DockPanel.Dock="Top"
        Margin="0 -25 10 0"
        VerticalAlignment="Top"
        HorizontalAlignment="Right"
        Text="{Binding NumberOfResults}"
        Foreground="{DynamicResource DisabledColor}"/>

    <ScrollViewer>
      <StackPanel>
        <Grid IsVisible="{Binding !LoadedWhatsNew}"
              ColumnDefinitions="Auto *"
              RowDefinitions="3*, *">

          <progRing:ProgressRing
              IsVisible="{Binding IsLoadingWhatsNew}"
              Grid.Row="0" Grid.Column="0"
              Grid.ColumnSpan="2"
              Width="100"
              Height="100"
              IsActive="True"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Foreground="Ivory"
              Margin="10,20,0,0"/>

          <PathIcon
              Grid.Column="0"
              Grid.Row="1"
              IsVisible="{Binding ShouldShowWhatsNewErrorIcon}"
              Margin="30,40,10,0"
              Data="{StaticResource warning_regular}"
              Height="50" Width="50"/>

          <TextBlock
              Grid.Row="1"
              Grid.Column="1"
              Margin="20,40,0,0"
              TextWrapping="Wrap"
              IsVisible="{Binding ShouldShowWhatsNewInfoText}"
              Text="{Binding WhatsNewLoadingText}"
              FontSize="16"
              VerticalAlignment="Center"/>
        </Grid>
        <TextBlock
            IsVisible="{Binding NoFilteredItems}"
            Text="{ext:Localize XAML_No_Items}"
            Margin="15"
            Foreground="{DynamicResource DisabledColor}"/>

        <StackPanel Orientation="Vertical">
            <ItemsRepeater ItemsSource="{Binding BaseItems}" ElementPrepared="PrepareElement" VerticalCacheLength="20" ItemTemplate="{StaticResource ModItemTemplate}">
            </ItemsRepeater>
            
            <TextBlock Text="Dependency Mods" FontSize="18" Margin="10" IsVisible="{Binding ShouldShowDependencyItems}"/>

            <ItemsRepeater ItemsSource="{Binding DependencyItems}" ElementPrepared="PrepareElement" VerticalCacheLength="20" ItemTemplate="{StaticResource ModItemTemplate}">
            </ItemsRepeater>
        </StackPanel>
      </StackPanel>
    </ScrollViewer>
  </DockPanel>
  </SplitView>
</views:View>
