/*
 * 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
 */

package com.pullenti.unitext;

/**
 * Элемент сегмента страниц
 */
public class UnitextPagesectionItem extends UnitextItem {

    /**
     * Footer или Header
     */
    public boolean isFooter;

    /**
     * К каким страницам относится
     */
    public UnitextPagesectionItemPages pages = UnitextPagesectionItemPages.DEFAULT;

    /**
     * Содержимое
     */
    public UnitextItem content;

    @Override
    public String toString() {
        return ((isFooter ? "Footer" : "Header") + " pages=" + pages.toString().toLowerCase());
    }

    @Override
    public UnitextItem clone() {
        UnitextPagesectionItem res = new UnitextPagesectionItem();
        res._cloneFrom(this);
        res.isFooter = isFooter;
        res.pages = pages;
        if (content != null) {
            res.content = content.clone();
            res.content.parent = res;
        }
        return res;
    }

    @Override
    public void getXml(com.pullenti.unisharp.XmlWriterWrapper xml) throws javax.xml.stream.XMLStreamException {
        xml.wr.writeStartElement("sectionitem");
        this._writeXmlAttrs(xml);
        xml.wr.writeAttribute("type", (isFooter ? "footer" : "header"));
        xml.wr.writeAttribute("pages", pages.toString().toLowerCase());
        if (content != null) {
            xml.wr.writeStartElement("content");
            content.getXml(xml);
            xml.wr.writeEndElement();
            if (content.m_StyledFrag != null) 
                content.m_StyledFrag.getXml(xml, null, false);
        }
        xml.wr.writeEndElement();
    }

    @Override
    public void fromXml(org.w3c.dom.Node xml) throws NumberFormatException {
        UnitextDocument doc = null;
        for (UnitextItem it = this; it != null; it = it.parent) {
            if (it instanceof UnitextDocument) 
                doc = (UnitextDocument)com.pullenti.unisharp.Utils.cast(it, UnitextDocument.class);
        }
        super.fromXml(xml);
        for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xml.getAttributes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "type")) 
                isFooter = com.pullenti.unisharp.Utils.stringsEq(a.getNodeValue(), "footer");
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "pages")) {
                try {
                    pages = (UnitextPagesectionItemPages)UnitextPagesectionItemPages.of(a.getNodeValue());
                } catch (Exception ex621) {
                }
            }
        }
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "content")) {
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x.getChildNodes())).arr) {
                    content = com.pullenti.unitext.internal.uni.UnitextHelper.createItem(xx, this);
                    if (content != null) 
                        content.parent = this;
                    break;
                }
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "stylefrag") && content != null) {
                content.m_StyledFrag = new UnitextStyledFragment();
                content.m_StyledFrag.setDoc(doc);
                content.m_StyledFrag.fromXml(x);
            }
        }
    }

    @Override
    public void getAllItems(java.util.ArrayList<UnitextItem> res, int lev) {
        if (res != null) 
            res.add(this);
        if (content != null) {
            content.parent = this;
            content.getAllItems(res, lev + 1);
        }
    }

    public static UnitextPagesectionItem _new48(UnitextItem _arg1) {
        UnitextPagesectionItem res = new UnitextPagesectionItem();
        res.content = _arg1;
        return res;
    }

    public static UnitextPagesectionItem _new49(boolean _arg1, UnitextItem _arg2) {
        UnitextPagesectionItem res = new UnitextPagesectionItem();
        res.isFooter = _arg1;
        res.content = _arg2;
        return res;
    }

    public static UnitextPagesectionItem _new277(UnitextItem _arg1, boolean _arg2) {
        UnitextPagesectionItem res = new UnitextPagesectionItem();
        res.content = _arg1;
        res.isFooter = _arg2;
        return res;
    }
    public UnitextPagesectionItem() {
        super();
    }
}
