"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.existsIBMapStatic = existsIBMapStatic;
exports.isIBMap = isIBMap;
exports.getIBMapStatic = getIBMapStatic;
exports.destroyIBMapStatic = destroyIBMapStatic;
exports.validMapRegistData = validMapRegistData;
exports.setIBMapLicense = setIBMapLicense;
exports.generateMapID = generateMapID;
exports.generateElementID = generateElementID;
var lodash_1 = require("../shared/lodash");
var dom_utils_1 = require("../shared/dom-utils");
var constant_1 = require("../constant");
function existsIBMapStatic(name) {
    if (name === void 0) { name = constant_1.IBMAP_GLOBAL; }
    return !(0, lodash_1.isNil)((0, lodash_1.get)(window, name));
}
function isIBMap(name) {
    return name === constant_1.IBMAP;
}
function getIBMapStatic(name) {
    if (name === void 0) { name = constant_1.IBMAP_GLOBAL; }
    return (0, lodash_1.get)(window, name);
}
function destroyIBMapStatic(name) {
    if (name === void 0) { name = constant_1.IBMAP_GLOBAL; }
    var ibmap = getIBMapStatic(name);
    try {
        for (var i = 0; i < ibmap.length; i++) {
            ibmap[i].dispose();
        }
        Object.keys(ibmap).forEach(function (key) { return delete ibmap[key]; });
    }
    catch (err) {
        console.warn('IBMap disposeAll failed:', err);
    }
    (0, lodash_1.set)(window, name, undefined);
}
function validMapRegistData(param) {
    if ((0, lodash_1.isString)(param)) {
        return param.indexOf(constant_1.IBMAP) > -1;
    }
    var name = (0, lodash_1.get)(param, 'name');
    if ((0, lodash_1.isNil)(name))
        return false;
    return (0, lodash_1.trim)(name) === constant_1.IBMAP;
}
function setIBMapLicense(value) {
    var _a, _b;
    var ibleaders = (_a = (0, lodash_1.get)(window, 'ibleaders')) !== null && _a !== void 0 ? _a : {};
    (0, lodash_1.set)(window, 'ibleaders', ibleaders);
    var ibmap = (_b = (0, lodash_1.get)(ibleaders, 'ibmap')) !== null && _b !== void 0 ? _b : {};
    (0, lodash_1.set)(ibmap, 'license', value);
    (0, lodash_1.set)(ibleaders, 'ibmap', ibmap);
}
function generateMapID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBMAP_PREFIX);
}
function generateElementID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBMAP_EL_PREFIX);
}
//# sourceMappingURL=utils.js.map