<script setup lang="ts">
import { Subject } from 'rxjs';
import { IActionParam, IParam, ControlAction, PickupViewPanelControl, IContext } from '@core';
import { ctrlState } from './{{spinalCase ctrl.codeName}}-pickup-view-panel-state';
{{#if ctrl.embeddedPSAppDEView}}
import {{ctrl.embeddedPSAppDEView.codeName}} from '@views/{{spinalCase ctrl.embeddedPSAppDEView.psAppModule.codeName}}/{{spinalCase ctrl.embeddedPSAppDEView.codeName}}';
{{/if}}
interface Props {
  name:string,
  parent: IParam;
  context: IContext;
  viewParams?: IParam;
  controlAction: ControlAction;
  showBusyIndicator?: boolean;
  isSingleSelect?: boolean;
  viewMode?: number;
  selectedData?: IParam[];
  isShowButton?: boolean;
  viewSubject: Subject<IActionParam>;
  multiple?: boolean;
}

const props = withDefaults(defineProps < Props > (), {
  viewSubject: () => new Subject < IActionParam > (),
  viewMode: 0,
  isSingleSelect: false,
  isShowButton: true,
  showBusyIndicator: true,
  multiple: false
})

// emit声明
interface CtrlEmit {
  (name: "onCtrlEvent", value: IActionParam): void;
}

const emit = defineEmits <CtrlEmit> ();

// 安装功能模块，提供状态和能力方法
const { name, state, onViewEvent } = new PickupViewPanelControl(ctrlState(), props, emit).moduleInstall();

// 暴露内部状态及能力
defineExpose({ name, state });
</script>

<template>

  <div class="app-pickup-view-panel{{#if ctrl.psSysCss}} {{ctrl.psSysCss.cssName}}{{/if}}">
  {{#if ctrl.embeddedPSAppDEView}}
    <{{ctrl.embeddedPSAppDEView.codeName}}
      :context="state.context"
      :viewParams="state.viewParams"
      :isShowButton="state.isShowButton" 
      :selectedData="selectedData"
      :viewSubject="state.viewSubject"
      :multiple="multiple"
      @viewEvent="onViewEvent"      
    />
  {{else}}
    <div class="app-pickup-view-panel--empty">视图不存在，请配置选择视图</div>
  {{/if}}
  </div>
</template>