"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StateParser = void 0;
var StateParser = /** @class */ (function () {
    function StateParser() {
    }
    StateParser.prototype.onStart = function () {
        this.state = {};
    };
    StateParser.prototype.parseModule = function (pageId, mod) {
        var _a;
        var stateObj = ((_a = mod.exports) === null || _a === void 0 ? void 0 : _a.default) || mod.exports;
        if (typeof stateObj === 'object') {
            // FIXME
            var plain = JSON.parse(JSON.stringify(stateObj)); // Creating observable from object defined in another context(lowcode state is executed in the iframe) will fail
            this.state[pageId] = plain;
        }
        else if (typeof stateObj === 'function') {
            var plain = JSON.parse(JSON.stringify(stateObj.call())); // Creating observable from object defined in another context(lowcode state is executed in the iframe) will fail
            this.state[pageId] = plain;
        }
        else {
            throw new Error('state must export an object or function');
        }
    };
    StateParser.prototype.onEnd = function (context) {
        context.state = this.state;
    };
    return StateParser;
}());
exports.StateParser = StateParser;
//# sourceMappingURL=stateParser.js.map