<script setup lang="ts">
import { Subject } from 'rxjs';
import { ctrlState } from './{{spinalCase ctrl.codeName}}-dashboard-state';
import { DashboardControl, IActionParam, IParam, IContext } from '@core';

{{#each ctrl.allPortlets as | control |}}
  {{#if control.psAppDataEntity}}
import { {{codeName}}Portlet } from '@widgets/{{spinalCase control.psAppDataEntity.codeName}}/{{spinalCase codeName}}-portlet';
  {{else}}
import { {{codeName}}Portlet } from '@widgets/app/{{spinalCase codeName}}-portlet';
  {{/if}}
{{/each}}

interface Props {
  name:string,
  parent: IParam;
  context: IContext;
  viewParams?: IParam;
  viewSubject: Subject<IActionParam>;
}

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

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

const emit = defineEmits <CtrlEmit> ();

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

// 暴露内部状态及能力
defineExpose({ name, state });
</script>
<template>
  <AppRow class="app-dashboard{{#if ctrl.psSysCss}} {{ctrl.psSysCss.cssName}}{{/if}}" :layoutOpts="{{> @macro/front-end/common/layoutPos.hbs layout=ctrl.psLayout layoutPos=ctrl.psLayoutPos}}">
    <template v-if="!state.isEnableCustomized">
  {{#each ctrl.psControls as |portlet|}}
    {{#eq portlet.portletType 'CONTAINER'}}
      {{> @macro/front-end/widgets/dashboard-detail/include-dashboard.hbs type='PORTLET_CONTAINER' portlet=portlet}}
    {{else}}
      {{> @macro/front-end/widgets/dashboard-detail/include-dashboard.hbs type='PORTLET' portlet=portlet}}
    {{/eq}}
  {{/each}}
    </template>
  </AppRow>
</template>
<style lang="scss">
</style>