<UserControl
    x:Class="Ryujinx.Ava.UI.Views.Misc.ApplicationListView"
    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="clr-namespace:Ryujinx.Ava.UI.Helpers"
    xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
    d:DesignHeight="450"
    d:DesignWidth="800"
    Focusable="True"
    mc:Ignorable="d"
    xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
    x:DataType="viewModels:MainWindowViewModel">
    <Grid RowDefinitions="*">
        <ListBox
            Name="GameListBox"
            Grid.Row="0"
            Padding="8"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            SelectedItem="{Binding ListSelectedApplication}"
            ContextFlyout="{Binding ListAppContextMenu}"
            DoubleTapped="GameList_DoubleTapped"
            ItemsSource="{Binding AppsObservableList}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Orientation="Vertical"
                        Spacing="2" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.Styles>
                <Style Selector="ListBoxItem:selected /template/ Rectangle#SelectionIndicator">
                    <Setter Property="MinHeight" Value="{Binding $parent[UserControl].((viewModels:MainWindowViewModel)DataContext).ListItemSelectorSize}" />
                </Style>
            </ListBox.Styles>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Border
                            Margin="0"
                            Padding="10"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            ClipToBounds="True"
                            CornerRadius="5">
                            <Grid ColumnDefinitions="Auto,10,*,150,100">
                                <Image
                                    Grid.RowSpan="3"
                                    Grid.Column="0"
                                    Margin="0"
                                    Classes.huge="{Binding $parent[UserControl].((viewModels:MainWindowViewModel)DataContext).IsGridHuge}"
                                    Classes.large="{Binding $parent[UserControl].((viewModels:MainWindowViewModel)DataContext).IsGridLarge}"
                                    Classes.normal="{Binding $parent[UserControl].((viewModels:MainWindowViewModel)DataContext).IsGridMedium}"
                                    Classes.small="{Binding $parent[UserControl].((viewModels:MainWindowViewModel)DataContext).IsGridSmall}"
                                    Source="{Binding Icon, Converter={x:Static helpers:BitmapArrayValueConverter.Instance}}" />
                                <Border
                                    Grid.Column="2"
                                    Margin="0,0,5,0"
                                    BorderBrush="{DynamicResource ThemeControlBorderColor}"
                                    BorderThickness="0,0,1,0">
                                    <StackPanel
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Top"
                                        Orientation="Vertical"
                                        Spacing="5">
                                        <TextBlock
                                            HorizontalAlignment="Stretch"
                                            FontWeight="Bold"
                                            Text="{Binding Name}"
                                            TextAlignment="Start"
                                            TextWrapping="Wrap" />
                                        <TextBlock
                                            HorizontalAlignment="Stretch"
                                            Text="{Binding Developer}"
                                            TextAlignment="Start"
                                            TextWrapping="Wrap" />
                                        <TextBlock
                                            HorizontalAlignment="Stretch"
                                            Text="{Binding Version}"
                                            TextAlignment="Start"
                                            TextWrapping="Wrap" />
                                        <Button 
                                            Click="PlayabilityStatus_OnClick" 
                                            HorizontalContentAlignment="Left"
                                            VerticalAlignment="Center"
                                            IsVisible="{Binding HasPlayabilityInfo}"
                                            Background="{DynamicResource AppListBackgroundColor}"
                                            Margin="-1, 0, 0, 0"
                                            Padding="0">
                                            <ToolTip.Tip>
                                                <StackPanel Orientation="Vertical">
                                                    <TextBlock 
                                                        Text="{Binding LocalizedStatusTooltip}" />
                                                    <Separator 
                                                        Margin="0, 10, 0, 10" 
                                                        IsVisible="{Binding HasCompatibilityLabels}" />
                                                    <TextBlock 
                                                        IsVisible="{Binding HasCompatibilityLabels}"
                                                        Text="{Binding FormattedCompatibilityLabels}" />
                                                </StackPanel>
                                            </ToolTip.Tip>
                                            <TextBlock
                                                Margin="1.5"
                                                Tag="{Binding IdString}"
                                                Text="{Binding LocalizedStatus}"
                                                Foreground="{Binding PlayabilityStatus, Converter={x:Static helpers:PlayabilityStatusConverter.Shared}}"
                                                TextAlignment="Start"
                                                TextWrapping="Wrap" />
                                            <Button.Styles>
                                                <Style Selector="Button">
                                                    <Setter Property="MinWidth"
                                                            Value="0" /> 
                                <!-- avoids very wide buttons from the overall project avalonia style -->
                                                </Style>
                                            </Button.Styles>
                                        </Button>
                                    </StackPanel>
                                </Border>
                                <StackPanel
                                    Grid.Column="3"
                                    Margin="10,0,0,0"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Top"
                                    Orientation="Vertical"
                                    Spacing="5">
                                    <Button 
                                        Click="IdString_OnClick" 
                                        HorizontalContentAlignment="Left" 
                                        VerticalAlignment="Center"
                                        Background="{DynamicResource AppListBackgroundColor}"
                                        Margin="-1, 0, 0, 0"
                                        Padding="0" >
                                        <TextBlock
                                            Margin="1.5"
                                            HorizontalAlignment="Stretch"
                                            Text="{Binding IdString}"
                                            Tag="{Binding Id}"
                                            TextAlignment="Start"
                                            TextWrapping="Wrap" />
                                    </Button>
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        Text="{Binding FileExtension}"
                                        TextAlignment="Start"
                                        TextWrapping="Wrap" />
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        IsVisible="{Binding HasLdnGames}"
                                        Text="{Binding Converter={x:Static helpers:MultiplayerInfoConverter.Instance}}"
                                        TextAlignment="Start"
                                        TextWrapping="Wrap"/>
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        IsVisible="{Binding HasIndependentConfiguration}"
                                        Text="{ext:Locale GameSpecificConfigurationHeader}"
                                        TextAlignment="Start"
                                        TextWrapping="Wrap"
                                        Foreground="{DynamicResource Warning}" />
                                </StackPanel>
                                <StackPanel
                                    Grid.Column="4"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Top"
                                    Orientation="Vertical"
                                    Spacing="5">
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        Text="{Binding LastPlayedString}"
                                        TextAlignment="End"
                                        TextWrapping="Wrap" />
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        Text="{Binding TimePlayedString}"
                                        IsVisible="{Binding HasPlayedPreviously}"
                                        TextAlignment="End"
                                        TextWrapping="Wrap" />
                                    <TextBlock
                                        HorizontalAlignment="Stretch"
                                        Text="{Binding FileSizeString}"
                                        TextAlignment="End"
                                        TextWrapping="Wrap" />
                                </StackPanel>
                                <ui:SymbolIcon
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    Margin="-5,-5,0,0"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Top"
                                    FontSize="16"
                                    Foreground="{DynamicResource FavoriteApplicationIconColor}"
                                    IsVisible="{Binding Favorite}"
                                    Symbol="StarFilled" />
                            </Grid>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
