<window:StyleableAppWindow xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:helpers="using:Ryujinx.Ava.UI.Helpers"
             xmlns:ext="using:Ryujinx.Ava.Common.Markup"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
             xmlns:systems="clr-namespace:Ryujinx.Ava.Systems"
             xmlns:window="clr-namespace:Ryujinx.Ava.UI.Windows"
             xmlns:controls="clr-namespace:Ryujinx.Ava.UI.Controls"
             CanResize="False"
             mc:Ignorable="d"
             MinWidth="800"
             MinHeight="745"
             x:Class="Ryujinx.Ava.UI.Windows.CompatibilityListWindow"
             x:DataType="viewModels:CompatibilityViewModel">
    <window:StyleableAppWindow.DataContext>
        <viewModels:CompatibilityViewModel />
    </window:StyleableAppWindow.DataContext>
    <Grid RowDefinitions="Auto,Auto,*">
        
        <!-- UI FlushControls -->
        <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto,Auto" Name="FlushControls">
            <controls:RyujinxLogo
                Grid.Column="0"
                Margin="15, 0, 7, 0"
                ToolTip.Tip="{ext:WindowTitle CompatibilityListTitle, False}"/>
            <TextBox Grid.Column="1"
                     Name="SearchBoxFlush" 
                     Margin="0, 5, 0, 5" 
                     HorizontalAlignment="Stretch" 
                     Watermark="{ext:Locale CompatibilityListSearchBoxWatermarkWithCount}" 
                     TextChanged="TextBox_OnTextChanged"/>
            <StackPanel Grid.Column="2" Orientation="Horizontal"  Margin="10, 5, 0, 5">
                <DropDownButton
                        Width="150"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Content="{Binding SortName}"
                        DockPanel.Dock="Right">
                    <DropDownButton.Flyout>
                        <Flyout Placement="Bottom">
                            <StackPanel
                                Margin="0"
                                HorizontalAlignment="Stretch"
                                Orientation="Vertical">
                                <StackPanel>
                                    <RadioButton
                                        Checked="Sort_Name_Checked"
                                        Content="{ext:Locale GameListSortStatusNameAscending}"
                                        GroupName="Sort"
                                        IsChecked="{Binding IsSortedByTitle, Mode=OneTime}"
                                        Tag="0" />
                                    <RadioButton
                                        Checked="Sort_Name_Checked"
                                        Content="{ext:Locale GameListSortStatusNameDescending}"
                                        GroupName="Sort"
                                        Tag="1" />
                                </StackPanel>
                                <Border
                                    Width="60"
                                    Height="2"
                                    Margin="5"
                                    HorizontalAlignment="Stretch"
                                    BorderBrush="White"
                                    BorderThickness="0,1,0,0">
                                    <Separator Height="0" HorizontalAlignment="Stretch" />
                                </Border>
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusDisable}"
                                    GroupName="Order"
                                    IsChecked="{Binding IsSortedByStatus, Mode=OneTime}"
                                    Tag="0" />
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusAscending}"
                                    GroupName="Order"
                                    Tag="1" />
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusDescending}"
                                    GroupName="Order"
                                    Tag="2" />
                            </StackPanel>
                        </Flyout>
                    </DropDownButton.Flyout>
                </DropDownButton>
            </StackPanel>
            <CheckBox Grid.Column="3" Margin="15, 0, 155, 0" IsChecked="{Binding OnlyShowOwnedGames}">
                <TextBlock Text="{ext:Locale CompatibilityListOnlyShowOwnedGames}" />
            </CheckBox>
        </Grid>

        <!-- UI NormalControls -->
        <Grid Grid.Row="0" ColumnDefinitions="*,Auto,Auto,Auto" Name="NormalControls">
            <TextBox Name="SearchBoxNormal" Grid.Column="0" Margin="15, 5, 0, 5" HorizontalAlignment="Stretch" Watermark="{ext:Locale CompatibilityListSearchBoxWatermarkWithCount}" TextChanged="TextBox_OnTextChanged" />
            <StackPanel Grid.Column="1" Orientation="Horizontal"  Margin="10, 5, 5, 5">
                <DropDownButton
                    Width="150"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    Content="{Binding SortName}"
                    DockPanel.Dock="Right">
                    <DropDownButton.Flyout>
                        <Flyout Placement="Bottom">
                            <StackPanel
                                Margin="0"
                                HorizontalAlignment="Stretch"
                                Orientation="Vertical">
                                <StackPanel>
                                    <RadioButton
                                        Checked="Sort_Name_Checked"
                                        Content="{ext:Locale GameListSortStatusNameAscending}"
                                        GroupName="Sort"
                                        IsChecked="{Binding IsSortedByTitle, Mode=OneTime}"
                                        Tag="0" />
                                    <RadioButton
                                        Checked="Sort_Name_Checked"
                                        Content="{ext:Locale GameListSortStatusNameDescending}"
                                        GroupName="Sort"
                                        Tag="1" />
                                </StackPanel>
                                <Border
                                    Width="60"
                                    Height="2"
                                    Margin="5"
                                    HorizontalAlignment="Stretch"
                                    BorderBrush="White"
                                    BorderThickness="0,1,0,0">
                                    <Separator Height="0" HorizontalAlignment="Stretch" />
                                </Border>
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusDisable}"
                                    GroupName="Order"
                                    IsChecked="{Binding IsSortedByStatus, Mode=OneTime}"
                                    Tag="0" />
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusAscending}"
                                    GroupName="Order"
                                    Tag="1" />
                                <RadioButton
                                    Checked="Sort_Status_Checked"
                                    Content="{ext:Locale GameListSortStatusDescending}"
                                    GroupName="Order"
                                    Tag="2" />
                            </StackPanel>
                        </Flyout>
                    </DropDownButton.Flyout>
                </DropDownButton>
            </StackPanel>
            <CheckBox Grid.Column="2" Margin="20, 0, 50, 0" IsChecked="{Binding OnlyShowOwnedGames}">
                <TextBlock Text="{ext:Locale CompatibilityListOnlyShowOwnedGames}" />
            </CheckBox>
        </Grid>

        <!-- Description Field Above ScrollViewer -->
        <Grid Grid.Row="1" ColumnDefinitions="*,Auto" Margin="10, 5, 10, 5">
            <Grid Grid.Column="0">
                <Border Classes="listbox-item-style">
                    <Grid MinWidth="800"
                          ColumnDefinitions="Auto,Auto,Auto,*,Auto"
                          Background="Transparent">
                        <TextBlock Grid.Column="0"
                                   Text="{ext:Locale CompatibilityListGamesAndApplications}"
                                   FontWeight="Bold"
                                   Width="525"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   TextWrapping="Wrap" />
                        <TextBlock Grid.Column="1"
                                   Text="ID"
                                   FontWeight="Bold"
                                   Width="135"
                                   Padding="7, 0, 0, 0"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   TextWrapping="Wrap" />
                        <TextBlock Grid.Column="2"
                                   Padding="7, 0"
                                   Text="{ext:Locale CompatibilityListStatus}"
                                   FontWeight="Bold"
                                   Width="100"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   TextWrapping="NoWrap" />
                        <TextBlock Grid.Column="3"
                                   Text="{ext:Locale CompatibilityListDescription}"
                                   FontWeight="Bold"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Left"
                                   TextWrapping="WrapWithOverflow" />
                    </Grid>
                </Border>
            </Grid>
            <Grid Grid.Column="1">
                <DropDownButton 
                    Width="80"
                    Height="35"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    Content="{ext:Locale CompatibilityListStats}"
                    DockPanel.Dock="Right">
                    <DropDownButton.Flyout>
                        <Flyout Placement="Bottom">
                            <StackPanel>
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{Binding IsStringPlayable, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                    Text="{Binding PlayableInfoText }" />
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{Binding IsStringInGame, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                    Text="{Binding InGameInfoText }" />
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{Binding IsStringMenus, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                    Text="{Binding MenusInfoText }" />
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{Binding IsStringBoots, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                    Text="{Binding BootsInfoText  }" />
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{Binding IsStringNothing, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                    Text="{Binding NothingInfoText  }" />
                            </StackPanel>
                        </Flyout>
                    </DropDownButton.Flyout>
                </DropDownButton>
            </Grid>
            
        </Grid>

        <!-- List of compatible games  -->
        <ScrollViewer Grid.Row="2">
            <ListBox Margin="12, 0, 13, 0"
                     Background="Transparent"
                     ItemsSource="{Binding CurrentEntries}">
                <ListBox.ItemTemplate>
                    <DataTemplate DataType="{x:Type systems:CompatibilityEntry}">
                        <Grid MinWidth="800"
                              Margin="10"
                              ColumnDefinitions="Auto,Auto,Auto,*"
                              Background="Transparent"
                              ToolTip.Tip="{Binding  LocalizedLastUpdated}">
                            <TextBlock Grid.Column="0"
                                       Text="{Binding GameName}"
                                       Width="525"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <TextBlock Grid.Column="1"
                                       Width="135"
                                       Padding="7, 0, 0, 0"
                                       FontFamily="{StaticResource JetBrainsMono}"
                                       Text="{Binding FormattedTitleId}"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       TextWrapping="Wrap" />
                            <TextBlock Grid.Column="2"
                                       Padding="7, 0"
                                       Text="{Binding LocalizedStatus}"
                                       Width="100"
                                       Background="Transparent"
                                       ToolTip.Tip="{Binding LocalizedStatusDescription}"
                                       Foreground="{Binding Status, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       TextWrapping="NoWrap" />
                            <TextBlock Grid.Column="3"
                                       Text="{Binding FormattedIssueLabels}"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Left"
                                       TextWrapping="WrapWithOverflow" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>
        <Grid></Grid>
    </Grid>
</window:StyleableAppWindow>
