function getBreadcrumbCss() {
    return `
  .planu-breadcrumbs {
    font-size: 0.82rem;
    color: #6b7280;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .planu-breadcrumbs a {
    color: var(--planu-info, #3498db);
    text-decoration: none;
  }
  .planu-breadcrumbs a:hover { text-decoration: underline; }
  .planu-breadcrumbs .sep { color: #9ca3af; }
  .planu-breadcrumbs .current { color: #374151; font-weight: 500; }
  .planu-spec-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-top: 24px;
    border-top: 1px solid #e5e7eb;
    font-size: 0.82rem;
    gap: 8px;
  }
  .planu-spec-nav a {
    color: var(--planu-info, #3498db);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    transition: background 0.15s;
  }
  .planu-spec-nav a:hover { background: #f3f4f6; }
  .planu-spec-nav .center-link {
    color: #6b7280;
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
  }
  .planu-spec-nav .center-link:hover { background: #f3f4f6; }
  .planu-spec-nav .spacer { flex: 1; }
  @media print {
    .planu-breadcrumbs, .planu-spec-nav { display: none !important; }
  }`;
}
function escapeHtml(str) {
    return str
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
}
/**
 * Build a breadcrumb trail.
 * Last item is rendered as plain text (current page); all others are links.
 *
 * Example: buildBreadcrumbs([
 *   { label: 'Dashboard', href: '../../index.html' },
 *   { label: 'SPEC-141', href: './executive-report.html' },
 *   { label: 'Executive Report' },
 * ])
 */
export function buildBreadcrumbs(items) {
    if (items.length === 0) {
        return '';
    }
    const parts = items.map((item, idx) => {
        const isLast = idx === items.length - 1;
        if (isLast || !item.href) {
            return `<span class="current">${escapeHtml(item.label)}</span>`;
        }
        return `<a href="${escapeHtml(item.href)}">${escapeHtml(item.label)}</a>`;
    });
    const separator = `<span class="sep" aria-hidden="true">›</span>`;
    const trail = parts.join(` ${separator} `);
    return `<style>${getBreadcrumbCss()}</style>
<nav class="planu-breadcrumbs" aria-label="Breadcrumb">
  ${trail}
</nav>`;
}
/** Extract numeric ID from a spec ID string like "SPEC-141" */
function extractSpecNumber(specId) {
    const m = /SPEC-(\d+)/i.exec(specId);
    return m?.[1] !== undefined ? parseInt(m[1], 10) : 0;
}
/**
 * Extracts the folder slug from a spec ID + array of known spec IDs mapped to folder names.
 * Since we only have IDs, we return the neighbouring ID and caller must compute the path.
 */
function findNeighbours(currentSpecId, allSpecIds) {
    const currentNum = extractSpecNumber(currentSpecId);
    // Sort all IDs numerically
    const sorted = [...allSpecIds].sort((a, b) => extractSpecNumber(a) - extractSpecNumber(b));
    const currentIdx = sorted.findIndex((id) => extractSpecNumber(id) === currentNum);
    if (currentIdx === -1) {
        return { prev: null, next: null };
    }
    /* v8 ignore next 4 */
    return {
        prev: currentIdx > 0 ? (sorted[currentIdx - 1] ?? null) : null,
        next: currentIdx < sorted.length - 1 ? (sorted[currentIdx + 1] ?? null) : null,
    };
}
/**
 * Build prev/next spec navigation links shown at the bottom of per-spec reports.
 *
 * @param currentSpecId - e.g. "SPEC-141"
 * @param allSpecIds - All known spec IDs (used to find neighbours by numeric order).
 * @param basePath - Path from current file to planu/specs/ directory, e.g. "../".
 *                   Each neighbour link appends "{SPEC-ID-slug}/executive-report.html"
 *                   but since we only have IDs (not slugs), we use the ID as-is.
 *                   Callers can pass slug-aware paths if needed.
 * @param reportFilename - The report file to link to in neighbour specs (e.g. "executive-report.html").
 * @param specFolderFn - Optional function to resolve spec ID → folder name. Defaults to identity.
 */
export function buildSpecNavigation(currentSpecId, allSpecIds, basePath, reportFilename = 'executive-report.html', specFolderFn) {
    if (allSpecIds.length === 0) {
        return '';
    }
    const { prev, next } = findNeighbours(currentSpecId, allSpecIds);
    const resolveFolder = specFolderFn ?? ((id) => id);
    const prevLink = prev
        ? `<a href="${escapeHtml(basePath)}${escapeHtml(resolveFolder(prev))}/${escapeHtml(reportFilename)}">← ${escapeHtml(prev)}</a>`
        : `<span style="opacity:0.3">← Prev</span>`;
    const nextLink = next
        ? `<a href="${escapeHtml(basePath)}${escapeHtml(resolveFolder(next))}/${escapeHtml(reportFilename)}">${escapeHtml(next)} →</a>`
        : `<span style="opacity:0.3">Next →</span>`;
    const dashboardHref = `${escapeHtml(basePath)}../index.html`;
    return `<div class="planu-spec-nav">
  ${prevLink}
  <a href="${dashboardHref}" class="center-link">📋 Dashboard</a>
  ${nextLink}
</div>`;
}
//# sourceMappingURL=portal-breadcrumbs.js.map