// Planu — Detects which portal pages exist on disk in planu/
import { access } from 'node:fs/promises';
import { join } from 'node:path';
/**
 * All detectable portal page keys mapped to their filenames within planu/.
 * Order matches the navbar display order.
 */
export const DETECTABLE_PAGES = {
    proposal: 'proposal.html',
    'executive-summary': 'executive-summary.html',
    roadmap: 'roadmap.html',
    analytics: 'analytics.html',
    risks: 'risks.html',
    decisions: 'decisions.html',
    architecture: 'architecture.html',
    changelog: 'changelog.html',
};
/**
 * Check whether a single file exists on disk (non-throwing).
 */
async function fileExists(filePath) {
    try {
        await access(filePath);
        return true;
    }
    catch {
        return false;
    }
}
/**
 * Detect which portal pages currently exist inside planu/.
 * Returns an array of page keys (e.g. ['proposal', 'executive-summary']).
 * The 'dashboard' (index.html) key is intentionally excluded — callers
 * can always assume the dashboard exists.
 *
 * @param portalPath - Absolute path to the planu/ directory.
 */
export async function detectAvailablePages(portalPath) {
    const checks = Object.entries(DETECTABLE_PAGES).map(async ([key, filename]) => {
        const exists = await fileExists(join(portalPath, filename));
        return exists ? key : null;
    });
    const results = await Promise.all(checks);
    return results.filter((key) => key !== null);
}
/**
 * Synchronous variant that accepts a pre-resolved set of existing filenames.
 * Useful in tests or when the filesystem check has already been performed.
 *
 * @param existingFilenames - Set or array of filenames that exist (e.g. ['proposal.html']).
 */
export function detectAvailablePagesSync(existingFilenames) {
    const filenameSet = new Set(existingFilenames);
    return Object.entries(DETECTABLE_PAGES)
        .filter(([, filename]) => filenameSet.has(filename))
        .map(([key]) => key);
}
//# sourceMappingURL=portal-page-detector.js.map