import { ModelTool, ReportViewEngine } from '@ibizstudio/runtime';
import { MDViewBase } from './mdview-base';
/**
 * 实体报表视图基类
 *
 * @export
 * @class DeReportViewBase
 * @extends {MDViewBase}
 * @implements {ReportViewInterface}
 */
export class DeReportViewBase extends MDViewBase {
    constructor() {
        super(...arguments);
        /**
         * 报表视图引擎
         *
         * @memberof DeReportViewBase
         */
        this.engine = new ReportViewEngine();
    }
    /**
     * 初始化报表视图实例
     *
     * @param opts
     * @memberof DeReportViewBase
     */
    async viewModelInit() {
        var _a;
        this.viewInstance = ((_a = this.staticProps) === null || _a === void 0 ? void 0 : _a.modeldata);
        await super.viewModelInit();
        this.reportPanelInstance = ModelTool.findPSControlByName('reportpanel', this.viewInstance.getPSControls());
    }
    /**
     * 报表视图引擎初始化
     *
     * @param opts
     * @memberof DeReportViewBase
     */
    engineInit() {
        var _a, _b, _c, _d, _e;
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        if (this.reportPanelInstance) {
            let engineOpts = ({
                view: this,
                parentContainer: this.$parent,
                p2k: '0',
                isLoadDefault: (_a = this.viewInstance) === null || _a === void 0 ? void 0 : _a.loadDefault,
                keyPSDEField: this.appDeCodeName.toLowerCase(),
                majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
                reportpanel: this.$refs[(_b = this.reportPanelInstance) === null || _b === void 0 ? void 0 : _b.name].ctrl,
            });
            if (((_c = this.searchFormInstance) === null || _c === void 0 ? void 0 : _c.name) && this.$refs[this.searchFormInstance.name]) {
                engineOpts.searchform = (this.$refs[this.searchFormInstance.name].ctrl);
            }
            else if (((_d = this.quickSearchFormInstance) === null || _d === void 0 ? void 0 : _d.name) && this.$refs[this.quickSearchFormInstance.name]) {
                engineOpts.searchform = (this.$refs[this.quickSearchFormInstance.name].ctrl);
            }
            if (((_e = this.searchBarInstance) === null || _e === void 0 ? void 0 : _e.name) && this.$refs[this.searchBarInstance.name]) {
                engineOpts.searchbar = (this.$refs[this.searchBarInstance.name].ctrl);
            }
            this.engine.init(engineOpts);
        }
    }
}
