import { PickUpViewPanelControlBase } from '../../../widgets';
import { IPSAppDEView } from '@ibizstudio/runtime';

/**
 * 选择视图面板部件基类
 *
 * @export
 * @class AppPickUpViewPanelBase
 * @extends {PickUpViewPanelControlBase}
 */
export class AppPickUpViewPanelBase extends PickUpViewPanelControlBase {
  /**
   * 绘制选择视图面板
   *
   * @returns {*}
   * @memberof AppPickUpViewPanelBase
   */
  render() {
    if (!this.controlIsLoaded || !this.inited) {
      return null;
    }
    const targetViewParam = {
      staticProps: {
        isSingleSelect: this.isSingleSelect,
        viewDefaultUsage: false,
        viewState: this.viewState,
        viewtag: this.viewtag,
        isShowButton: this.isShowButton,
        viewModelData: this.controlInstance.getEmbeddedPSAppDEView() as IPSAppDEView,
      },
      dynamicProps: {
        selectedData: this.selectedData,
        viewparam: this.viewparam,
        viewdata: this.viewdata,
      },
    };
    const targetViewEvent = {
      viewdataschange: (data: any) => this.onViewDatasChange(data),
      viewdatasactivated: (data: any) => {
        this.$emit('ctrl-event', { controlname: 'pickupviewpanel', action: 'activated', data: data });
      },
      viewload: (data: any) => {
        this.$emit('ctrl-event', { controlname: 'pickupviewpanel', action: 'load', data: data });
      },
    };
    return (
      <div class={{ ...this.renderOptions?.controlClassNames, pickupviewpanel: true }}>
        {this.$createElement(this.view.viewName, {
          ref: this.controlInstance.getEmbeddedPSAppDEView()?.name,
          props: targetViewParam,
          on: targetViewEvent,
          class: 'viewcontainer3',
        })}
      </div>
    );
  }
}
