using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Library;
using Titano.App.Sections;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Testing;
using Titano.Ui.Controls;
using Titano.Ui.Visuals;
namespace Titano.App.Tests.Library;
///
/// The Library's new states of --capture () on the sample index while signed in to the
/// sample server, rendered in both themes in the real main window: the timeline, a selection with the whole mass actions
/// bar and its delete dry run, the server's sequences as remote cards, saved views and Save view, and the archive's trash.
///
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class LibraryScreenSmokeTests
{
[Test]
public Task EveryLibrarySceneRendersInBothThemes() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
await app.Sample.FillAsync();
await app.Shell.Services.Server.RestoreAsync();
await app.Shell.Services.Sync.RefreshAsync();
var library = app.Shell.Library;
await LibraryScenes.ShowAsync(app.Shell, "timeline");
Assert.True(library.IsTimeline, "the timeline shows its bands");
Assert.True(library.IsGrid, "the cards stay under the bands");
Assert.Equal(2, library.TimelineBands.Count, "one band per year, 2026 and 2025, the server's sequences included");
Assert.True(library.TimelineBand >= 0 && library.TimelineSlot >= 0, "the chosen month is outlined");
Assert.True(library.IsYearFiltered, "a month narrows the Library to its year");
await app.ExpectAsync("library-timeline", waitForThumbnails: true);
var bands = Assert.NotNull(app.FindAll().FirstOrDefault(t => t.IsVisible && t.ActualHeight > 0), "the bands are drawn");
Assert.True(bands.Focusable, "the keyboard reaches the months");
// Without the mouse: Enter on the month under the keyboard narrows the Library to its year.
library.ClearFiltersCommand.Execute(null);
await library.RefreshAsync();
Assert.Equal(-1, library.TimelineBand);
bands.Focus();
Press(bands, Key.Enter);
await library.RefreshAsync();
Assert.True(library.TimelineBand >= 0 && library.TimelineSlot >= 0, "Enter chose a month");
Assert.True(library.IsYearFiltered, "the year filter follows the band");
await LibraryScenes.ShowAsync(app.Shell, "mass");
Assert.Equal(LibraryScenes.MassSelection, library.SelectionCount);
await app.ExpectAsync("library-mass", waitForThumbnails: true);
foreach (var command in new[] { library.AnalyseCommand, library.ProxiesCommand, library.VerifyCommand, library.TagCommand, library.MoveCommand,
library.ExportListCommand, library.DeleteCommand })
Assert.True(ButtonFor(app, command).IsEnabled, "the bar's archive actions work on sequences of this PC");
Assert.True(library.CanRate);
var request = Assert.NotNull(await LibraryScenes.DeleteRequestAsync(app.Shell), "the dry run moves something");
Assert.True(request.IsDestructive);
Assert.NotNull(request.TypedConfirmation);
var dialog = new ConfirmDialog(request) { WindowStartupLocation = WindowStartupLocation.Manual, Left = -20000, Top = -20000, ShowActivated = false };
dialog.Show();
try
{
dialog.UpdateLayout();
var action = Find