"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.existsIBChartStatic = existsIBChartStatic;
exports.isIBChart = isIBChart;
exports.getIBChartStatic = getIBChartStatic;
exports.destroyIBChartStatic = destroyIBChartStatic;
exports.validChartRegistData = validChartRegistData;
exports.setIBChartLicense = setIBChartLicense;
exports.generateChartID = generateChartID;
exports.generateElementID = generateElementID;
var lodash_1 = require("../shared/lodash");
var dom_utils_1 = require("../shared/dom-utils");
var constant_1 = require("../constant");
function existsIBChartStatic(name) {
    if (name === void 0) { name = constant_1.IBCHART_GLOBAL; }
    return !(0, lodash_1.isNil)((0, lodash_1.get)(window, name));
}
function isIBChart(name) {
    return name === constant_1.IBCHART;
}
function getIBChartStatic(name) {
    if (name === void 0) { name = constant_1.IBCHART_GLOBAL; }
    return (0, lodash_1.get)(window, name);
}
function destroyIBChartStatic(name) {
    if (name === void 0) { name = constant_1.IBCHART_GLOBAL; }
    var ibchart = getIBChartStatic(name);
    try {
        for (var i = 0; i < ibchart.length; i++) {
            ibchart[i].dispose();
        }
        Object.keys(ibchart).forEach(function (key) { return delete ibchart[key]; });
    }
    catch (err) {
        console.warn('IBChart disposeAll failed:', err);
    }
    (0, lodash_1.set)(window, name, undefined);
}
function validChartRegistData(param) {
    if ((0, lodash_1.isString)(param)) {
        return param.indexOf(constant_1.IBCHART) > -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.IBCHART;
}
function setIBChartLicense(value) {
    var _a;
    var ibleaders = (_a = (0, lodash_1.get)(window, 'ibleaders')) !== null && _a !== void 0 ? _a : {};
    (0, lodash_1.set)(window, 'ibleaders', ibleaders);
    (0, lodash_1.set)(ibleaders, 'license', value);
}
function generateChartID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBCHART_PREFIX);
}
function generateElementID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBCHART_EL_PREFIX);
}
//# sourceMappingURL=utils.js.map