"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CmptAction = void 0;
var tslib_1 = require("tslib");
var tpl_builtin_1 = require("../utils/tpl-builtin");
var Action_1 = require("./Action");
/**
 * 组件动作
 *
 * @export
 * @class CmptAction
 * @implements {Action}
 */
var CmptAction = /** @class */ (function () {
    function CmptAction() {
    }
    CmptAction.prototype.run = function (action, renderer, event) {
        var _a, _b, _c, _d, _e;
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
            var component, value;
            return (0, tslib_1.__generator)(this, function (_f) {
                component = action.componentId && renderer.props.$schema.id !== action.componentId
                    ? (_a = event.context.scoped) === null || _a === void 0 ? void 0 : _a.getComponentById(action.componentId)
                    : renderer;
                // 显隐&状态控制
                if (['show', 'hidden'].includes(action.actionType)) {
                    return [2 /*return*/, renderer.props.rootStore.setVisible(action.componentId, action.actionType === 'show')];
                }
                else if (['enabled', 'disabled'].includes(action.actionType)) {
                    return [2 /*return*/, renderer.props.rootStore.setDisable(action.componentId, action.actionType === 'disabled')];
                }
                // 数据更新
                if (action.actionType === 'setValue') {
                    value = (0, tpl_builtin_1.dataMapping)(action.value, event.data);
                    if (component.setData) {
                        return [2 /*return*/, component.setData(value)];
                    }
                    else {
                        return [2 /*return*/, (_c = (_b = component.props).onChange) === null || _c === void 0 ? void 0 : _c.call(_b, value)];
                    }
                }
                // 刷新
                if (action.actionType === 'reload') {
                    return [2 /*return*/, (_d = component.reload) === null || _d === void 0 ? void 0 : _d.call(component, undefined, action.args)];
                }
                // 执行组件动作
                return [2 /*return*/, (_e = component.doAction) === null || _e === void 0 ? void 0 : _e.call(component, action, action.args)];
            });
        });
    };
    return CmptAction;
}());
exports.CmptAction = CmptAction;
(0, Action_1.registerAction)('component', new CmptAction());
//# sourceMappingURL=./actions/CmptAction.js.map
