import { EditView3Engine, ModelTool } from '@ibizstudio/runtime';
import { EditViewBase } from './editview-base';
/**
 * 实体编辑视图（分页关系）基类
 *
 * @export
 * @class EditView3Base
 * @extends {EditViewBase}
 * @implements {EditView3Interface}
 */
export class EditView3Base extends EditViewBase {
    constructor() {
        super(...arguments);
        /**
         * 视图引擎
         *
         * @public
         * @type {Engine}
         * @memberof EditView3Base
         */
        this.engine = new EditView3Engine();
        /**
         * 选中数据
         *
         * @type {*}
         * @memberof EditView3Base
         */
        this.selection = {};
    }
    /**
     * 引擎初始化
     *
     * @public
     * @memberof EditView3Base
     */
    engineInit() {
        var _a;
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        this.engine.init({
            view: this,
            parentContainer: this.$parent,
            form: this.$refs[this.editFormInstance.name].ctrl,
            drtab: this.$refs[this.drtabInstance.name].ctrl,
            p2k: '0',
            isLoadDefault: this.viewInstance.loadDefault,
            keyPSDEField: this.appDeCodeName.toLowerCase(),
            majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
        });
        if (this.dataPanelInstance) {
            this.datapanel.init({
                view: this,
                parentContainer: this.$parent,
                datapanel: this.$refs[(_a = this.dataPanelInstance) === null || _a === void 0 ? void 0 : _a.name].ctrl,
                p2k: '0',
                isLoadDefault: this.viewInstance.loadDefault,
                keyPSDEField: this.appDeCodeName.toLowerCase(),
                majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
            });
        }
    }
    /**
     * 初始化编辑视图实例
     *
     * @memberof EditView3Base
     */
    async viewModelInit() {
        await super.viewModelInit();
        this.drtabInstance = ModelTool.findPSControlByName('drtab', this.viewInstance.getPSControls());
    }
    /**
     * 绘制表单
     *
     * @return {*}
     * @memberof EditView3Base
     */
    renderForm() {
        var _a;
        if (!this.editFormInstance) {
            return null;
        }
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.editFormInstance);
        return this.$createElement(targetCtrlName, { slot: 'mainform', props: targetCtrlParam, ref: (_a = this.editFormInstance) === null || _a === void 0 ? void 0 : _a.name, on: targetCtrlEvent });
    }
    /**
     * 渲染视图主体内容区
     *
     * @memberof EditView3Base
     */
    renderMainContent() {
        var _a;
        if (!this.drtabInstance) {
            return null;
        }
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.drtabInstance);
        return this.$createElement(targetCtrlName, {
            slot: 'default',
            props: targetCtrlParam,
            ref: (_a = this.drtabInstance) === null || _a === void 0 ? void 0 : _a.name,
            on: targetCtrlEvent,
        }, [
            this.renderForm(),
        ]);
    }
}
