using System.Text.Json; using PlotLine.ViewModels; namespace PlotLine.Services; public sealed record ToolbarCommand(string Key, string Label, string IconPath, string Controller, string Action, string Section, bool IsDefault = false, bool RequiresProject = true, bool RequiresBook = false) { public bool IsAvailable(ApplicationNavigationViewModel context) => (!RequiresProject || context.Project is not null) && (!RequiresBook || context.Book is not null); public bool IsActive(string controller, string action, string section) => Key == "review" ? controller == "Onboarding" && (action.StartsWith("StoryIntelligence", StringComparison.Ordinal) || action == "ContinueStoryIntelligence") : Key == "projects" ? controller == "Projects" && action == "Index" : string.Equals(Section, section, StringComparison.OrdinalIgnoreCase); public object RouteValues(ApplicationNavigationViewModel context) => RequiresBook ? new { bookId = context.Book?.BookID } : Key == "overview" ? new { id = context.Project?.ProjectID } : RequiresProject ? new { projectId = context.Project?.ProjectID } : new { }; } public static class ToolbarCommands { public static IReadOnlyList All { get; } = Array.AsReadOnly([ new("overview", "Overview", "M3 3h7v7H3z M14 3h7v7h-7z M3 14h7v7H3z M14 14h7v7h-7z", "Projects", "Details", "Overview", true), new("timeline", "Timeline", "M3 6h18 M3 12h18 M3 18h18 M7 3v6 M15 9v6 M10 15v6", "Timeline", "Index", "Timeline", true), new("calendar", "Calendar", "M4 5h16v16H4z M4 10h16 M8 3v4 M16 3v4 M8 14h2 M14 14h2 M8 18h2", "StoryCalendar", "Index", "Calendar", true), new("characters", "Characters", "M9 3a3 3 0 1 0 0 6 3 3 0 0 0 0-6 M3 21v-4a6 6 0 0 1 12 0v4 M17 4a3 3 0 0 1 0 6 M18 13a5 5 0 0 1 3 5v3", "Characters", "Index", "Characters", true), new("threads", "Threads", "M4 3v18 M4 7h8l6 10h3 M4 17h8l6-10h3", "PlotThreads", "Index", "Threads", true), new("plotlines", "Plot Lines", "M3 5h6l3 4 3-4h6 M3 12h5l4 4 4-4h5 M3 19h8l3-3 3 3h4", "PlotLineWorkspace", "Index", "Plot Lines", true), new("relationships", "Relationships", "M4 4h5v5H4z M15 15h5v5h-5z M15 4h5v5h-5z M9 6h6 M6 9v8h9", "RelationshipMap", "Index", "Relationships", true), new("review", "Review Centre", "M5 3h14v18H5z M8 8l2 2 5-5 M8 14h8 M8 18h6", "Onboarding", "StoryIntelligenceBookReviewCentre", "Review", true, RequiresBook: true), new("locations", "Locations", "M12 21s7-7 7-12a7 7 0 0 0-14 0c0 5 7 12 7 12 M12 6a3 3 0 1 0 0 6 3 3 0 0 0 0-6", "Locations", "Index", "Locations"), new("assets", "Assets", "M3 7l9-4 9 4v11l-9 4-9-4z M3 7l9 4 9-4 M12 11v11", "StoryAssets", "Index", "Assets"), new("names", "Names", "M4 4h16v16H4z M7 8h10 M7 12h7 M7 16h10", "Names", "Index", "Names"), new("point", "At This Point", "M12 3v18 M3 12h18 M12 6a6 6 0 1 0 0 12 6 6 0 0 0 0-12", "StoryPoint", "Index", "At This Point"), new("scenarios", "Scenarios", "M5 3v7l14 7v4 M5 10l14-5V3 M5 10v11", "Scenarios", "Index", "Scenarios"), new("maps", "Maps", "M3 5l6-2 6 2 6-2v16l-6 2-6-2-6 2z M9 3v16 M15 5v16", "Maps", "Index", "Maps"), new("floorplans", "Floor Plans", "M3 3h18v18H3z M3 12h7 M14 12h7 M12 3v6 M12 15v6", "FloorPlans", "Index", "Floor Plans"), new("bible", "Story Bible", "M12 5C8 2 4 3 2 4v16c4-2 7-1 10 1 3-2 6-3 10-1V4c-4-2-7-1-10 1v16", "StoryBible", "Index", "Story Bible"), new("continuity", "Continuity", "M4 5h16 M4 12h16 M4 19h16 M8 3v4 M16 10v4 M10 17v4", "ContinuityExplorer", "Index", "Continuity Explorer"), new("metrics", "Metrics", "M3 3v18h18 M7 17v-5 M12 17V7 M17 17V4", "ProjectMetrics", "Index", "Metrics"), new("health", "Health", "M2 12h5l3-8 4 16 3-8h5", "Analytics", "Index", "Health"), new("warnings", "Warnings", "M12 3L2 21h20z M12 9v5 M12 17v1", "Warnings", "Index", "Warnings"), new("archive", "Archive", "M3 3h18v5H3z M5 8v13h14V8 M9 12h6", "Archives", "Index", "Archive"), new("projects", "Projects", "M3 5h7l2 3h9v13H3z", "Projects", "Index", "Projects", RequiresProject: false), new("writer", "Writer", "M4 20l1-5L17 3l4 4L9 19z M14 6l4 4", "Writer", "Index", "Writer", RequiresProject: false) ]); public static string[] Defaults => All.Where(x => x.IsDefault).Select(x => x.Key).ToArray(); // An explicit ordered list is a complete custom configuration: absent keys are disabled. public static string[] Resolve(string? json) { if (json is null) return Defaults; try { return (JsonSerializer.Deserialize(json) ?? []).Where(key => All.Any(x => x.Key == key)).Distinct().ToArray(); } catch (JsonException) { return Defaults; } } public static bool IsValid(string[] keys) => keys.Length <= All.Count && keys.Distinct().Count() == keys.Length && keys.All(key => All.Any(x => x.Key == key)); }