/**
 * Human-readable commit messages for entity + folder mutations.
 *
 * These strings are display-only — nothing parses them for behavior. Restore
 * keys off the commit hash + the entity from the request, and the audit log
 * only records the string. They surface in `git log`, the audit log, MCP file
 * history, and any future cross-entity history view, where the entity name +
 * type IS the useful context.
 *
 * The per-entity History panel renders its own change summary (computed from
 * the file diff) and does NOT show these messages, so we optimize purely for
 * how they read in a flat log.
 *
 * Format decisions:
 *  - Past tense ("Created", "Edited", "Moved") — it's a log of what happened.
 *  - `"Display Title" (Type)` — the title in quotes, the friendly type in parens.
 *  - Batches enumerate up to 3 names + "(+N more)".
 */
/** Cap a title so it can't blow out a one-line subject. */
const MAX_TITLE = 80;
/**
 * Title-case an internal type key for display:
 *   "deal" → "Deal", "meeting_note" → "Meeting Note".
 * Built-in types have no stored label, so this is their friendly name.
 */
export function titleCaseType(type) {
    const cased = type
        .split(/[_-]+/)
        .filter(Boolean)
        .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
        .join(' ');
    return cased || type;
}
/** Collapse whitespace and cap length so a title is safe in a subject line. */
function cleanTitle(title) {
    if (!title)
        return '';
    const flat = String(title).replace(/\s+/g, ' ').trim();
    return flat.length > MAX_TITLE ? `${flat.slice(0, MAX_TITLE - 1)}…` : flat;
}
/** The user-facing name for an entity: cleaned title, or the slug as fallback. */
function displayName(ref) {
    return cleanTitle(ref.title) || ref.id;
}
/** `"Acme Corp Redesign" (Deal)` */
export function entityLabel(ref) {
    return `"${displayName(ref)}" (${ref.typeLabel})`;
}
/** Just the quoted name (no type) — for batch enumeration. */
function quotedName(ref) {
    return `"${displayName(ref)}"`;
}
/** `"A", "B", "C" (+2 more)` — enumerate up to `max` names. */
function enumerateNames(refs, max = 3) {
    const names = refs.map(quotedName);
    if (names.length <= max)
        return names.join(', ');
    return `${names.slice(0, max).join(', ')} (+${names.length - max} more)`;
}
const plural = (n) => (n === 1 ? 'entry' : 'entries');
export const commitMessage = {
    created: (ref) => `Created ${entityLabel(ref)}`,
    edited: (ref) => `Edited ${entityLabel(ref)}`,
    editedBatch: (refs) => `Edited ${enumerateNames(refs)}`,
    deleted: (ref) => `Deleted ${entityLabel(ref)}`,
    deletedBatch: (refs) => `Deleted ${enumerateNames(refs)}`,
    /** Rename changes the slug id; the title may be unchanged, so show the ids. */
    renamed: (typeLabel, oldId, newId) => `Renamed "${oldId}" → "${newId}" (${typeLabel})`,
    changedType: (ref, fromLabel, toLabel) => `Changed ${quotedName(ref)} from ${fromLabel} to ${toLabel}`,
    /** `folder` is the destination path display, or "(root)" for the repo root. */
    movedTo: (ref, folder) => `Moved ${entityLabel(ref)} → ${folder}`,
    /** Bulk move: count + destination reads cleaner than enumerate + target. */
    movedBatch: (count, where) => `Moved ${count} ${plural(count)} → ${where}`,
    receivedBatch: (count, fromRepo) => `Received ${count} ${plural(count)} from ${fromRepo}`,
    restored: (ref, shortHash) => `Restored ${entityLabel(ref)} from ${shortHash}`,
    relinked: (oldId, newId) => `Relinked "${oldId}" → "${newId}"`,
    // Folders are path-based (no type/title).
    folderCreated: (path) => `Created folder "${path}"`,
    folderRenamed: (from, to) => `Renamed folder "${from}" → "${to}"`,
    folderDisplayRenamed: (path) => `Renamed folder "${path}"`,
    folderDeleted: (path) => `Deleted folder "${path}"`,
    folderMoved: (from, toRepo, to) => `Moved folder "${from}" → ${toRepo}:${to || '/'}`,
    folderReceived: (fromRepo, from, to) => `Received folder from ${fromRepo}:${from} → ${to || '/'}`,
};
//# sourceMappingURL=commit-messages.js.map