"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    SchemaSettings: function() {
        return SchemaSettings;
    }
});
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class SchemaSettings {
    get items() {
        return this.options.items;
    }
    add(name, item) {
        const arr = name.split('.');
        const data = {
            ...item,
            name: arr[arr.length - 1]
        };
        if (1 === arr.length) {
            const index = this.items.findIndex((item)=>item.name === name);
            if (-1 === index) this.items.push(data);
            else this.items[index] = data;
            return;
        }
        const parentName = arr.slice(0, -1).join('.');
        const parentItem = this.get(parentName);
        if (parentItem) {
            if (!parentItem.children) parentItem.children = [];
            const index = parentItem.children.findIndex((item)=>item.name === name);
            if (-1 === index) parentItem.children.push(data);
            else parentItem.children[index] = data;
        }
    }
    get(nestedName) {
        const arr = nestedName.split('.');
        let current = this.items;
        for(let i = 0; i < arr.length; i++){
            const name = arr[i];
            current = current.find((item)=>item.name === name);
            if (!current || i === arr.length - 1) break;
            if (!current.children) return;
            current = current.children;
        }
        return current;
    }
    remove(nestedName) {
        const arr = nestedName.split('.');
        if (1 === arr.length) {
            const index = this.items.findIndex((item)=>item.name === arr[0]);
            if (-1 !== index) this.items.splice(index, 1);
            return;
        }
        const parent = this.get(arr.slice(0, -1).join('.'));
        if (parent && parent.children) {
            const name = arr[arr.length - 1];
            const index = parent.children.findIndex((item)=>item.name === name);
            if (-1 !== index) parent.children.splice(index, 1);
        }
    }
    constructor(options){
        _define_property(this, "options", void 0);
        _define_property(this, "name", void 0);
        this.options = Object.assign({
            items: []
        }, options);
        this.name = options.name;
    }
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
