<template>
  <MenuItem
    :name="item.path"
    v-if="!menuHasChildren(item) && getShowMenu"
    v-bind="$props"
    :class="getLevelClass"
  >
    <img v-if="getImg" :src="getImg" class="w-16px h-16px align-top" />
    <Icon v-if="getIcon" :icon="getIcon" :size="16" />
    <div v-if="collapsedShowTitle && getIsCollapseParent" class="mt-1 collapse-title">
      {{ getI18nName }}
    </div>
    <template #title>
      <span :class="['ml-2', `${prefixCls}-sub-title`]" :data-cy="item.path">
        {{ getI18nName }}
      </span>
      <SimpleMenuTag :item="item" :collapseParent="getIsCollapseParent" />
    </template>
  </MenuItem>
  <SubMenu
    v-if="menuHasChildren(item) && getShowMenu"
    :isThemeBright="isThemeBright"
    :name="item.path"
    :class="[getLevelClass, theme]"
    :collapsedShowTitle="collapsedShowTitle"
  >
    <template #title>
      <img v-if="getImg" :src="getImg" class="w-16px h-16px align-top" />
      <Icon v-if="getIcon" :icon="getIcon" :size="16" />

      <div v-if="collapsedShowTitle && getIsCollapseParent" class="mt-2 collapse-title">
        {{ getI18nName }}
      </div>

      <span v-show="getShowSubTitle" :class="['ml-2', `${prefixCls}-sub-title`]" :data-cy="item.path">
        {{ getI18nName }}
      </span>
      <SimpleMenuTag :item="item" :collapseParent="!!collapse && !!parent" />
    </template>
    <template
      v-for="childrenItem in item.children || []"
      :key="childrenItem.paramPath || childrenItem.path"
    >
      <SimpleSubMenu v-bind="$props" :isThemeBright="isThemeBright" :item="childrenItem" :parent="false" />
    </template>
  </SubMenu>
</template>
<script lang="ts" setup>
  import type { Menu } from '@/router/types';
  import { createAsyncComponent } from '@/utils/factory/createAsyncComponent';
  import { useDesign } from '@/hooks/web/useDesign';
  import { checkChildrenHidden } from '@/utils/common/compUtils';
  import MenuItem from './components/MenuItem.vue';
  import SubMenu from './components/SubMenuItem.vue';
<%_ if (enableTranslation) { _%>
  import { useI18n } from '@/hooks/web/useI18n';
<%_ } _%>

  const SimpleMenuTag = createAsyncComponent(() => import('./SimpleMenuTag.vue'));

  // begcode-please-regenerate-this-file 如果您不希望重新生成代码时被覆盖，将please修改为don't ！！！

  defineOptions({ name: 'SimpleSubMenu' });

  const props = defineProps({
    item: {
      type: Object as PropType<Menu>,
      default: () => ({}),
    },
    parent: {
      type: Boolean,
      default: false,
    },
    collapsedShowTitle: {
      type: Boolean,
      default: false,
    },
    collapse: {
      type: Boolean,
      default: false,
    },
    theme: {
      type: String as PropType<'light' | 'dark'>,
    },
    isThemeBright: {
      type: Boolean,
      default: false,
    },
  });

  <%_ if (enableTranslation) { _%>
  const { t } = useI18n();
  <%_ } _%>

  const { prefixCls } = useDesign('simple-menu');

  const getShowMenu = computed(() => !props.item?.meta?.hideMenu);
  const getIcon = computed(() => (props.item?.img ? undefined : props.item?.icon));
  const getImg = computed(() => props.item?.img);
  const getI18nName = computed(() => <% if (enableTranslation) { %>t(props.item?.meta?.title || props.item?.name)<% } else { %>props.item?.meta?.title<% } %>);
  const getShowSubTitle = computed(() => !props.collapse || !props.parent);
  const getIsCollapseParent = computed(() => !!props.collapse && !!props.parent);
  const getLevelClass = computed(() => {
    return [
      {
        [`${prefixCls}__parent`]: props.parent,
        [`${prefixCls}__children`]: !props.parent,
      },
    ];
  });

  function menuHasChildren(menuTreeItem): boolean {
    return (
            !menuTreeItem.meta?.hideChildrenInMenu &&
            Reflect.has(menuTreeItem, 'children') &&
            !!menuTreeItem.children &&
            menuTreeItem.children.length > 0 &&
            checkChildrenHidden(menuTreeItem)
    );
  }
</script>
