import { MPickUpView2Base } from '../../../view/mpickupview2-base';
import { AppLayoutService } from '../../..';

export class AppMPickUpView2Base extends MPickUpView2Base {
  /**
   * 初始化containerModel
   *
   * @memberof AppMPickUpView2Base
   */
  initContainerModel(opts: any) {
    super.initContainerModel(opts);
    const { modeldata } = opts;
    modeldata?.getPSControls().forEach((ctrl: any) => {
      this.containerModel[`view_${ctrl.name}`] = { name: `${ctrl.name}`, type: `${ctrl.controlType}` };
    });
  }

  /**
   * 渲染
   *
   * @memberof AppMPickUpView2Base
   */
  render(h: any) {
    if (!this.viewIsLoaded) {
      return;
    }
    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.renderBodyMessage(), this.renderToolBar(), this.renderMainContent(), this.renderBottomMessage()],
    );
  }
}
