import { MDViewBase } from './mdview-base';
import { ModelTool } from '@ibizstudio/runtime';
/**
 * 表单数据选择视图
 *
 * @export
 * @class FormPickupDataViewBase
 * @extends {MDViewBase}
 * @implements {FormPickupDataViewInterface}
 */
export class FormPickupDataViewBase extends MDViewBase {
    /**
     * 初始化表单选择数据视图实例
     *
     * @memberof FormPickupDataViewBase
     */
    async viewModelInit() {
        var _a;
        this.viewInstance = ((_a = this.staticProps) === null || _a === void 0 ? void 0 : _a.modeldata);
        await super.viewModelInit();
        this.dataviewInstance = ModelTool.findPSControlByType("DATAVIEW", this.viewInstance.getPSControls());
    }
    /**
     * 处理部件事件
     *
     * @memberof FormPickupDataViewBase
     */
    onCtrlEvent(controlname, action, data) {
        if (Object.is(action, "controlIsMounted")) {
            this.setIsMounted(controlname);
        }
        if (Object.is(action, "selectionchange")) {
            this.$emit('view-event', { action: 'viewdataschange', data: data });
        }
    }
    /**
     *  视图挂载
     *
     * @memberof FormPickupDataViewBase
     */
    viewMounted() {
        super.viewMounted();
        this.viewState.next({ tag: this.dataviewInstance.name, action: 'load', data: this.viewparams });
    }
    /**
     * 监听视图动态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof FormPickupDataViewBase
     */
    onDynamicPropsChange(newVal, oldVal) {
        super.onDynamicPropsChange(newVal, oldVal);
    }
    /**
     * 监听视图静态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof FormPickupDataViewBase
     */
    onStaticPropsChange(newVal, oldVal) {
        this.isSingleSelect = newVal.isSingleSelect;
        super.onStaticPropsChange(newVal, oldVal);
    }
    /**
     * 渲染视图主体内容区
     *
     * @memberof FormPickupDataViewBase
     */
    renderMainContent() {
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.dataviewInstance);
        return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.dataviewInstance.name, on: targetCtrlEvent });
    }
    /**
     * 计算目标部件所需参数
     *
     * @param {string} [controlType]
     * @returns
     * @memberof FormPickupDataViewBase
     */
    computeTargetCtrlData(controlInstance) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance);
        Object.assign(targetCtrlParam.staticProps, {
            isSingleSelect: this.isSingleSelect,
        });
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent };
    }
}
