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

    public String name;

    public String aliases;

    public boolean isHeading() {
        if (name != null) {
            if (com.pullenti.unisharp.Utils.startsWithString(name, "head", true)) 
                return true;
        }
        if (aliases != null) {
            if (com.pullenti.unisharp.Utils.startsWithString(aliases, "head", true)) 
                return true;
            if ((aliases.indexOf("аголовок") >= 0)) 
                return true;
        }
        return false;
    }


    public int calcHeadingLevel() throws NumberFormatException {
        if (!isHeading()) 
            return 0;
        if (aliases != null) {
            for (int i = aliases.length() - 1; i >= 0; i--) {
                if (!Character.isDigit(aliases.charAt(i))) {
                    if ((i + 1) < aliases.length()) 
                        return com.pullenti.unisharp.Utils.parseInteger(aliases.substring(i + 1), 0, null);
                    break;
                }
            }
        }
        if (name != null) {
            for (int i = name.length() - 1; i >= 0; i--) {
                if (!Character.isDigit(name.charAt(i))) {
                    if ((i + 1) < name.length()) 
                        return com.pullenti.unisharp.Utils.parseInteger(name.substring(i + 1), 0, null);
                    break;
                }
            }
        }
        return 0;
    }

    public com.pullenti.unitext.UnitextStyle uStyle = new com.pullenti.unitext.UnitextStyle();

    public String numId;

    public int numLvl;

    public boolean isDefault;

    public String xlsFormat;

    public com.pullenti.unitext.internal.misc.BorderInfo xlsBorder;

    public org.w3c.dom.Node xml;

    public String basedOn;

    public boolean loaded;

    @Override
    public String toString() {
        return name;
    }

    public String correctXlsText(String val) {
        if (com.pullenti.unisharp.Utils.isNullOrEmpty(val) || xlsFormat == null) 
            return val;
        if (com.pullenti.unisharp.Utils.stringsEq(val, "6965606.333333333")) {
        }
        if (com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "22")) {
            int ii = val.indexOf('.');
            String dat = val;
            String tim = null;
            if (ii > 0) {
                dat = val.substring(0, 0 + ii);
                tim = val.substring(ii + 1);
            }
            long lo;
            com.pullenti.unisharp.Outargwrapper<Long> wraplo460 = new com.pullenti.unisharp.Outargwrapper<Long>();
            boolean inoutres461 = com.pullenti.unisharp.Utils.parseLong(dat, 0, null, wraplo460);
            lo = (wraplo460.value != null ? wraplo460.value : 0);
            if (!inoutres461) 
                return val;
            java.time.LocalDateTime dt = java.time.LocalDateTime.of(1900, 1, 1, 0, 0, 0);
            dt = dt.plusDays(((int)lo) - 2);
            String res = (((Integer)dt.getYear()).toString() + "." + String.format("%02d", dt.getMonthValue()) + "." + String.format("%02d", dt.getDayOfMonth()));
            if (tim == null) 
                return res;
            double d;
            com.pullenti.unisharp.Outargwrapper<Double> wrapd458 = new com.pullenti.unisharp.Outargwrapper<Double>();
            boolean inoutres459 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd458);
            d = (wrapd458.value != null ? wrapd458.value : 0);
            if (inoutres459) {
                d *= (86400.0);
                dt = dt.plusSeconds((int)d);
                res = (res + " " + String.format("%02d", dt.getHour()) + ":" + String.format("%02d", dt.getMinute()) + ":" + String.format("%02d", dt.getSecond()));
            }
            return res;
        }
        if ((xlsFormat.indexOf("yyyy") >= 0)) {
            double d;
            com.pullenti.unisharp.Outargwrapper<Double> wrapd462 = new com.pullenti.unisharp.Outargwrapper<Double>();
            boolean inoutres463 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd462);
            d = (wrapd462.value != null ? wrapd462.value : 0);
            if (inoutres463) {
                java.time.LocalDateTime dt = java.time.LocalDateTime.of(1899, 12, 30, 0, 0, 0);
                dt = dt.plusDays((int)d);
                d = d - ((double)((int)d));
                d *= (86400.0);
                dt = dt.plusSeconds((int)d);
                return com.pullenti.util.MiscHelper.outDateTime(dt, false);
            }
        }
        if ((com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "18") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "19") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "20")) || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "21")) {
            double d;
            com.pullenti.unisharp.Outargwrapper<Double> wrapd464 = new com.pullenti.unisharp.Outargwrapper<Double>();
            boolean inoutres465 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd464);
            d = (wrapd464.value != null ? wrapd464.value : 0);
            if (inoutres465) {
                d *= (86400.0);
                java.time.LocalDateTime dt = java.time.LocalDateTime.of(1900, 1, 1, 0, 0, 0);
                dt = dt.plusSeconds((int)d);
                String res = (String.format("%02d", dt.getHour()) + ":" + String.format("%02d", dt.getMinute()));
                if (com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "19") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "21")) 
                    res = (res + ":" + String.format("%02d", dt.getSecond()));
                return res;
            }
        }
        if ((com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "14") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "15") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "6")) || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "17") || (xlsFormat.indexOf("yy") >= 0)) {
            long lo;
            com.pullenti.unisharp.Outargwrapper<Long> wraplo466 = new com.pullenti.unisharp.Outargwrapper<Long>();
            boolean inoutres467 = com.pullenti.unisharp.Utils.parseLong(val, 0, null, wraplo466);
            lo = (wraplo466.value != null ? wraplo466.value : 0);
            if (!inoutres467) 
                return val;
            java.time.LocalDateTime dt = java.time.LocalDateTime.of(1900, 1, 1, 0, 0, 0);
            dt = dt.plusDays(((int)lo) - 2);
            return (((Integer)dt.getYear()).toString() + "." + String.format("%02d", dt.getMonthValue()) + "." + String.format("%02d", dt.getDayOfMonth()));
        }
        if (com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "9") || com.pullenti.unisharp.Utils.stringsEq(xlsFormat, "10")) {
            double d;
            com.pullenti.unisharp.Outargwrapper<Double> wrapd468 = new com.pullenti.unisharp.Outargwrapper<Double>();
            boolean inoutres469 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd468);
            d = (wrapd468.value != null ? wrapd468.value : 0);
            if (inoutres469) 
                return (((Double)com.pullenti.unisharp.Utils.mathRound(d * (100.0), 2)).toString() + "%");
        }
        if ((xlsFormat.indexOf("##") >= 0)) {
            char delim = '.';
            int nn = 0;
            if ((xlsFormat.indexOf("#.##") >= 0)) {
                nn = 2;
                if ((xlsFormat.indexOf("#.###") >= 0)) 
                    nn = 3;
            }
            else if ((xlsFormat.indexOf("#,##") >= 0)) {
                delim = ',';
                nn = 2;
                if ((xlsFormat.indexOf("#,###") >= 0)) 
                    nn = 3;
            }
            if (nn > 0) {
                double d;
                com.pullenti.unisharp.Outargwrapper<Double> wrapd470 = new com.pullenti.unisharp.Outargwrapper<Double>();
                boolean inoutres471 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd470);
                d = (wrapd470.value != null ? wrapd470.value : 0);
                if (inoutres471) {
                    d = com.pullenti.unisharp.Utils.mathRound(d, nn);
                    String val1 = com.pullenti.util.MiscHelper.outDouble(d);
                    int ii = val1.indexOf('.');
                    if (ii < 0) 
                        val1 += (nn == 2 ? ".00" : ".000");
                    else {
                        int kk = val1.length() - ii;
                        for (; kk < nn; kk++) {
                            val1 += "0";
                        }
                    }
                    if (delim == ',') 
                        val1 = val1.replace('.', ',');
                    return val1;
                }
            }
        }
        return val;
    }
    public DocTextStyle() {
    }
}
