<dialogs:ImmersiveDialog xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dialogs="using:UniGetUI.Avalonia.Views.DialogPages"
        xmlns:automation="clr-namespace:Avalonia.Automation;assembly=Avalonia.Controls"
        xmlns:vm="using:UniGetUI.Avalonia.ViewModels"
        xmlns:controls="using:UniGetUI.Avalonia.Views.Controls"
        xmlns:t="using:UniGetUI.Avalonia.MarkupExtensions"
        x:Class="UniGetUI.Avalonia.Views.ManageIgnoredUpdatesWindow"
        x:DataType="vm:ManageIgnoredUpdatesViewModel"
        Title="{Binding Title}"
        MaxWidth="850"
        MinWidth="520"
        MaxHeight="500"
        MinHeight="280"
        HorizontalContentAlignment="Stretch"
        VerticalContentAlignment="Stretch">

    <dialogs:ImmersiveDialog.Styles>
        <!-- WinUI-style row hover highlight. The base Background must be set via a style
             (not a local value) so the :pointerover setter can override it. -->
        <Style Selector="Border.row">
            <Setter Property="Background" Value="Transparent"/>
        </Style>
        <Style Selector="Border.row:pointerover">
            <Setter Property="Background" Value="{DynamicResource SubtleFillColorSecondaryBrush}"/>
        </Style>
    </dialogs:ImmersiveDialog.Styles>

    <Grid RowDefinitions="Auto,*"
          Margin="20"
          RowSpacing="12">

        <!-- ── Description + Reset list button ── -->
        <Grid Grid.Row="0" ColumnDefinitions="*,Auto" ColumnSpacing="8">
            <TextBlock Text="{Binding Description}"
                       TextWrapping="Wrap"
                       VerticalAlignment="Center"
                       Opacity="0.75"/>

            <Button x:Name="ResetButton" Grid.Column="1" VerticalAlignment="Center"
                    automation:AutomationProperties.Name="{Binding ResetLabel}">
                <TextBlock Text="{Binding ResetLabel}"/>
                <Button.Flyout>
                    <Flyout Placement="Bottom">
                        <Flyout.FlyoutPresenterTheme>
                            <ControlTheme TargetType="FlyoutPresenter">
                                <Setter Property="Background" Value="{DynamicResource AppDialogPanelBackground}"/>
                                <Setter Property="BorderBrush" Value="{DynamicResource AppBorderBrush}"/>
                                <Setter Property="BorderThickness" Value="1"/>
                                <Setter Property="CornerRadius" Value="8"/>
                                <Setter Property="Padding" Value="12"/>
                            </ControlTheme>
                        </Flyout.FlyoutPresenterTheme>
                        <Grid Width="300"
                              ColumnDefinitions="*,*"
                              RowDefinitions="Auto,Auto"
                              ColumnSpacing="8" RowSpacing="16"
                              Margin="4">
                            <TextBlock Grid.ColumnSpan="2"
                                       Text="{Binding ResetConfirm}"
                                       TextWrapping="Wrap"/>
                            <Button Grid.Row="1" Grid.Column="0"
                                    Content="{Binding ResetYes}"
                                    automation:AutomationProperties.Name="{Binding ResetYes}"
                                    HorizontalAlignment="Stretch"
                                    Click="ResetYes_Click"/>
                            <Button Grid.Row="1" Grid.Column="1"
                                    Content="{Binding ResetNo}"
                                    automation:AutomationProperties.Name="{Binding ResetNo}"
                                    HorizontalAlignment="Stretch"
                                    Classes="accent"
                                    Click="ResetNo_Click"/>
                        </Grid>
                    </Flyout>
                </Button.Flyout>
            </Button>

        </Grid>

        <!-- ── Package list (mirrors the WinUI ItemsView: flat rows, no header) ── -->
        <Border Grid.Row="1"
                CornerRadius="8"
                Background="{DynamicResource AppDialogDarkBackground}">
          <Panel>

            <!-- Empty state -->
            <TextBlock Text="{Binding EmptyLabel}"
                       IsVisible="{Binding ShowEmptyLabel}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       FontSize="20"
                       FontWeight="Bold"
                       Opacity="0.5"/>

            <ScrollViewer IsVisible="{Binding HasEntries}"
                          HorizontalScrollBarVisibility="Disabled"
                          VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Entries}"
                              x:Name="IgnoredUpdatesGrid"
                              Padding="2,4"
                              automation:AutomationProperties.Name="{Binding Title}"
                              automation:AutomationProperties.HelpText="{Binding Description}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" Spacing="0"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate x:DataType="vm:IgnoredPackageEntryViewModel">
                          <Border Classes="row" Height="36" Margin="0" CornerRadius="4"
                                  Padding="8,0">
                            <Grid ColumnSpacing="4"
                                  automation:AutomationProperties.Name="{Binding AutomationName}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*" MaxWidth="120"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*" MaxWidth="170"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*" MaxWidth="90"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <controls:SvgIcon Grid.Column="0" Width="24" Height="24" VerticalAlignment="Center"
                                                  Path="avares://UniGetUI/Assets/Symbols/package.svg"/>
                                <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="2,0"
                                           Text="{Binding Name}" TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding Name}"/>

                                <controls:SvgIcon Grid.Column="2" Width="24" Height="24" VerticalAlignment="Center"
                                                  Path="avares://UniGetUI/Assets/Symbols/id.svg"/>
                                <TextBlock Grid.Column="3" VerticalAlignment="Center" Margin="2,0"
                                           Text="{Binding Id}" TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding Id}"/>

                                <controls:SvgIcon Grid.Column="4" Width="24" Height="24" VerticalAlignment="Center"
                                                  Path="avares://UniGetUI/Assets/Symbols/version.svg"/>
                                <TextBlock Grid.Column="5" VerticalAlignment="Center" Margin="2,0"
                                           Text="{Binding VersionDisplay}" TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding VersionDisplay}"/>

                                <controls:SvgIcon Grid.Column="6" Width="24" Height="24" VerticalAlignment="Center"
                                                  Path="avares://UniGetUI/Assets/Symbols/upgradable.svg"/>
                                <TextBlock Grid.Column="7" VerticalAlignment="Center" Margin="2,0"
                                           Text="{Binding NewVersion}" TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding NewVersion}"/>

                                <controls:SvgIcon Grid.Column="8" Width="24" Height="24" VerticalAlignment="Center"
                                                  Path="{Binding ManagerIconPath}"/>
                                <TextBlock Grid.Column="9" VerticalAlignment="Center" Margin="2,0"
                                           Text="{Binding Manager}" TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding Manager}"/>

                                <Button Grid.Column="10" Width="32" Height="32" Padding="0" Margin="4,0,0,0"
                                        VerticalAlignment="Center"
                                        Command="{Binding RemoveCommand}"
                                        automation:AutomationProperties.Name="{Binding RemoveAutomationName}"
                                        ToolTip.Tip="{t:Translate Text='Remove from list'}">
                                    <controls:SvgIcon Path="avares://UniGetUI/Assets/Symbols/delete.svg"
                                                      Width="16" Height="16"/>
                                </Button>
                            </Grid>
                          </Border>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>

          </Panel>
        </Border>

    </Grid>
</dialogs:ImmersiveDialog>
