/**
 * Shared selection + mapping for the llms.txt family of routes (`/llms.txt`,
 * `/llms-full.txt`). Keeping this in one place means the curation rules and the
 * privacy boundary (noindex exclusion) can never drift between the two surfaces.
 */
import { resolveDocumentUrl } from './page-meta.js';
/** Tri-state per-doc include flag; defaults to AUTO for unrecognized values. */
export function readLlmsInclude(data) {
    const v = String(data?.llmsInclude ?? '').toUpperCase();
    return v === 'ALWAYS' || v === 'NEVER' ? v : 'AUTO';
}
/** A doc is excluded from every llms surface when it is noindexed. */
export function isLlmsNoindex(data) {
    const d = data;
    return d?.noindex === true || d?.robotsNoindex === true || d?.noindex === 'true';
}
/**
 * Apply the curation + privacy rules:
 *   - internal/system collections excluded
 *   - noindexed docs excluded (privacy boundary)
 *   - `llmsInclude` NEVER excluded, ALWAYS included (overrides eligibility),
 *     AUTO included only when the collection is eligible
 */
export function selectLlmsDocs(docs, opts) {
    return docs
        .filter((d) => !opts.isInternalCollection(d.collection))
        .filter((d) => {
        const data = d.data || {};
        if (isLlmsNoindex(data))
            return false;
        const include = readLlmsInclude(data);
        if (include === 'NEVER')
            return false;
        if (include === 'ALWAYS')
            return true;
        return opts.eligible ? opts.eligible.has(d.collection) : true;
    });
}
/** Map a selected document to the generator's page shape (curation-aware). */
export function toLlmsPage(d, opts) {
    const data = d.data || {};
    const section = typeof data.llmsSection === 'string' && data.llmsSection.trim()
        ? data.llmsSection.trim()
        : undefined;
    const str = (v) => typeof v === 'string' && v.trim() ? v : undefined;
    return {
        title: str(data.metaTitle) ?? d.title ?? str(data.title) ?? 'Untitled',
        url: resolveDocumentUrl({
            siteUrl: opts.base,
            urlPrefix: opts.urlPrefix,
            slug: d.slug ?? undefined,
            data,
        }),
        description: str(data.llmsDescription) ??
            str(data.keyTakeaway) ??
            str(data.metaDescription) ??
            str(data.seoDescription) ??
            '',
        collection: d.collection,
        section,
        optional: data.llmsOptional === true,
        priority: typeof data.llmsPriority === 'number' ? data.llmsPriority : undefined,
        updatedAt: d.updatedAt?.toISOString(),
        isCornerstone: data.isCornerstone === true,
    };
}
//# sourceMappingURL=llms-select.js.map