import { createHash } from 'node:crypto';
/** Embedded comment marker used to persist spec data hash inside the HTML file. */
export const HASH_MARKER = 'planu-data-hash:';
/**
 * Compute a deterministic SHA-256 hash of the spec data (excluding timestamp).
 * Used to detect whether the underlying data has changed before rewriting the file.
 */
export function computeSpecDataHash(specs, availablePages) {
    const payload = JSON.stringify({
        specs: [...specs]
            .sort((a, b) => a.id.localeCompare(b.id))
            .map((s) => ({
            id: s.id,
            title: s.title,
            status: s.status,
            risk: s.risk,
            tags: s.tags,
            type: s.type,
            estimation: s.estimation,
            specPath: s.specPath,
        })),
        availablePages: [...availablePages].sort(),
    });
    return createHash('sha256').update(payload).digest('hex');
}
/** Extract the embedded hash from existing HTML content, or null if not found. */
export function extractEmbeddedHash(html) {
    const idx = html.indexOf(HASH_MARKER);
    if (idx === -1) {
        return null;
    }
    const start = idx + HASH_MARKER.length + 1; // skip space after marker
    const end = html.indexOf(' -->', start);
    if (end === -1) {
        return null;
    }
    return html.slice(start, end).trim();
}
//# sourceMappingURL=hash-utils.js.map