"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.existsIBSheetStatic = existsIBSheetStatic;
exports.isIBSheet = isIBSheet;
exports.getIBSheetStatic = getIBSheetStatic;
exports.destroyIBSheetStatic = destroyIBSheetStatic;
exports.validSheetRegistData = validSheetRegistData;
exports.setIBSheetLicense = setIBSheetLicense;
exports.generateSheetID = generateSheetID;
exports.generateElementID = generateElementID;
var lodash_1 = require("../shared/lodash");
var dom_utils_1 = require("../shared/dom-utils");
var constant_1 = require("../constant");
function existsIBSheetStatic(name) {
    if (name === void 0) { name = constant_1.IBSHEET_GLOBAL; }
    return !(0, lodash_1.isNil)((0, lodash_1.get)(window, name));
}
function isIBSheet(name) {
    return name === constant_1.IBSHEET;
}
function getIBSheetStatic(name) {
    if (name === void 0) { name = constant_1.IBSHEET_GLOBAL; }
    return (0, lodash_1.get)(window, name);
}
function destroyIBSheetStatic(name) {
    if (name === void 0) { name = constant_1.IBSHEET_GLOBAL; }
    var ibsheet = getIBSheetStatic(name);
    try {
        ibsheet.disposeAll(true, true);
    }
    catch (err) {
        console.warn('IBSheet disposeAll failed:', err);
    }
    (0, lodash_1.set)(window, name, undefined);
}
function validSheetRegistData(param) {
    if ((0, lodash_1.isString)(param)) {
        return param.indexOf(constant_1.IBSHEET) > -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.IBSHEET;
}
function setIBSheetLicense(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 generateSheetID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBSHEET_PREFIX);
}
function generateElementID() {
    return (0, dom_utils_1.genUniqueElementId)(constant_1.IBSHEET_EL_PREFIX);
}
//# sourceMappingURL=utils.js.map