<script setup lang="ts">
import { Subject } from 'rxjs';
import { PortalView, IActionParam, IParam, IContext } from '@core';
import { viewState } from './{{spinalCase page.codeName}}-state';
{{#page.ctrls}}
{{#eq controlType "DASHBOARD"}}
import { {{codeName}}Dashboard } from '@widgets/app/{{spinalCase codeName}}-dashboard';
{{/eq}}
{{/page.ctrls}}

// props声明和默认值处理
interface Props {
  context?: IContext;
  viewParams?: IParam;
  openType?: "ROUTE" | "MODAL" | "EMBED";
  viewSubject?: Subject<IActionParam>;
}

const props = withDefaults(defineProps<Props>(), {
  openType:'ROUTE',
  viewSubject: () => new Subject<IActionParam>()
})

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

const emit = defineEmits<ViewEmit>();

// 安装功能模块，提供状态和能力方法
const portalView = new PortalView(viewState(), props, emit).moduleInstall();
const { state, dashboard, onCtrlEvent } = portalView;

</script>

<template>
  <AppPortalViewLayout :class="['app-edit-view', state.viewSysCss]">
    <template v-slot:caption>
      <AppIconText
        class="app-view__caption"
        size="large"
        :text="state.viewCaption"
      />
    </template>
    {{#page.ctrls}}
    {{#eq controlType "DASHBOARD"}}
    <{{codeName}}Dashboard
      ref="dashboard"
      name="{{name}}"
      :context="state.context"
      :viewParams="state.viewParams"
      :viewSubject="state.viewSubject"
      :parent="portalView"
      @ctrlEvent="onCtrlEvent"      
    ></{{codeName}}Dashboard>
    {{/eq}}
    {{/page.ctrls}}
  </AppPortalViewLayout>
</template>

<style lang="scss">
</style>