/**
 * Pure user-turn section builders. They render host-supplied submit
 * enrichments into LLM-only `TextContent` blocks; the query itself remains
 * owned by `build-user-message.ts`.
 *
 * This file is intentionally separate from `sections.ts`: that module owns
 * system-prompt sections, while this one owns per-submit user context.
 */
const textBlock = (text) => ({ type: 'text', text });
/** Render the workbook-summary block. Empty or missing summaries are omitted. */
export function buildWorkbookSummaryBlock(summary) {
    if (!summary || summary.length === 0)
        return null;
    return textBlock(`\n# Brief summary of the current active workbook and sheets *(NOT an attachment)*\n\n${summary}\n`);
}
/**
 * Render the focused-range block. It supports sheet-only focus, range focus
 * with optional inline data, and an optional chart name.
 */
export function buildFocusedRangeBlock(focus) {
    if (!focus)
        return null;
    const range = (focus.range ?? '').trim();
    const data = focus.data ?? '';
    const dataSection = data.trim().length > 0 ? `\n\nData in this range is shown below:\n\n${data}` : '';
    let focusText;
    if (range.length === 0) {
        focusText = `The user has clicked into the ${focus.sheet} sheet.${dataSection}`;
    }
    else {
        const rangeStr = `${focus.sheet}!${focus.range}`;
        focusText = `The user has clicked on the following range: ${rangeStr}.${dataSection}`;
    }
    if (focus.chartName) {
        focusText += ` Selected chart: "${focus.chartName}".`;
    }
    focusText += `\n\nThis may or may not be related to the current task.`;
    return textBlock(`\n# User Focus\n${focusText}\n`);
}
/**
 * Render range restrictions as either a hard edit boundary or enhanced
 * context. Mixed modes intentionally follow the first restriction so the
 * entire block has one clear instruction.
 */
export function buildRangeRestrictionsBlock(restrictions) {
    if (!restrictions || restrictions.length === 0)
        return null;
    const plural = restrictions.length > 1 ? 's' : '';
    const thisThese = restrictions.length > 1 ? 'these' : 'this';
    // One bullet per allowed/context range.
    const rangeList = restrictions.map((r) => `- ${r.sheet}!${r.range}`).join('\n');
    // Include data only for restrictions that carry non-empty inline values.
    const populated = restrictions.filter((r) => {
        const d = r.data ?? '';
        return d.trim().length > 0;
    });
    let dataSection = '';
    if (populated.length > 0) {
        const rangeData = populated
            .map((r) => `**${r.sheet}!${r.range}:**\n${r.data ?? ''}`)
            .join('\n\n');
        dataSection = `\n\nCurrent data in ${thisThese} range${plural}:\n\n${rangeData}`;
    }
    const mode = restrictions[0]?.mode ?? 'enhanced';
    if (mode === 'restricted') {
        return textBlock(`\n# Critical Restriction\n` +
            `You MUST ONLY edit cells in the following range${plural}. Do NOT modify, write to, or change ANY other cells in the workbook.\n\n` +
            `${rangeList}${dataSection}\n\n` +
            `⚠️ IMPORTANT: You are STRICTLY PROHIBITED from editing any cells outside of the range${plural} listed above. If the task requires editing other cells, you must inform the user that it cannot be completed with the current restrictions.\n`);
    }
    return textBlock(`\n# Enhanced Context\n` +
        `The following range${plural} provided as primary context for your task:\n\n` +
        `${rangeList}${dataSection}\n\n` +
        `You can read from and write to these cells, and you can also edit other cells in the workbook as needed to complete the task.\n`);
}
/**
 * Render the multi-turn context-update warning block.
 *
 * Eligibility is a caller decision: the composer invokes this only when prior
 * transcript state means the spreadsheet may have changed since earlier turns.
 */
export function buildContextUpdateWarningBlock() {
    return textBlock(`\n⚠️ User may have modified spreadsheet. Focus ONLY on current request - abandon previous directives unless explicitly referenced.\n\n` +
        `Make surgical edits to explicitly requested cells only. When deleting/moving data, check dependent cells and update formulas/styling accordingly.\n`);
}
//# sourceMappingURL=user-turn-sections.js.map