/**
 * getWorkbookSummary — produce a concise workbook overview for agent context.
 *
 * Calls the public workbook/worksheet APIs and formats the result as a
 * human-readable string that mirrors the OfficeJS workbook summary injected
 * via prePromptContext. This keeps the agent-facing contract simple and avoids
 * coupling the wrapper to internal snapshot methods.
 */
function isObjectRange(range) {
    return !!range && typeof range === 'object';
}
function columnLetter(index) {
    let value = index + 1;
    let result = '';
    while (value > 0) {
        const rem = (value - 1) % 26;
        result = String.fromCharCode(65 + rem) + result;
        value = Math.floor((value - 1) / 26);
    }
    return result;
}
function toA1(row, col) {
    return `${columnLetter(col)}${row + 1}`;
}
function formatUsedRange(range) {
    if (typeof range === 'string')
        return range;
    if (!isObjectRange(range))
        return '(empty)';
    return `${toA1(range.startRow, range.startCol)}:${toA1(range.endRow, range.endCol)}`;
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Build a human-readable workbook summary from the engine snapshot.
 *
 * Output format matches the OfficeJS summary so the agent sees the same context:
 * ```
 * Sheets and their used ranges:
 *   Income Statement: A1:L45 (active)
 *   Balance Sheet: A1:K38
 *   Cash Flow: A1:J52
 * ```
 */
export async function getWorkbookSummary(wb) {
    const workbook = wb;
    const sheetNames = await workbook.getSheetNames();
    const activeSheetName = await workbook.activeSheet.getName();
    const lines = [];
    lines.push('Sheets and their used ranges:');
    for (const sheetName of sheetNames) {
        const sheet = await workbook.getSheet(sheetName);
        const range = formatUsedRange(await sheet.getUsedRange());
        const resolvedSheetName = await sheet.getName();
        const active = resolvedSheetName === activeSheetName ? ' (active)' : '';
        lines.push(`  ${resolvedSheetName}: ${range}${active}`);
    }
    return lines.join('\n');
}
//# sourceMappingURL=workbook-summary.js.map