/*
 * 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 UnitextItem = require("./UnitextItem");
const UnitextMiscType = require("./UnitextMiscType");

/**
 * Разные нетекстовые элементы
 */
class UnitextMisc extends UnitextItem {
    
    constructor() {
        super();
        this.typ = UnitextMiscType.UNDEFINED;
    }
    
    toString() {
        if (this.typ === UnitextMiscType.ANCHOR) 
            return (this.typ.toString() + ": " + ((this.id != null ? this.id : "")));
        return this.typ.toString();
    }
    
    get innerTag() {
        return "misc";
    }
    
    clone() {
        let res = new UnitextMisc();
        res._cloneFrom(this);
        res.typ = this.typ;
        return res;
    }
    
    getPlaintext(res, pars) {
        if (pars !== null && pars.setPositions) 
            this.beginChar = (this.endChar = res.length);
    }
    
    getHtml(res, par) {
        if (!par.callBefore(this, res)) 
            return;
        if (this.id !== null) 
            res.append("<a name=\"").append(this.id).append("\"> </a>");
        if (this.typ === UnitextMiscType.HORIZONTALLINE) 
            res.append("\r\n<HR/>");
        par.callAfter(this, res);
    }
    
    getXml(xml) {
        xml.writeStartElement("misc");
        this._writeXmlAttrs(xml);
        xml.writeAttributeString("type", this.typ.toString().toLowerCase());
        xml.writeEndElement();
    }
    
    fromXml(xml) {
        super.fromXml(xml);
        if (xml.attributes !== null) {
            for (const a of xml.attributes) {
                if (a.local_name === "type") {
                    try {
                        this.typ = UnitextMiscType.of(a.value);
                    } catch (ex614) {
                    }
                }
            }
        }
    }
    
    get isWhitespaces() {
        return false;
    }
    
    static _new286(_arg1) {
        let res = new UnitextMisc();
        res.typ = _arg1;
        return res;
    }
}


module.exports = UnitextMisc