/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */


const UnitextTable = require("./../../UnitextTable");

/**
 * Это для поддержки генерации таблиц из модели COLSPAN + ROWSPAN
 */
class UnitextGenTable {
    
    constructor() {
        this.cells = new Array();
        this.m_ColWidth = new Array();
        this.mayHasError = false;
    }
    
    convert() {
        let res = new UnitextTable();
        res.mayHasError = this.mayHasError;
        for (let c = 0; c < this.m_ColWidth.length; c++) {
            res.setColWidth(c, this.m_ColWidth[c]);
        }
        for (let r = 0; r < this.cells.length; r++) {
            let cn = 0;
            for (const cc of this.cells[r]) {
                for (; ; cn++) {
                    if (res.getCell(r, cn) === null) 
                        break;
                }
                res.addCell(r, (r + cc.rowSpan) - 1, cn, (cn + cc.colSpan) - 1, cc.content, false);
                if (cc.width !== null && cc.colSpan <= 1 && res.getColWidth(cn) === null) {
                    if (cc.width !== null) 
                        res.setColWidth(cn, cc.width);
                    else if ((cc.content instanceof UnitextTable) && cc.content.width !== null) 
                        res.setColWidth(cn, cc.content.width);
                }
                cn += cc.colSpan;
            }
        }
        return res;
    }
}


module.exports = UnitextGenTable