/*
 * 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.internal.word;

public class DocSection {

    public com.pullenti.unitext.UnitextPagesection uSect = new com.pullenti.unitext.UnitextPagesection();

    public boolean titlePg;

    public boolean loaded = false;

    public java.util.HashMap<com.pullenti.unitext.UnitextPagesectionItemPages, String> headIds = new java.util.HashMap<com.pullenti.unitext.UnitextPagesectionItemPages, String>();

    public java.util.HashMap<com.pullenti.unitext.UnitextPagesectionItemPages, String> footIds = new java.util.HashMap<com.pullenti.unitext.UnitextPagesectionItemPages, String>();

    private static double _readDoubleCm(String str) {
        double d;
        com.pullenti.unisharp.Outargwrapper<Double> wrapd447 = new com.pullenti.unisharp.Outargwrapper<Double>();
        boolean inoutres448 = com.pullenti.util.MiscHelper.tryParseDouble(str, wrapd447);
        d = (wrapd447.value != null ? wrapd447.value : 0);
        if (!inoutres448) 
            return 0.0;
        d /= (20.0);
        d *= 2.54;
        d /= (72.0);
        return com.pullenti.unisharp.Utils.mathRound(d, 2);
    }

    private static String _readAttrVal(org.w3c.dom.Node x, String nam, String nam2) {
        if (x.getAttributes() != null) {
            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam)) 
                    return a.getNodeValue();
                else if (nam2 != null && com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam2)) 
                    return a.getNodeValue();
            }
        }
        return null;
    }

    public void load(org.w3c.dom.Node xml) {
        loaded = true;
        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), "pgSz")) {
                uSect.width = _readDoubleCm(_readAttrVal(x, "w", null));
                uSect.height = _readDoubleCm(_readAttrVal(x, "h", null));
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "pgMar")) {
                uSect.left = _readDoubleCm(_readAttrVal(x, "left", null));
                uSect.right = _readDoubleCm(_readAttrVal(x, "right", null));
                uSect.top = _readDoubleCm(_readAttrVal(x, "top", null));
                uSect.bottom = _readDoubleCm(_readAttrVal(x, "bottom", null));
                uSect.headerHeight = _readDoubleCm(_readAttrVal(x, "header", null));
                uSect.footerHeight = _readDoubleCm(_readAttrVal(x, "footer", null));
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "titlePg")) 
                titlePg = true;
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "headerReference") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "footerReference")) {
                String id = _readAttrVal(x, "id", null);
                String typ = _readAttrVal(x, "type", null);
                com.pullenti.unitext.UnitextPagesectionItemPages ptyp = com.pullenti.unitext.UnitextPagesectionItemPages.DEFAULT;
                if (com.pullenti.unisharp.Utils.stringsCompare(typ, "first", true) == 0) 
                    ptyp = com.pullenti.unitext.UnitextPagesectionItemPages.FIRST;
                else if (com.pullenti.unisharp.Utils.stringsCompare(typ, "even", true) == 0) 
                    ptyp = com.pullenti.unitext.UnitextPagesectionItemPages.EVEN;
                else if (com.pullenti.unisharp.Utils.stringsCompare(typ, "odd", true) == 0) 
                    ptyp = com.pullenti.unitext.UnitextPagesectionItemPages.ODD;
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "headerReference")) {
                    if (!headIds.containsKey(ptyp)) 
                        headIds.put(ptyp, id);
                }
                else if (!footIds.containsKey(ptyp)) 
                    footIds.put(ptyp, id);
            }
        }
    }
    public DocSection() {
    }
}
