// ─── Schema Reference ────────────────────────────────────────────────
export const PAGE_TREE_SCHEMA_REFERENCE = `
Page Tree Structure Rules:
- Root node: { type: "page", id: string, children: SectionNode[] }
- SectionNode: { type: "section", id: string, settings: SectionSettings, children: (ContainerNode | RowNode)[] }
- ContainerNode: { type: "container", id: string, settings: { maxWidth?: string, alignment?: string, padding?: string }, children: RowNode[] }
- RowNode: { type: "row", id: string, settings: { gap?: string, verticalAlign?: string }, children: ColumnNode[] }
- ColumnNode: { type: "column", id: string, settings: { width: number }, children: (BlockNode | ContainerNode)[] }
- BlockNode: { type: "block", id: string, settings: { blockType: string, variant?: string }, data: Record<string, unknown> }

Column width rules:
- Column widths in a row MUST sum to exactly 12
- Valid single-column widths: 12 (full), 6 (half), 4 (third), 3 (quarter)
- Valid two-column splits: 6+6, 7+5, 8+4, 9+3
- Valid three-column splits: 4+4+4, 6+3+3, 3+6+3

Available block types and their data fields:
- hero: { title, subtitle, image, videoUrl, ctaText, ctaLink, overlayOpacity }
  variants: centered, split-image, video-bg, minimal
- text: { body (richText), heading, headingLevel (h2|h3|h4) }
  variants: prose, two-column, with-sidebar
- image: { src, alt, caption, link, aspectRatio }
  variants: full-width, captioned, rounded, side-by-side
- cards: { items: [{ title, description, image, link, icon }] }
  variants: grid-2, grid-3, grid-4, horizontal
- cta: { heading, body, buttonText, buttonLink, buttonStyle }
  variants: banner, inline, floating, split
- video: { url, poster, autoplay, loop }
  variants: inline, lightbox, background
- gallery: { images: [{ src, alt, caption }] }
  variants: grid, masonry, carousel, lightbox
- faq: { items: [{ question, answer }] }
  variants: accordion, list, two-column
- form: { formId, successMessage }
  variants: contact, newsletter, custom
- code: { content, language (html|javascript|css), sandboxed }
  variants: embed, html, script

Nesting rules:
- page > section > container | row
- container > row
- row > column
- column > block | container
- Never nest blocks inside blocks
- Every id must be unique (use format "node_<random>")
`.trim();
// ─── Prompt Builders ─────────────────────────────────────────────────
function formatBusinessContext(ctx) {
    const parts = [];
    const biz = ctx.context;
    if (!biz)
        return '';
    if (biz.businessName)
        parts.push(`Business name: ${biz.businessName}`);
    if (biz.industry)
        parts.push(`Industry: ${biz.industry}`);
    if (biz.phone)
        parts.push(`Phone: ${biz.phone}`);
    if (biz.address)
        parts.push(`Address: ${biz.address}`);
    if (biz.services?.length)
        parts.push(`Services: ${biz.services.join(', ')}`);
    return parts.length > 0 ? `\nBusiness context:\n${parts.join('\n')}` : '';
}
function formatTone(tone) {
    if (!tone)
        return '';
    return `\nTone: ${tone}. Adjust all copy to match this voice.`;
}
export function buildStructurePrompt(ctx, templateTree) {
    const templateInstruction = templateTree
        ? `\nUse the following page tree as a starting template and adapt it to match the user's request. Modify sections, add or remove blocks as needed:\n${JSON.stringify(templateTree, null, 2)}`
        : '\nGenerate the page tree structure from scratch.';
    return [
        'You are a page builder AI. Generate a valid PageNode JSON tree for a website page.',
        '',
        `User request: ${ctx.prompt}`,
        formatBusinessContext(ctx),
        formatTone(ctx.tone),
        templateInstruction,
        '',
        'Schema reference:',
        PAGE_TREE_SCHEMA_REFERENCE,
        '',
        'Requirements:',
        '- Output ONLY valid JSON matching the schema above.',
        '- Generate unique IDs for every node using the format "node_<random8chars>".',
        '- Column widths in each row must sum to exactly 12.',
        '- Choose appropriate block types and variants for the content described.',
        '- Include at least a hero section and one content section.',
        '- Leave block data fields empty or with brief placeholders — content will be filled in the next step.',
        '- Do not include any explanation or markdown, only the JSON object.',
    ].join('\n');
}
export function buildContentPrompt(ctx, tree) {
    return [
        'You are a content writer AI. Fill in the content for all blocks in the following page tree.',
        '',
        `Original user request: ${ctx.prompt}`,
        formatBusinessContext(ctx),
        formatTone(ctx.tone),
        '',
        'Current page tree (with empty/placeholder block data):',
        JSON.stringify(tree, null, 2),
        '',
        'Instructions:',
        '- Populate the "data" field of every BlockNode with relevant, high-quality content.',
        '- For text blocks: write compelling copy that matches the tone and business context.',
        '- For hero blocks: write a strong headline (title), supporting subtitle, and CTA text.',
        '- For cards blocks: generate 3-4 items with titles and descriptions.',
        '- For CTA blocks: write persuasive heading, body, and button text.',
        '- For FAQ blocks: generate 4-6 relevant questions and answers.',
        '- For image blocks: use descriptive placeholder src values like "/images/hero-bg.jpg" and write proper alt text.',
        '- For gallery blocks: include 4-6 images with descriptive alt text.',
        '- Keep the tree structure EXACTLY the same — only modify "data" fields inside BlockNodes.',
        '- Output ONLY the complete JSON tree with content filled in. No explanation or markdown.',
    ].join('\n');
}
export function buildSEOPrompt(ctx, tree) {
    return [
        'You are an SEO specialist AI. Optimize the following page tree for search engines.',
        '',
        `Original user request: ${ctx.prompt}`,
        formatBusinessContext(ctx),
        '',
        'Current page tree:',
        JSON.stringify(tree, null, 2),
        '',
        'Instructions:',
        '- Ensure the first text or hero block contains the primary keyword in the heading.',
        '- Ensure headings follow proper hierarchy (h2 before h3, no skipping levels).',
        '- Add descriptive alt text to any image blocks missing it.',
        '- Ensure the first paragraph of body content includes the focus keyphrase naturally.',
        '- Keep sentences concise and scannable for readability.',
        '- Do NOT change the tree structure — only modify text content and data fields.',
        '- After the tree JSON, add a "pageSEO" object with: { metaTitle: string, metaDescription: string, focusKeyphrase: string }',
        '- metaTitle should be 50-60 characters and include the primary keyword.',
        '- metaDescription should be 150-160 characters and include a call-to-action.',
        '',
        'Output format:',
        '{ "tree": <PageNode JSON>, "pageSEO": { "metaTitle": "...", "metaDescription": "...", "focusKeyphrase": "..." } }',
        '- Output ONLY the JSON object. No explanation or markdown.',
    ].join('\n');
}
export function buildAccessibilityPrompt(tree) {
    return [
        'You are an accessibility specialist AI. Audit and fix the following page tree for WCAG 2.1 AA compliance.',
        '',
        'Current page tree:',
        JSON.stringify(tree, null, 2),
        '',
        'Check and fix:',
        '- Heading hierarchy: ensure headings go in order (h2 → h3 → h4) with no skipped levels.',
        '- Image alt text: every image block, hero image, and gallery image must have descriptive alt text.',
        '- Form labels: form blocks should reference forms with proper labels.',
        '- CTA/button blocks: ensure button text is descriptive (not just "Click here" or "Submit").',
        '- Link text: avoid generic "Read more" or "Click here" — use descriptive link text.',
        '- Color contrast: if text colors are specified, note any potential contrast issues in changes.',
        '',
        'Output format:',
        '{ "tree": <fixed PageNode JSON>, "changes": ["description of each fix applied"] }',
        '- Output ONLY the JSON object. No explanation or markdown.',
    ].join('\n');
}
//# sourceMappingURL=ai-pipeline.js.map