"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeGlobalVar = exports.initGlobalVar = exports.getEnumOptions = void 0;
var global_api_1 = require("../app/global-api");
var computed_1 = require("./computed");
var mobx_1 = require("mobx");
var weda_client_1 = require("@cloudbase/weda-client");
var adapter_1 = require("./adapter");
var createDataset = weda_client_1._WEDA_CLOUD_SDK.createDataset;
// 防止页面重复引用
var isInit = false;
var options = (0, mobx_1.observable)({});
var loading = {};
function getEnumOptions(optionName) {
    if (options[optionName]) {
        return options[optionName];
    }
    if (!loading[optionName]) {
        loading[optionName] = true;
        (0, weda_client_1._getGeneralOptions)(optionName).then(function (data) {
            var _a;
            options[optionName] = (_a = data === null || data === void 0 ? void 0 : data.Items[0]) === null || _a === void 0 ? void 0 : _a.Config;
        });
    }
    return '';
}
exports.getEnumOptions = getEnumOptions;
function initGlobalVar(_a) {
    var common = _a.common, state = _a.state, computedFuncs = _a.computedFuncs, _b = _a.dataset, dataset = _b === void 0 ? undefined : _b;
    if (!isInit) {
        adapter_1.runtime['$$global'] = adapter_1.runtime['$$global'] || {};
        global_api_1.app.common = common;
        global_api_1.app.state = (0, mobx_1.observable)(state);
        global_api_1.app.computed = (0, computed_1.createComputed)(computedFuncs);
        var _dataset = dataset || createDataset('$global');
        global_api_1.app.dataset = _dataset;
        global_api_1.app.state.dataset = _dataset;
        global_api_1.app.enumOptions = options;
    }
}
exports.initGlobalVar = initGlobalVar;
function removeGlobalVar() {
    isInit = false;
    adapter_1.runtime['$$global'] = undefined;
}
exports.removeGlobalVar = removeGlobalVar;
//# sourceMappingURL=initGlobalVar.js.map