<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: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="20 0 20 0" RowDefinitions="Auto,Auto,*,Auto,Auto">
        <Panel
            Margin="10 10 10 10"
            Grid.Row="0">
            <TextBlock Text="{Binding Status}" />
        </Panel>
        <Panel
            Margin="0 0 10 10"
            IsVisible="{Binding !Processing}"
            Grid.Row="1">
            <Grid ColumnDefinitions="Auto,*,Auto">
                <StackPanel 
                    Grid.Column="0"
                    Orientation="Horizontal">
                    <DropDownButton
                        Width="150"
                        HorizontalAlignment="Left"
                        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 XCITrimmerSortName}"
                                            GroupName="Sort"
                                            IsChecked="{Binding IsSortedByName, Mode=OneTime}"
                                            Tag="Name" />
                                        <RadioButton
                                            Checked="Sort_Checked"
                                            Content="{ext:Locale XCITrimmerSortSaved}"
                                            GroupName="Sort"
                                            IsChecked="{Binding IsSortedBySaved, Mode=OneTime}"
                                            Tag="Saved" />
                                    </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 OrderAscending}"
                                        GroupName="Order"
                                        IsChecked="{Binding SortingAscending, Mode=OneTime}"
                                        Tag="Ascending" />
                                    <RadioButton
                                        Checked="Order_Checked"
                                        Content="{ext:Locale OrderDescending}"
                                        GroupName="Order"
                                        IsChecked="{Binding !SortingAscending, Mode=OneTime}"
                                        Tag="Descending" />
                                </StackPanel>
                            </Flyout>
                        </DropDownButton.Flyout>
                    </DropDownButton>
                </StackPanel>
                <TextBox
                    Grid.Column="1"
                    MinHeight="29"
                    MaxHeight="29"
                    Margin="5 0 5 0"
                    HorizontalAlignment="Stretch"
                    Watermark="{ext:Locale Search}"
                    Text="{Binding Search}" />
                <StackPanel
                    Grid.Column="2"
                    Orientation="Horizontal">
                    <Button
                        Name="SelectDisplayedButton"
                        MinWidth="90"
                        Margin="5"
                        Command="{Binding SelectDisplayed}">
                        <TextBlock Text="{ext:Locale XCITrimmerSelectDisplayed}" />
                    </Button>
                    <Button
                        Name="DeselectDisplayedButton"
                        MinWidth="90"
                        Margin="5"
                        Command="{Binding DeselectDisplayed}">
                        <TextBlock Text="{ext:Locale XCITrimmerDeselectDisplayed}" />
                    </Button>
                </StackPanel>
            </Grid>
        </Panel>
        <Border
            Grid.Row="2"
            Margin="0 0 0 10"
            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.DataTemplates>
                    <DataTemplate
                        DataType="models:XCITrimmerFileModel">
                        <Panel Margin="10">
                            <Grid ColumnDefinitions="65*,35*">
                                <TextBlock
                                    Grid.Column="0"
                                    Margin="10 0 10 0"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    MaxLines="2"
                                    TextWrapping="Wrap"
                                    TextTrimming="CharacterEllipsis"
                                    Text="{Binding Name}">
                                </TextBlock>
                                <Grid Grid.Column="1" ColumnDefinitions="45*,55*">
                                    <ProgressBar
                                        Height="10"
                                        Margin="10 0 10 0"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Center"
                                        CornerRadius="5"
                                        IsVisible="{Binding $parent[UserControl].((viewModels:XciTrimmerViewModel)DataContext).Processing}"
                                        Maximum="100"
                                        Minimum="0"
                                        Value="{Binding PercentageProgress}" />
                                    <TextBlock
                                        Grid.Column="0"
                                        Margin="10 0 10 0"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Center"
                                        MaxLines="1"
                                        Text="{Binding ., Converter={x:Static helpers:XCITrimmerFileStatusConverter.Instance}}">
                                        <ToolTip.Tip>
                                            <StackPanel
                                                IsVisible="{Binding IsFailed}">
                                                <TextBlock 
                                                    Classes="h1" 
                                                    Text="{ext:Locale XCITrimmerTitleStatusFailed}" />
                                                <TextBlock 
                                                    Text="{Binding ., Converter={x:Static helpers:XCITrimmerFileStatusDetailConverter.Instance}}" 
                                                    MaxLines="5"
                                                    MaxWidth="200"
                                                    MaxHeight="100"
                                                    TextTrimming="None"
                                                    TextWrapping="Wrap"/>
                                            </StackPanel>
                                        </ToolTip.Tip>
                                    </TextBlock>
                                    <TextBlock
                                        Grid.Column="1"
                                        Margin="10 0 10 0"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Center"
                                        MaxLines="1"
                                        Text="{Binding ., Converter={x:Static helpers:XCITrimmerFileSpaceSavingsConverter.Instance}}">>
                                    </TextBlock>
                                </Grid>
                            </Grid>
                        </Panel>
                    </DataTemplate>
                </ListBox.DataTemplates>
                <ListBox.Styles>
                    <Style Selector="ListBoxItem">
                        <Setter Property="Background" Value="Transparent" />
                    </Style>
                </ListBox.Styles>
            </ListBox>
        </Border>
        <Border
            Grid.Row="3"
            Margin="0 0 0 10"
            HorizontalAlignment="Stretch"
            BorderBrush="{DynamicResource AppListHoverBackgroundColor}"
            BorderThickness="1"
            CornerRadius="5"
            Padding="2.5">
            <Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto">
                <TextBlock
                    Grid.Column="0"
                    Grid.Row="0"
                    Classes="h1"
                    Margin="5"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    MaxLines="1"
                    Text="{ext:Locale XCITrimmerPotentialSavings}" />
                <TextBlock
                    Grid.Column="0"
                    Grid.Row="1"
                    Classes="h1"
                    Margin="5"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    MaxLines="1"
                    Text="{ext:Locale XCITrimmerActualSavings}" />
                <TextBlock
                    Grid.Column="1"
                    Grid.Row="0"
                    Margin="5"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    MaxLines="1"
                    Text="{Binding PotentialSavings}" />
                <TextBlock
                    Grid.Column="1"
                    Grid.Row="1"
                    Margin="5"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    MaxLines="1"
                    Text="{Binding ActualSavings}" />
            </Grid>
        </Border>
        <Panel
            Grid.Row="4"
            HorizontalAlignment="Stretch">
            <Grid ColumnDefinitions="*,Auto">
                <StackPanel
                    Grid.Column="0"
                    Orientation="Horizontal"
                    Spacing="10"
                    HorizontalAlignment="Left">
                    <Button
                        Name="TrimButton"
                        MinWidth="90"
                        Margin="5"
                        Click="Trim"
                        IsEnabled="{Binding CanTrim}">
                        <TextBlock Text="{ext:Locale XCITrimmerTrim}" />
                    </Button>
                    <Button
                        Name="UntrimButton"
                        MinWidth="90"
                        Margin="5"
                        Click="Untrim"
                        IsEnabled="{Binding CanUntrim}">
                        <TextBlock Text="{ext:Locale XCITrimmerUntrim}" />
                    </Button>
                </StackPanel>
                <StackPanel
                    Grid.Column="1"
                    Orientation="Horizontal"
                    Spacing="10"
                    HorizontalAlignment="Right">
                    <Button
                        Name="CancellingButton"
                        MinWidth="90"
                        Margin="5"
                        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"
                        Margin="5"
                        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"
                        Margin="5"
                        Click="Close"
                        IsVisible="{Binding !Processing}">
                        <TextBlock Text="{ext:Locale InputDialogClose}" />
                    </Button>
                </StackPanel>
            </Grid>
        </Panel>
    </Grid>
</UserControl>
