"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExcelBody = getExcelBody;
const utils_1 = require("../../utils");
function getExcelBody(rows, op) {
    const { filterColumn } = op;
    const payload = [];
    const header = [];
    const width = [];
    /* ---------- headers + widths ---------- */
    if (typeof filterColumn !== 'undefined') {
        filterColumn.forEach((col) => {
            let colWidth = 20;
            if (col.excelWidth) {
                colWidth = col.excelWidth === 'auto' ? { auto: 1 } : col.excelWidth;
            }
            width.push(colWidth);
            header.push(col.title);
        });
    }
    payload.push(header);
    /* ---------- rows ---------- */
    rows.forEach((rowData) => {
        const row = [];
        if (typeof filterColumn !== 'undefined') {
            filterColumn.forEach((col) => {
                let access = col.data;
                if (col.renderData) {
                    access = col.renderData.data;
                    const type = col.renderData.type ?? 'text';
                    if (type === 'image') {
                        // Excel image handling (optional future feature)
                        // row.push({ image: escapeHtml(getNestedValue(access, rowData)) });
                        row.push('');
                    }
                    else {
                        row.push(utils_1.Str.escapeHtml(utils_1.Str.getNestedValue(access, rowData)));
                    }
                }
                else {
                    row.push(utils_1.Str.escapeHtml(utils_1.Str.getNestedValue(access, rowData)));
                }
            });
        }
        payload.push(row);
    });
    return { payload, width };
}
//# sourceMappingURL=excel.js.map