import { MDViewBase } from './mdview-base';
import { ModelTool } from '@ibizstudio/runtime';
/**
 * 日历视图基类
 *
 * @export
 * @class CalendarViewBase
 * @extends {MDViewBase}
 * @implements {CalendarViewInterface}
 */
export class CalendarViewBase extends MDViewBase {
    /**
     * 引擎初始化（日历视图暂无引擎）
     *
     * @memberof CalendarViewBase
     */
    engineInit() { }
    /**
     * 初始化日历视图实例
     *
     * @param opts
     * @memberof CalendarViewBase
     */
    async viewModelInit() {
        var _a;
        this.viewInstance = ((_a = this.staticProps) === null || _a === void 0 ? void 0 : _a.modeldata);
        await super.viewModelInit();
        this.calendarInstance = ModelTool.findPSControlByType("CALENDAR", this.viewInstance.getPSControls());
    }
    /**
     * 渲染视图主体内容区
     *
     * @memberof CalendarViewBase
     */
    renderMainContent() {
        var _a;
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.calendarInstance);
        return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: (_a = this.calendarInstance) === null || _a === void 0 ? void 0 : _a.name, on: targetCtrlEvent });
    }
    /**
     * 快速搜索
     *
     * @param {*} $event
     * @memberof CalendarViewBase
     */
    onSearch($event) {
        var _a, _b, _c;
        const refs = this.$refs;
        if (refs[(_a = this.calendarInstance) === null || _a === void 0 ? void 0 : _a.name] && refs[(_b = this.calendarInstance) === null || _b === void 0 ? void 0 : _b.name].ctrl) {
            refs[(_c = this.calendarInstance) === null || _c === void 0 ? void 0 : _c.name].ctrl.refresh();
        }
    }
    /**
     * calendar 的 beforeload 事件
     *
     * @param {*} arg
     * @memberof CalendarViewBase
     */
    onBeforeLoad(arg) {
        var _a, _b;
        let _this = this;
        if (_this.viewparams && Object.keys(_this.viewparams).length > 0) {
            Object.assign(arg, _this.viewparams);
        }
        if ((_a = this.searchFormInstance) === null || _a === void 0 ? void 0 : _a.name) {
            const searchFrom = (_b = _this.$refs[this.searchFormInstance.name]) === null || _b === void 0 ? void 0 : _b.ctrl;
            if (searchFrom && _this.isExpandSearchForm) {
                Object.assign(arg, searchFrom.getData());
            }
        }
        if (_this && !_this.isExpandSearchForm) {
            Object.assign(arg, { query: _this.query });
        }
        // 快速分组和快速搜索栏
        let otherQueryParam = {};
        if (_this && _this.quickGroupData) {
            Object.assign(otherQueryParam, _this.quickGroupData);
        }
        if (_this && _this.quickFormData) {
            Object.assign(otherQueryParam, _this.quickFormData);
        }
        // 自定义查询条件
        //TODO YY 日历部件自定义查询条件
        // if (this.calendarInstance && this.calendarInstance.customCond) {
        //     Object.assign(otherQueryParam, { srfdsscope: this.calendarInstance.customCond });
        // }
        Object.assign(arg, { viewparams: otherQueryParam });
    }
    /**
     * searchform 部件 search 事件
     *
     * @param {*} $event
     * @memberof CalendarViewBase
     */
    searchform_search($event) {
        this.onSearch($event);
    }
    /**
     * searchform 部件 load 事件
     *
     * @param {*} $event
     * @memberof CalendarViewBase
     */
    searchform_load($event) {
        this.onSearch($event);
    }
    /**
     * 部件事件处理
     *
     * @param {*} $event
     * @memberof CalendarViewBase
     */
    onCtrlEvent(ctrlName, action, data) {
        var _a;
        if (!action) {
            return;
        }
        if (Object.is(ctrlName, this.calendarInstance.name)) {
            if (Object.is(action, "beforeload")) {
                this.onBeforeLoad(data);
            }
        }
        else if (Object.is(ctrlName, (_a = this.searchFormInstance) === null || _a === void 0 ? void 0 : _a.name)) {
            switch (action) {
                case "search":
                    this.searchform_search(data);
                    break;
                case "load":
                    this.searchform_load(data);
                    break;
            }
        }
        super.onCtrlEvent(ctrlName, action, data);
    }
}
