<UserControl
    x:Class="Ryujinx.Ava.UI.Views.Dialog.XCITrimmerView"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
    xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
    xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
    xmlns:models="clr-namespace:Ryujinx.Ava.Common.Models"
    Width="700"
    Height="600"
    x:DataType="viewModels:XCITrimmerViewModel"
    Focusable="True"
    mc:Ignorable="d">
    <Grid Margin="25,10,25,0" RowDefinitions="Auto,Auto,*,Auto,Auto">
        <Panel Margin="0,0,0,10" Grid.Row="0">
            <TextBlock Text="{Binding Status}" />
        </Panel>
        <Grid Margin="0,0,0,10" Grid.Row="1" IsVisible="{Binding !Processing}" ColumnDefinitions="Auto,*">
            <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                <Button Margin="0,0,10,0" MinWidth="90" Click="ToggleSelect">
                    <TextBlock Text="{Binding SelectToggleText}" />
                </Button>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                <DropDownButton Width="170" HorizontalAlignment="Right" VerticalAlignment="Center" Content="{Binding SortingFieldName}">
                    <DropDownButton.Flyout>
                        <Flyout Placement="Bottom">
                            <StackPanel Margin="0" HorizontalAlignment="Stretch" Orientation="Vertical">
                                <StackPanel>
                                    <RadioButton Checked="Sort_Checked" Content="{ext:Locale Common_Sort_NameLabel}" GroupName="Sort" IsChecked="{Binding IsSortedByName, Mode=OneTime}" Tag="Name" />
                                    <RadioButton Checked="Sort_Checked" Content="{ext:Locale Common_Sort_SavingsLabel}" GroupName="Sort" IsChecked="{Binding IsSortedBySavings, Mode=OneTime}" Tag="Savings" />
                                    <RadioButton Checked="Sort_Checked" Content="{ext:Locale Common_Sort_TrimStatusLabel}" GroupName="Sort" IsChecked="{Binding IsSortedByStatus, Mode=OneTime}" Tag="Status" />
                                </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="Order_Checked" Content="{ext:Locale Common_Sort_OrderAscending}" GroupName="Order" IsChecked="{Binding SortingAscending, Mode=OneTime}" Tag="Ascending" />
                                <RadioButton Checked="Order_Checked" Content="{ext:Locale Common_Sort_OrderDescending}" GroupName="Order" IsChecked="{Binding !SortingAscending, Mode=OneTime}" Tag="Descending" />
                            </StackPanel>
                        </Flyout>
                    </DropDownButton.Flyout>
                </DropDownButton>
                <TextBox
                    Width="200"
                    MaxWidth="200"
                    Margin="5,0,0,0"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Right"
                    Watermark="{ext:Locale Common_Search_SearchWatermark}"
                    Text="{Binding Search}" />
            </StackPanel>
        </Grid>
        <Border
            Grid.Row="2"
            Margin="0,0,0,20"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            BorderBrush="{DynamicResource AppListHoverBackgroundColor}"
            BorderThickness="1"
            CornerRadius="5"
            Padding="2.5">
            <ListBox
                AutoScrollToSelectedItem="{Binding Processing}"
                SelectedItem="{Binding NullableProcessingApplication}"
                SelectionMode="Multiple, Toggle"
                Background="Transparent"
                SelectionChanged="OnSelectionChanged"
                SelectedItems="{Binding SelectedDisplayedXCIFiles, Mode=OneWay}"
                ItemsSource="{Binding DisplayedXCIFiles}"
                IsEnabled="{Binding !Processing}">
                <ListBox.Styles>
                    <Style Selector="ListBoxItem">
                        <Setter Property="Margin" Value="0" />
                        <Setter Property="Background" Value="Transparent" />
                    </Style>
                </ListBox.Styles>
                <ListBox.DataTemplates>
                    <DataTemplate DataType="models:XCITrimmerFileModel">
                        <Grid ColumnDefinitions="Auto,*,Auto">
                            <ui:SymbolIcon
                                Grid.Column="0"
                                Margin="10,0,20,0"
                                Width="15"
                                Height="15"
                                FontSize="15"
                                FlowDirection="LeftToRight"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Symbol="{Binding Converter={x:Static helpers:XCITrimmerFileStatusConverter.Instance}}">
                                <ToolTip.Tip>
                                    <StackPanel>
                                        <TextBlock
                                            Text="{Binding StatusText}" />
                                        <TextBlock
                                            MaxLines="5"
                                            MaxWidth="200"
                                            TextWrapping="Wrap"
                                            IsVisible="{Binding HasStatusDetail}"
                                            Text="{Binding ., Converter={x:Static helpers:XCITrimmerFileStatusDetailConverter.Instance}}" />
                                    </StackPanel>
                                </ToolTip.Tip>
                            </ui:SymbolIcon>
                            <TextBlock
                                Grid.Column="1"
                                Margin="0,0,10,0"
                                VerticalAlignment="Center"
                                MaxLines="2"
                                TextWrapping="Wrap"
                                TextTrimming="CharacterEllipsis"
                                Text="{Binding Name}" />
                            <Grid
                                Grid.Column="2"
                                MinWidth="120"
                                ColumnDefinitions="*">
                                <ProgressBar
                                    Height="10"
                                    Margin="10,0,10,0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Center"
                                    CornerRadius="5"
                                    IsVisible="{Binding $parent[UserControl].DataContext.Processing}"
                                    Maximum="100"
                                    Minimum="0"
                                    Value="{Binding PercentageProgress}" />
                                <TextBlock
                                    Margin="10,0,10,0"
                                    FlowDirection="LeftToRight"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    MaxLines="1"
                                    IsVisible="{Binding !$parent[UserControl].DataContext.Processing}"
                                    Text="{Binding ., Converter={x:Static helpers:XCITrimmerFileSpaceSavingsConverter.Instance}}" />
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </ListBox.DataTemplates>
            </ListBox>
        </Border>
        <StackPanel Grid.Row="3" Margin="0,0,0,20" Spacing="5" FlowDirection="LeftToRight" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
            <TextBlock Classes="h1" HorizontalAlignment="Center" VerticalAlignment="Center" MaxLines="1" Text="{ext:Locale XCITrimmer_SavedLabel}" />
            <TextBlock Classes="h1" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Regular" MaxLines="1" Text="{Binding ActualSavings}" />
            <TextBlock Classes="h1" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Regular" MaxLines="1" Text="•" />
            <TextBlock Classes="h1" HorizontalAlignment="Center" VerticalAlignment="Center" MaxLines="1" Text="{ext:Locale XCITrimmer_RemainingLabel}" />
            <TextBlock Classes="h1" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Regular" MaxLines="1" Text="{Binding SavingsDifference}" />
        </StackPanel>
        <Panel Grid.Row="4" Margin="0,10,0,0" HorizontalAlignment="Stretch">
            <Grid ColumnDefinitions="*,Auto">
                <StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="10" HorizontalAlignment="Left">
                    <Button Name="TrimButton" MinWidth="90" Click="Trim" IsEnabled="{Binding CanTrim}">
                        <TextBlock Text="{ext:Locale XCITrimmer_TrimButton}" />
                    </Button>
                    <Button Name="UntrimButton" MinWidth="90" Click="Untrim" IsEnabled="{Binding CanUntrim}">
                        <TextBlock Text="{ext:Locale XCITrimmer_UntrimButton}" />
                    </Button>
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="10" HorizontalAlignment="Right">
                    <Button Name="CancellingButton" MinWidth="90" Click="Cancel" IsEnabled="False">
                        <Button.IsVisible>
                            <MultiBinding Converter="{x:Static BoolConverters.And}">
                                <Binding Path="Processing" />
                                <Binding Path="Cancel" />
                            </MultiBinding>
                        </Button.IsVisible>
                        <TextBlock Text="{ext:Locale InputDialogCancelling}" />
                    </Button>
                    <Button Name="CancelButton" MinWidth="90" Click="Cancel">
                        <Button.IsVisible>
                            <MultiBinding Converter="{x:Static BoolConverters.And}">
                                <Binding Path="Processing" />
                                <Binding Path="!Cancel" />
                            </MultiBinding>
                        </Button.IsVisible>
                        <TextBlock Text="{ext:Locale InputDialogCancel}" />
                    </Button>
                    <Button Name="CloseButton" MinWidth="90" Click="Close" IsVisible="{Binding !Processing}">
                        <TextBlock Text="{ext:Locale SettingsButtonClose}" />
                    </Button>
                </StackPanel>
            </Grid>
        </Panel>
    </Grid>
</UserControl>