namespace PlotLine.Services; public sealed record RibbonIcon(string Key, string IconPath, string Tone); // Presentation metadata only. Routes, permissions and command execution stay with their owners. public static class RibbonPresentation { public static string Operation(string controller, string action) => $"{controller}.{action}".ToLowerInvariant(); public static string? IconFor(string operation, string? format = null) { operation = operation.ToLowerInvariant(); format = format?.ToLowerInvariant(); if (operation.StartsWith("exports.")) { if (format == "markdown") return "markdown"; if (format == "text") return "text-export"; return operation switch { "exports.storybible" => "print", "exports.narrativetimeline" => "timeline-export", "exports.researchpack" => "research", "exports.projectbackup" => "backup", "exports.writingsession" => "session", _ => "export" }; } if (operation == "timeline.settings" || operation is "manageaccount.index" or "manageaccount.subscription") return "settings"; if (operation == "plotlines.index") return "list"; if (operation == "acceptance.phase1") return "validate"; if (operation == "imports.sample") return "export"; if (operation == "dynamics.knowledge") return "knowledge"; if (operation == "dynamics.character") return "metrics"; if (operation == "dynamics.story") return "health"; if (operation.StartsWith("warnings.validate") || operation == "dynamics.runchecks") return "validate"; if (operation == "projectrestorepoints.index") return "restore"; var action = operation.Split('.').Last(); if (action.StartsWith("reanalyse") || action.StartsWith("retry") || action.StartsWith("regenerate")) return "refresh"; if (action == "save") return "save"; if (action == "edit") return "writer"; if (action.StartsWith("merge")) return "merge"; if (action.StartsWith("delete") || action.StartsWith("remove")) return "remove"; if (action.StartsWith("restore")) return "restore"; if (action.StartsWith("archive")) return "archive"; if (action == "create" && operation is not ("books.create" or "chapters.create")) return "add"; if (action.StartsWith("schedule") || action == "writingplans") return "calendar"; return null; } public static IReadOnlyList AdditionalIcons { get; } = [ new("save", "M4 3h13l4 4v14H3V3z M7 3v6h10V3 M7 21v-7h10v7", "planning"), new("close", "M5 5l14 14 M19 5L5 19", "planning"), new("cut", "M4 3l16 18 M20 3L9 14 M8 17a3 3 0 1 0-6 0 3 3 0 0 0 6 0 M22 17a3 3 0 1 0-6 0 3 3 0 0 0 6 0", "planning"), new("copy", "M8 8h13v13H8z M3 16V3h13", "planning"), new("paste", "M8 5H4v16h16V5h-4 M8 3h8v5H8z M8 12h8 M8 16h6", "planning"), new("select-all", "M3 8V3h5 M16 3h5v5 M21 16v5h-5 M8 21H3v-5 M7 7h10v10H7z", "planning"), new("search", "M20 20l-5-5 M17 10a7 7 0 1 0-14 0 7 7 0 0 0 14 0", "planning"), new("help", "M21 12a9 9 0 1 0-18 0 9 9 0 0 0 18 0 M9.5 9a2.5 2.5 0 0 1 5 0c0 2-2.5 2-2.5 4 M12 17v.01", "books"), new("print", "M6 8V3h12v5 M6 17H3V8h18v9h-3 M6 14h12v7H6z M17 11h1", "planning"), new("markdown", "M4 3h11l5 5v13H4z M15 3v6h5 M7 13l-2 2 2 2 M16 13l2 2-2 2 M12 12l-2 6", "planning"), new("text-export", "M5 3h10l5 5v13H5z M15 3v6h5 M8 12h9 M8 15h9 M8 18h6", "books"), new("timeline-export", "M3 5h14 M3 10h14 M3 15h7 M7 3v4 M12 8v4 M17 13v8 M13 17l4 4 4-4", "calendar"), new("research", "M3 6l8-3 8 3v8 M3 6v12l8 3 M3 6l8 4 8-4 M11 10v6 M22 22l-4-4 M20 16a4 4 0 1 0-8 0 4 4 0 0 0 8 0", "locations"), new("export", "M4 3h10v7 M4 3v18h13v-7 M10 14L21 3 M15 3h6v6", "planning"), new("backup", "M4 3h16v18H4z M8 3v6h8V3 M8 21v-7h8v7", "planning"), new("restore", "M4 8a9 9 0 1 1-1 7 M4 3v5h5 M12 7v6l4 2", "calendar"), new("settings", "M10 3h4l.6 3 2 .9 2.6-1.3 2 3.4-2.3 1.8v2.4l2.3 1.8-2 3.4-2.6-1.3-2 .9-.6 3h-4l-.6-3-2-.9-2.6 1.3-2-3.4L5 13.2v-2.4L2.7 9l2-3.4 2.6 1.3 2-.9z M15 12a3 3 0 1 0-6 0 3 3 0 0 0 6 0", "planning"), new("validate", "M4 3h13v18H4z M8 12l3 3 9-9 M8 6h5", "review"), new("refresh", "M20 9a8 8 0 0 0-14-4 L3 8 M3 3v5h5 M4 15a8 8 0 0 0 14 4l3-3 M16 16h5v5", "review"), new("merge", "M4 3v4l8 7 M20 3v4l-8 7v7 M8 17l4 4 4-4", "relationships"), new("remove", "M3 6h18 M9 6V3h6v3 M5 6l1 15h12l1-15 M10 10v7 M14 10v7", "warning"), new("add", "M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18 M12 7v10 M7 12h10", "planning"), new("list", "M8 5h13 M8 12h13 M8 19h13 M3 5h.01 M3 12h.01 M3 19h.01", "planning"), new("knowledge", "M9 18h6 M10 21h4 M8 14a7 7 0 1 1 8 0l-1 4H9z", "review"), new("session", "M3 4h12v16H3z M7 8h4 M7 12h4 M17 10l4 3-4 3z", "review") ]; public static IEnumerable Icons => ToolbarCommands.All.Select(command => new RibbonIcon(command.Key, command.IconPath, ApplicationRibbon.Tone(command.Key))).Concat(AdditionalIcons); }