<UserControl
    x:Class="Ryujinx.Ava.UI.Controls.ApplicationListView"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Ryujinx.Ava.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
    d:DesignHeight="450"
    d:DesignWidth="800"
    Focusable="True"
    mc:Ignorable="d"
    xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
    x:DataType="viewModels:MainWindowViewModel">
    <UserControl.Resources>
        <helpers:BitmapArrayValueConverter x:Key="ByteImage" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </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={StaticResource ByteImage}}" />
                                <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" />
                                    </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"
                                        Text="{Binding Converter={helpers:MultiplayerInfoConverter}}"
                                        TextAlignment="Start"
                                        TextWrapping="Wrap"/>
                                </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>
