using Chronos.App.Infrastructure;
using Chronos.App.Shell;
using Chronos.Data.Copies;
using Chronos.Data.Sync;
namespace Chronos.App.Server.Copies;
///
/// The Matches states that --capture renders (server-copies-<scene>-<theme>.png, design ยง8.7) and the
/// screen smoke tests check, on the sample pairs: the list, the dialog at each part and with each list, the plan with and
/// without a block, the merge of a local pair, the toast of Find matches, and the sync rows a pair marks.
///
public static class CopyScenes
{
/// Scenes shown in the window (dialogs in-window included); the confirmations are separate windows.
public static readonly IReadOnlyList Views =
[
"server-copies", "server-copies-toast", "server-copies-photos", "server-copies-choose", "server-copies-versions",
"server-copies-review", "server-copies-details", "server-copies-projects", "server-copies-plan", "server-copies-blocked",
"server-copies-merge", "server-sync-copyfound", "server-copies-gone",
];
/// The Lighthouse pair (a match found on the server).
public const string Lighthouse = "Lighthouse 2026-08-13";
/// The Alps pair (twice on this PC).
public const string Alps = "Alps 2025";
/// Shows ; returns the dialog it opened, if any.
public static async Task ShowAsync(ShellViewModel shell, string view)
{
var server = shell.Server;
var sync = server.Sync;
var list = sync.Copies;
shell.Navigate(SectionKey.Server);
if (server.Dialog is { } open) server.CloseDialog(open);
sync.SearchText = string.Empty;
await sync.ReloadAsync();
await list.ReloadAsync();
switch (view)
{
case "server-sync-copyfound":
sync.ShowFilter(SyncFilter.All);
return null;
case "server-copies-gone":
sync.ShowFilter(SyncFilter.All, "Garden");
return null;
case "server-copies-toast":
sync.ShowFilter(SyncFilter.FoundCopies);
if (list.Engine is { } engine) list.Announce(await engine.FindAsync(shell.Services.Sync.Remote, CancellationToken.None));
return null;
}
sync.ShowFilter(SyncFilter.FoundCopies);
if (view == "server-copies") return null;
var title = view is "server-copies-versions" or "server-copies-merge" ? Alps : view == "server-copies-review" ? "Bridge works wk 41" : Lighthouse;
if (list.Pairs.FirstOrDefault(p => p.Here.Title == title) is not { } pair) return null;
var (part, photos) = view switch
{
"server-copies-photos" => (CopyDialogPart.Photos, PhotoClass.OnlyHere),
"server-copies-choose" => (CopyDialogPart.Photos, PhotoClass.Differs),
"server-copies-versions" => (CopyDialogPart.Photos, PhotoClass.Versions),
"server-copies-review" => (CopyDialogPart.Photos, PhotoClass.DeletedThere),
"server-copies-details" => (CopyDialogPart.Details, (PhotoClass?)null),
"server-copies-projects" => (CopyDialogPart.Projects, null),
_ => (CopyDialogPart.Plan, null),
};
if (list.Open(pair, part, photos) is not { } dialog) return null;
await dialog.LoadAsync();
switch (view)
{
case "server-copies-choose":
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ChoosePerPhoto);
dialog.SelectedClass = dialog.Classes.FirstOrDefault(c => c.Class == PhotoClass.Differs);
break;
case "server-copies-details":
if (dialog.Details.Count > 0) dialog.Details[0].ChoiceIndex = 0;
break;
case "server-copies-plan":
dialog.AllHereCommand.Execute(null);
dialog.Part = CopyDialogPart.Plan;
break;
}
if (dialog.IsPlan) await dialog.PlanNowAsync();
return dialog;
}
/// "Replace photos?": the Lighthouse plan where this PC's version of the different photos wins.
public static async Task ReplaceRequestAsync(ShellViewModel shell)
{
if (await ShowAsync(shell, "server-copies-plan") is not { } dialog) return null;
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
await dialog.PlanNowAsync();
// Worded as the dialog words it: the plan's server name, else the signed-in one's.
var request = dialog.Plan is { } plan ? dialog.ReplaceRequest(plan) : null;
shell.Server.CloseDialog(dialog);
return request;
}
/// "Merge sequences?": the Alps merge, with the typed photo count.
public static async Task MergeRequestAsync(ShellViewModel shell)
{
if (await ShowAsync(shell, "server-copies-merge") is not { } dialog) return null;
dialog.AllHereCommand.Execute(null);
await dialog.PlanNowAsync();
var request = dialog.MergePlan is { } plan ? dialog.MergeRequest(plan) : null;
shell.Server.CloseDialog(dialog);
return request;
}
/// Back to the sync table with no dialog and no search.
public static void Reset(ShellViewModel shell)
{
if (shell.Server.Dialog is { } open) shell.Server.CloseDialog(open);
shell.Server.Sync.ShowFilter(SyncFilter.All, string.Empty);
}
}