import { AppLayoutService } from '../../../app-service';
import { DePanelViewBase } from '../../../view';

/**
 * 应用实体面板视图基类
 *
 * @export
 * @class AppDataViewExpViewBase
 * @extends {DataViewExpBase}
 */
export class AppDePanelViewBase extends DePanelViewBase {
  /**
   * 渲染视图主体内容区
   *
   * @memberof ExpViewBase
   */
  renderMainContent() {
    let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.panelInstance);
    if (this.panelInstance) {
      Object.assign(targetCtrlParam.dynamicProps, {
        navdatas: this.navdatas,
      });
    }
    return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.panelInstance?.name, on: targetCtrlEvent });
  }

  /**
   * 数据视图渲染
   *
   * @memberof AppDataViewExpViewBase
   */
  render(h: any) {
    if (!this.viewIsLoaded) {
      return null;
    }
    const targetViewLayoutComponent: any = AppLayoutService.getLayoutComponent(`${this.viewInstance.viewType}-${this.viewInstance.viewStyle}`);
    return h(
      targetViewLayoutComponent,
      {
        props: { viewInstance: this.viewInstance, model: this.model, modelService: this.modelService, viewparams: this.viewparams, context: this.context },
      },
      [this.renderTopMessage(), this.renderToolBar(), this.renderBodyMessage(), this.renderMainContent(), this.renderBottomMessage()],
    );
  }
}
