import { MainControlBase } from "./main-control-base";
import { IPSAppView, IPSDEViewPanel } from '@ibizstudio/runtime';

/**
 * 嵌入视图面板部件基类
 *
 * @export
 * @class ViewPanelControlBase
 * @extends {MDControlBase}
 */
export class ViewPanelControlBase extends MainControlBase {

    /**
     * 面板的模型对象
     *
     * @type {*}
     * @memberof ViewPanelControlBase
     */
    declare controlInstance: IPSDEViewPanel;

    /**
     * 缓存UUID
     *
     * @type {*}
     * @memberof ViewPanelControlBase
     */
    cacheUUID: any;

    /**
     * 嵌入视图模型路径
     *
     * @type {string}
     * @memberof ViewPanelControlBase
     */
    embedViewPath: string = '';

    /**
     * 部件模型初始化
     *
     * @memberof ViewPanelControlBase
     */
    async ctrlModelInit(args?: any) {
        await super.ctrlModelInit(args);
        await this.initEmbedViewPath();
    }

    /**
     * 初始化嵌入视图模型路径
     *
     * @memberof ViewPanelControlBase
     */
    async initEmbedViewPath() {
        const embedView = this.controlInstance.getEmbeddedPSAppDEView?.() as IPSAppView;
        await embedView?.fill?.(true);
        this.embedViewPath = embedView.modelPath || '';
    }

}