import { Emit } from 'vue-property-decorator';
import { AppLayoutService } from '../../../app-service';
import { GanttViewBase } from '../../../view/ganttview-base';

/**
 * 应用实体甘特视图基类
 *
 * @export
 * @class AppGanttViewBase
 * @extends {GanttViewBase}
 */
export class AppGanttViewBase extends GanttViewBase {
  /**
   * 部件事件
   *
   * @param {{ controlname: string; action: string; data: any }} { controlname 部件名称, action 事件名称, data 事件参数 }
   * @memberof AppDefaultTree
   */
  @Emit('ctrl-event')
  ctrlEvent({ controlname, action, data }: { controlname: string; action: string; data: any }): void {}

  /**
   * 绘制
   *
   * @param h
   * @memberof AppGanttViewBase
   */
  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.renderBodyMessage(),
        this.renderToolBar(),
        this.renderQuickGroup(),
        this.renderQuickSearch(),
        !(this.viewInstance?.viewStyle == 'DEFAULT' && this.viewInstance?.enableQuickSearch) ? this.renderSearchForm() : null,
        this.renderMainContent(),
        this.renderBottomMessage(),
      ],
    );
  }
}
