// ---------------------------------------------------------------------------
// framesToSnapshot — map FigmaFrame[] to FigmaFrameSnapshot[]
// ---------------------------------------------------------------------------
export function framesToSnapshot(frames) {
    return frames.map((f) => ({
        nodeId: f.nodeId,
        name: f.name,
        pageId: f.pageId,
        pageName: f.pageName,
        section: f.section,
    }));
}
// ---------------------------------------------------------------------------
// computeFrameDiff — compare two snapshots and return a diff
// ---------------------------------------------------------------------------
export function computeFrameDiff(previous, current) {
    const previousMap = new Map();
    for (const snap of previous) {
        previousMap.set(snap.nodeId, snap);
    }
    const currentMap = new Map();
    for (const snap of current) {
        currentMap.set(snap.nodeId, snap);
    }
    const added = [];
    const removed = [];
    const renamed = [];
    const moved = [];
    for (const [nodeId, snap] of currentMap) {
        if (!previousMap.has(nodeId)) {
            added.push(snap);
        }
    }
    for (const [nodeId, snap] of previousMap) {
        if (!currentMap.has(nodeId)) {
            removed.push(snap);
        }
    }
    for (const [nodeId, prev] of previousMap) {
        const curr = currentMap.get(nodeId);
        if (curr === undefined) {
            continue;
        }
        if (curr.name !== prev.name) {
            renamed.push({ nodeId, oldName: prev.name, newName: curr.name });
        }
        if (curr.pageName !== prev.pageName) {
            moved.push({ nodeId, oldPageName: prev.pageName, newPageName: curr.pageName });
        }
    }
    const hasChanges = added.length > 0 || removed.length > 0 || renamed.length > 0 || moved.length > 0;
    return { added, removed, renamed, moved, hasChanges };
}
// ---------------------------------------------------------------------------
// formatDiffAsMarkdown — human-readable summary of a FigmaFrameDiff
// ---------------------------------------------------------------------------
export function formatDiffAsMarkdown(diff) {
    if (!diff.hasChanges) {
        return 'No changes detected since last sync.';
    }
    const lines = ['**Figma Changes Detected**', ''];
    if (diff.added.length > 0) {
        const names = diff.added.map((f) => f.name).join(', ');
        lines.push(`Added (${diff.added.length.toString()}): ${names}`);
    }
    if (diff.removed.length > 0) {
        const names = diff.removed.map((f) => f.name).join(', ');
        lines.push(`Removed (${diff.removed.length.toString()}): ${names}`);
    }
    if (diff.renamed.length > 0) {
        const entries = diff.renamed.map((r) => `${r.oldName} → ${r.newName}`).join(', ');
        lines.push(`Renamed (${diff.renamed.length.toString()}): ${entries}`);
    }
    if (diff.moved.length > 0) {
        const entries = diff.moved
            .map((m) => `${m.nodeId} (${m.oldPageName} → ${m.newPageName})`)
            .join(', ');
        lines.push(`Moved (${diff.moved.length.toString()}): ${entries}`);
    }
    return lines.join('\n');
}
//# sourceMappingURL=change-detector.js.map