using Chronos.App.Library;
using Chronos.Core.Localization;
using Chronos.Data.Workspaces;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Workspace;
///
/// A project of the workspace in Edit's picker (owner review 2, R8): its name, its sequence (title and thumbnail; a server's
/// as the Library lists it, phase 5b) and where it stands, a chip read from its home after the list shows and again when
/// the home tells it changed. A copy whose working state cannot be read is listed as damaged, one a newer Chronos wrote
/// as such, by the name each is still known by.
///
public sealed class WorkspaceProjectItem(WorkspaceEntry entry, SequenceItem? sequence) : ObservableObject
{
private WorkspaceStatus? _status;
public WorkspaceEntry Entry { get; } = entry;
/// The sequence's row of the library, for its thumbnail; null when the index no longer has it.
public SequenceItem? Sequence { get; } = sequence;
public Guid ProjectId => Entry.ProjectId;
public Guid SequenceId => Entry.SequenceId;
/// The project's name (Main in the UI language).
public string Name => WorkspaceText.ProjectName(Entry.Name, Entry.IsMain);
public string SequenceTitle => Sequence?.Title ?? Entry.SequenceTitle;
public WorkspaceStatus? Status
{
get => _status;
set
{
if (!Set(ref _status, value)) return;
OnPropertyChanged(nameof(StateText));
OnPropertyChanged(nameof(StateKind));
OnPropertyChanged(nameof(StateToolTip));
OnPropertyChanged(nameof(Description));
}
}
/// Its working state cannot be read: it cannot open, and Remove local copy keeps its files aside.
public bool IsDamaged => Entry.Damaged;
/// A newer Chronos wrote its working state: it neither opens nor goes from here, and stays as it is.
public bool IsNewer => Entry.Newer;
/// This Chronos reads its working state: it opens, and its state is asked of its home.
public bool IsReadable => Entry.IsReadable;
public string StateText => Entry.Newer ? Loc.L("Editor.Workspace.State.NewerCopy")
: Entry.Damaged ? Loc.L("Editor.Workspace.State.Damaged")
: Entry.HasMedia || _status is not null ? WorkspaceText.State(_status, server: Entry.IsServerHome) : Loc.L("Editor.Workspace.State.MediaRemoved");
public StatusKind StateKind => Entry.Newer ? StatusKind.Warning
: Entry.Damaged ? StatusKind.Error
: Entry.HasMedia || _status is not null ? WorkspaceText.Kind(_status) : StatusKind.NoProxies;
public string StateToolTip => Entry.Newer ? Loc.L("Tooltips.Editor.Workspace.State.NewerCopy")
: Entry.Damaged ? Loc.L("Tooltips.Editor.Workspace.State.DamagedCopy")
: Entry.HasMedia || _status is not null ? WorkspaceText.StateToolTip(_status, server: Entry.IsServerHome) : Loc.L("Tooltips.Editor.Workspace.State.MediaRemoved");
/// "Vertical social · Harbour sunset · In sync": what screen readers hear for the row.
public string Description => string.Join(Loc.Separator, Name, SequenceTitle, StateText);
public override string ToString() => Name;
internal void Refresh() => OnAllPropertiesChanged();
}