import { IPSAppDETreeExplorerView, IPSTreeExpBar } from '@ibizstudio/runtime';
import { TreeExpViewEngine, ModelTool, TreeExpViewInterface } from '@ibizstudio/runtime';
import { ExpViewBase } from './expview-base';

/**
 * 树导航视图基类
 *
 * @export
 * @class TreeExpViewBase
 * @extends {ExpViewBase}
 * @implements {TreeExpViewInterface}
 */
export class TreeExpViewBase extends ExpViewBase implements TreeExpViewInterface {
    /**
     * 视图实例
     *
     * @memberof TreeExpViewBase
     */
    declare viewInstance: IPSAppDETreeExplorerView;

    /**
     * 导航栏实例
     *
     * @memberof TreeExpViewBase
     */
    declare expBarInstance: IPSTreeExpBar;

    /**
     * 视图引擎
     *
     * @public
     * @type {ChartViewEngine}
     * @memberof TreeExpViewBase
     */
    engine: TreeExpViewEngine = new TreeExpViewEngine();

    /**
     * 引擎初始化
     *
     * @public
     * @memberof TreeExpViewBase
     */
    engineInit(): void {
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        this.engine.init({
          view: this,
          parentContainer: this.$parent,
          p2k: '0',
          treeexpbar:(this.$refs[this.expBarInstance?.name] as any).ctrl,
          keyPSDEField: this.appDeCodeName.toLowerCase(),
          majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
          isLoadDefault: this.viewInstance?.loadDefault,
        });
    } 

    /**
     * 初始化列表视图实例
     *
     * @memberof TreeExpViewBase
     */
    async viewModelInit() {
        this.viewInstance = (this.staticProps?.modeldata) as IPSAppDETreeExplorerView;
        await super.viewModelInit();
        this.expBarInstance = ModelTool.findPSControlByType('TREEEXPBAR', this.viewInstance.getPSControls() || []);
    }

}