using System.Windows.Input;
using Titano.Core.Archiving;
using Titano.Core.Localization;
using Titano.Ui.Controls;
using Titano.Ui.Mvvm;
namespace Titano.App.Archiving;
/// A visible row of the archive tree: indentation, expander, title, figures and availability.
public sealed class ArchiveTreeRowViewModel(ArchiveTreeNode node, ArchiveAvailability availability, Action toggle) : ObservableObject
{
public ArchiveTreeNode Node { get; } = node;
public string Title => Node.Title;
public string Detail => Node.Detail;
/// 16 px per level.
public System.Windows.Thickness IndentMargin => new(Node.Depth * 16, 0, 0, 0);
public bool HasChildren => Node.HasChildren;
public bool IsExpanded => Node.IsExpanded;
public bool IsArchive => Node.Kind == TreeNodeKind.Archive;
public bool IsYear => Node.Kind == TreeNodeKind.Year;
public string ToggleToolTip => Loc.L(Node.IsExpanded ? "Tooltips.Archive.Collapse" : "Tooltips.Archive.Expand");
/// The row's figures; a year also says how the keyboard opens and closes it.
public string RowToolTip => IsYear ? Loc.L("Tooltips.Archive.YearRow", Detail) : Detail;
public ICommand ToggleCommand { get; } = new RelayCommand(() => toggle(node));
/// The archive's availability (BRIEF §7: online, read-only, offline) on the archive row.
public StatusKind AvailabilityKind => availability switch
{
ArchiveAvailability.Online => StatusKind.Online,
ArchiveAvailability.ReadOnly => StatusKind.Warning,
_ => StatusKind.Offline,
};
public string AvailabilityText => Loc.L("Archive.Availability." + availability);
public string AvailabilityToolTip => Loc.L("Tooltips.Archive.Availability." + availability);
}
/// A line of "Index health" with its fix.
public sealed class HealthLineViewModel(HealthLine line, ICommand? fix) : ObservableObject
{
public HealthLine Line { get; } = line;
public string Text => Line.Text;
public StatusKind Kind => Line.IsOk ? StatusKind.Done : StatusKind.Warning;
public string KindToolTip => Loc.L(Line.IsOk ? "Tooltips.Archive.HealthOk" : "Tooltips.Archive.HealthWarning");
public bool HasFix => FixCommand is not null && Line.Action != HealthAction.None;
public ICommand? FixCommand { get; } = fix;
public string FixText => HasFix ? Loc.L("Archive.Health.Fix." + Line.Action) : string.Empty;
public string FixToolTip => HasFix ? Loc.L("Tooltips.Archive.Fix." + Line.Action) : string.Empty;
}
/// A duplicate group with its safe actions: open the first copy's sequence, show its folder.
public sealed class DuplicateRowViewModel(DuplicateRow row, ICommand open, ICommand reveal) : ObservableObject
{
public DuplicateRow Row { get; } = row;
public string Places => string.Join(" · ", Row.Places);
public ICommand OpenCommand { get; } = open;
public ICommand RevealCommand { get; } = reveal;
}
/// An orphan line with its fix (index, reconcile, remove the row, scan).
public sealed class OrphanRowViewModel(OrphanRow row, ICommand fix) : ObservableObject
{
public OrphanRow Row { get; } = row;
public StatusKind Kind => Row.Kind is OrphanKind.MissingFiles or OrphanKind.MissingSequence ? StatusKind.Warning : StatusKind.Queued;
public string KindText => Loc.L("Archive.Orphans.Kind." + Row.Kind);
public ICommand FixCommand { get; } = fix;
public string FixText => Loc.L("Archive.Orphans.Fix." + Row.Kind);
public string FixToolTip => Loc.L("Tooltips.Archive.Orphans." + Row.Kind);
}
/// A value of a set filter menu (camera, status, tag): checked while chosen; choosing it again clears it.
public sealed record FilterChoice(string Label, bool IsChecked, ICommand Command);