import { ModelTool, ViewTool } from '@ibizstudio/runtime';
import { AppFuncService } from '../app-service';
import { ViewBase } from "./view-base";
/**
 * 首页视图基类
 *
 * @export
 * @class IndexViewBase
 * @extends {ViewBase}
 * @implements {IndexViewInterface}
 */
export class IndexViewBase extends ViewBase {
    constructor() {
        super(...arguments);
        /**
         * 是否支持应用切换
         *
         * @type {boolean}
         * @memberof IndexViewBase
         */
        this.isEnableAppSwitch = false;
        /**
         * 是否为应用起始页面
         *
         * @type {boolean}
         * @memberof IndexViewBase
         */
        this.isDefaultPage = false;
        /**
         * 是否为空白视图模式
         *
         * @type {boolean}
         * @memberof IndexViewBase
         */
        this.isBlankMode = false;
        /**
         * 菜单收缩变化
         *
         * @type {boolean}
         * @memberof IndexViewBase
         */
        this.collapseChange = false;
    }
    /**
     * 初始化应用首页视图实例
     *
     * @memberof IndexViewBase
     */
    async viewModelInit() {
        var _a;
        this.viewInstance = ((_a = this.staticProps) === null || _a === void 0 ? void 0 : _a.modeldata);
        await super.viewModelInit();
        this.menuInstance = (this.viewInstance.findPSControl(ModelTool.findPSControlByType("APPMENU", this.viewInstance.getPSControls())));
    }
    /**
     * 视图初始化
     *
     * @memberof IndexViewBase
     */
    viewInit() {
        super.viewInit();
        AppFuncService.getInstance().init(this);
    }
    /**
     *  视图挂载
     *
     * @memberof IndexViewBase
     */
    viewMounted() {
        var _a, _b, _c;
        super.viewMounted();
        this.viewState.next({ tag: (_a = this.menuInstance) === null || _a === void 0 ? void 0 : _a.name, action: 'load', data: {} });
        ViewTool.setIndexParameters([{ pathName: (_b = this.viewInstance) === null || _b === void 0 ? void 0 : _b.codeName, parameterName: (_c = this.viewInstance) === null || _c === void 0 ? void 0 : _c.codeName }]);
        ViewTool.setIndexViewParam(this.context);
        this.appLoadingDestroyed();
    }
    /**
     *  应用loading销毁
     *
     * @memberof IndexViewBase
     */
    appLoadingDestroyed() {
        setTimeout(() => {
            const el = document.getElementById('app-loading-x');
            if (el) {
                el.style.display = 'none';
            }
        }, 300);
    }
    /**
     * 视图销毁
     *
     * @memberof IndexViewBase
     */
    viewDestroyed() {
        super.viewDestroyed();
    }
    /**
     * 渲染视图主题内容
     *
     * @memberof IndexViewBase
     */
    renderMainContent() {
        var _a;
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.menuInstance);
        return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: (_a = this.menuInstance) === null || _a === void 0 ? void 0 : _a.name, on: targetCtrlEvent });
    }
    /**
     * 计算目标部件所需参数
     *
     * @param {string} [controlType]
     * @returns
     * @memberof IndexViewBase
     */
    computeTargetCtrlData(controlInstance) {
        var _a, _b, _c, _d, _e, _f;
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance);
        Object.assign(targetCtrlParam.dynamicProps, {
            collapseChange: this.collapseChange
        });
        let counterdata = null;
        if (((_a = this.counterServiceArray) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            counterdata = (_b = this.counterServiceArray[0].service) === null || _b === void 0 ? void 0 : _b.counterData;
        }
        Object.assign(targetCtrlParam.staticProps, {
            mode: (_c = this.viewInstance) === null || _c === void 0 ? void 0 : _c.mainMenuAlign,
            isDefaultPage: (_d = this.viewInstance) === null || _d === void 0 ? void 0 : _d.defaultPage,
            isBlankMode: (_e = this.viewInstance) === null || _e === void 0 ? void 0 : _e.blankMode,
            defPSAppView: (_f = this.viewInstance) === null || _f === void 0 ? void 0 : _f.getDefPSAppView(),
            counterdata: counterdata,
        });
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent };
    }
}
