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

// Стиль нумерации
public class UnitextGenNumStyle implements IUnitextGenNumStyle {

    private String _id;

    @Override
    public String getId() {
        return _id;
    }

    public String setId(String value) {
        _id = value;
        return _id;
    }


    public java.util.ArrayList<UniTextGenNumLevel> levels = new java.util.ArrayList<UniTextGenNumLevel>();

    private int _lvl;

    @Override
    public int getLvl() {
        return _lvl;
    }

    public int setLvl(int value) {
        _lvl = value;
        return _lvl;
    }


    private boolean _isbullet;

    @Override
    public boolean isBullet() {
        return _isbullet;
    }

    public boolean setBullet(boolean value) {
        _isbullet = value;
        return _isbullet;
    }


    private String _txt;

    @Override
    public String getTxt() {
        return _txt;
    }

    public String setTxt(String value) {
        _txt = value;
        return _txt;
    }


    @Override
    public String toString() {
        if (getTxt() != null) 
            return ("Level: " + this.getLvl() + " Val: " + this.getTxt());
        return ("Id: " + this.getId() + " Levels: " + levels.size() + " FirstLevel: " + (levels.size() == 0 ? "" : levels.get(0).toString()));
    }

    private java.util.ArrayList<Integer> nums = new java.util.ArrayList<Integer>();

    public com.pullenti.unitext.UnitextStyle style;

    public UnitextGenNumStyle clone() {
        UnitextGenNumStyle res = new UnitextGenNumStyle();
        res.setId(this.getId());
        res.setLvl(this.getLvl());
        res.setBullet(this.isBullet());
        res.setTxt(this.getTxt());
        if (style != null) 
            res.style = style.clone(false);
        for (UniTextGenNumLevel ll : levels) {
            res.levels.add(ll.clone());
        }
        return res;
    }

    @Override
    public UniTextGenNumLevel getLevel(int lev) {
        if ((lev < 0) || lev >= levels.size()) 
            return null;
        return levels.get(lev);
    }

    @Override
    public String process(int lev, boolean init) {
        if (getTxt() != null) 
            return getTxt();
        if (lev >= levels.size()) 
            return null;
        if (init) 
            nums.clear();
        if (lev >= nums.size()) {
            if (nums.size() == 0) {
                for (int ii = 0; ii <= lev; ii++) {
                    if (ii < levels.size()) 
                        nums.add(levels.get(ii).start);
                    else 
                        nums.add(1);
                }
            }
            else 
                while (lev >= nums.size()) {
                    if (lev < levels.size()) 
                        nums.add(levels.get(lev).start);
                    else 
                        nums.add(1);
                }
        }
        else if (lev == (nums.size() - 1)) {
            com.pullenti.unisharp.Utils.putArrayValue(nums, lev, nums.get(lev) + 1);
            if (nums.get(lev) < levels.get(lev).start) 
                com.pullenti.unisharp.Utils.putArrayValue(nums, lev, levels.get(lev).start);
        }
        else {
            if ((lev + 1) < nums.size()) 
                for(int jjj = lev + 1 + nums.size() - lev - 1 - 1, mmm = lev + 1; jjj >= mmm; jjj--) nums.remove(jjj);
            com.pullenti.unisharp.Utils.putArrayValue(nums, lev, nums.get(lev) + 1);
        }
        String val = (levels.get(lev).format != null ? levels.get(lev).format : "");
        for (int ii = 0; ii <= lev; ii++) {
            if ((val.indexOf("%" + ((ii + 1))) >= 0)) {
                String nn = levels.get(ii).getValue(nums.get(ii));
                if (nn != null) 
                    val = val.replace("%" + ((ii + 1)), nn);
            }
        }
        if (com.pullenti.unisharp.Utils.stringsEq(val, "1.1.1.")) {
        }
        return val;
    }

    public static UnitextGenNumStyle _new110(String _arg1) {
        UnitextGenNumStyle res = new UnitextGenNumStyle();
        res.setId(_arg1);
        return res;
    }
    public UnitextGenNumStyle() {
    }
}
