import { z } from 'zod';
/**
 * Frontmatter Schema for MDX Documentation Pages
 * 
 * Defines the structure and validation for page metadata
 * Compatible with Mintlify-style frontmatter
 */ export const frontmatterSchema = z.object({
    // Core metadata
    title: z.string(),
    description: z.string().optional(),
    // Navigation
    sidebarTitle: z.string().optional(),
    icon: z.string().optional(),
    // Page behavior
    // - 'default': Standard documentation page with max-width container
    // - 'wide': Wide container for content that needs more space
    // - 'custom': Full-width custom layout (no container, no header) - for landing pages
    mode: z.enum([
        'default',
        'wide',
        'custom'
    ]).optional(),
    // Custom page options (only used when mode: 'custom')
    // Hides the default page header (title & description)
    hideHeader: z.boolean().optional(),
    // Full-width layout without container constraints
    fullWidth: z.boolean().optional(),
    // Custom background color or gradient
    background: z.string().optional(),
    // OpenAPI integration
    openapi: z.string().optional(),
    api: z.string().optional(),
    // SEO
    'og:title': z.string().optional(),
    'og:description': z.string().optional(),
    'og:image': z.string().optional(),
    'twitter:title': z.string().optional(),
    'twitter:description': z.string().optional(),
    // Visibility
    hidden: z.boolean().optional(),
    noindex: z.boolean().optional(),
    // Version/Status
    version: z.string().optional(),
    deprecated: z.boolean().optional()
});
/**
 * Parse and validate frontmatter data
 * Returns the validated data or throws an error with details
 */ export function parseFrontmatter(data) {
    const result = frontmatterSchema.safeParse(data);
    if (!result.success) {
        const issues = result.error.issues || [];
        const errors = issues.map((e)=>`${e.path.map(String).join('.')}: ${e.message}`).join('\n');
        throw new Error(`Invalid frontmatter:\n${errors}`);
    }
    return result.data;
}
/**
 * Safe parse that returns null on failure instead of throwing
 */ export function safeParseFrontmatter(data) {
    const result = frontmatterSchema.safeParse(data);
    return result.success ? result.data : null;
}
/**
 * Get default frontmatter values
 */ export function getDefaultFrontmatter() {
    return {
        mode: 'default',
        hidden: false,
        noindex: false,
        deprecated: false
    };
}
