/*
 * 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 Utils = require("./../../../unisharp/Utils");
const RefOutArgWrapper = require("./../../../unisharp/RefOutArgWrapper");

const UnitextGen = require("./../uni/UnitextGen");
const UnitextStyledFragmentType = require("./../../UnitextStyledFragmentType");
const UnitextStyle = require("./../../UnitextStyle");
const UnitextStyledFragment = require("./../../UnitextStyledFragment");

class DocTableCell {
    
    constructor() {
        this.gridNum = 0;
        this.colSpan = 1;
        this.rowSpan = 1;
        this.mergeVert = 0;
        this.text = null;
        this.uni = null;
        this.frag = null;
    }
    
    toString() {
        let txt = this.text;
        if (Utils.isNullOrEmpty(txt) && this.uni !== null) 
            txt = this.uni.getPlaintextString(null);
        return ("N=" + this.gridNum + ", PS=" + this.colSpan + "x" + this.rowSpan + ", V=" + this.mergeVert + " : " + ((txt != null ? txt : "")));
    }
    
    read(own, sfrag, stackNodes) {
        let xml = stackNodes[stackNodes.length - 1];
        if (sfrag !== null) {
            this.frag = UnitextStyledFragment._new448(UnitextStyledFragmentType.TABLECELL, sfrag);
            sfrag.children.push(this.frag);
        }
        for (const x of xml.child_nodes) {
            if (x.local_name === "tcPr") {
                if (this.frag !== null) {
                    let st0 = new UnitextStyle();
                    own.m_Styles.readUnitextStyle(x, st0, false);
                    st0.removeInheritAttrs(this.frag);
                    this.frag.style = own.m_Styles.registerStyle(st0);
                }
                for (const xx of x.child_nodes) {
                    if (xx.local_name === "gridSpan" && xx.attributes !== null && xx.attributes.length === 1) {
                        let cou = 0;
                        let wrapcou455 = new RefOutArgWrapper();
                        let inoutres456 = Utils.tryParseInt(xx.attributes[0].value, wrapcou455);
                        cou = wrapcou455.value;
                        if (inoutres456) {
                            if (cou > 1) 
                                this.colSpan = cou;
                        }
                    }
                    else if (xx.local_name === "vMerge") {
                        this.mergeVert = 1;
                        if (xx.attributes.length > 0 && xx.attributes !== null && xx.attributes[0].value === "restart") 
                            this.mergeVert = 2;
                    }
                }
            }
        }
        let gen = new UnitextGen();
        gen.setStyle(this.frag);
        stackNodes.push(xml);
        own.readNode(stackNodes, gen, this.frag, -1);
        stackNodes.splice(stackNodes.length - 1, 1);
        this.uni = gen.finish(true, null);
    }
}


module.exports = DocTableCell