"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseLoadItems = parseLoadItems;
var constant_1 = require("../../constant");
var lodash_1 = require("../../shared/lodash");
var str_utils_1 = require("../../shared/str-utils");
var registry_1 = require("../../registry");
function parseLoadItemData(data) {
    var registry = this.registry;
    var item;
    if ((0, lodash_1.isString)(data)) {
        if ((0, str_utils_1.isUrlStr)(data)) {
            item = registry.add(data);
        }
        else {
            item = registry.findOne(data);
        }
    }
    else if ((0, lodash_1.isObject)(data)) {
        var itf = (0, registry_1.getRegistryIdentifier)(data);
        if ((0, lodash_1.isNil)(itf)) {
            item = registry.add(data);
        }
        else {
            var alias = itf.alias;
            item = registry.findOne(alias);
            if (!(0, lodash_1.isNil)(item)) {
                console.log("%c[load.parse] updated: ".concat(alias), 'color: royalblue', data);
                item.update(data);
            }
            else {
                item = registry.add(data);
            }
        }
    }
    else {
        if (this.debug) {
            console.warn("not supprted parameter type: ".concat(data));
        }
    }
    return item;
}
function parseLoadItems(loadItems) {
    var _this = this;
    var taskMan = this._loadTaskMan;
    var res = (0, lodash_1.castArray)(loadItems)
        .map(function (data) {
        var item = parseLoadItemData.call(_this, data);
        if ((0, lodash_1.isNil)(item)) {
            console.warn("invalid paramater: ".concat(data));
            return;
        }
        if (item.loaded && !item.changed) {
            if (_this.debug) {
                console.warn("already loaded library: ".concat(item.alias));
            }
            return;
        }
        if (item.name === constant_1.IBSHEET ||
            item.name === constant_1.IBCHART ||
            item.name === constant_1.IBMAP) {
            if (taskMan.exists(item) && !item.changed) {
                return;
            }
        }
        return item;
    })
        .filter(Boolean);
    return res;
}
//# sourceMappingURL=parse-load-items.js.map