<template>
  <div class="welcome-page">
    <div class="welcome-header">
      <h2>{{ t('welcome.heading') }} 👋</h2>
      <p>{{ t('welcome.subtitle') }}</p>
    </div>
    <div class="menu-sections">
      <div class="menu-section" v-for="menu in menus" :key="menu.name">
        <div class="section-title">
          <el-icon><component :is="menu.icon" /></el-icon>
          <span>{{ t(menu.titleKey) }}</span>
        </div>
        <div class="section-items">
          <router-link
            :to="submenu.path"
            v-for="submenu in menu.child"
            :key="submenu.path"
            class="menu-item"
          >
            <span class="item-label">{{ t(submenu.titleKey) }}</span>
            <el-icon class="item-arrow"><ArrowRight /></el-icon>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import allMenus from '../config/menu'
import type { MenuGroup } from '../config/menu'
import { hasPermission } from '@/utils/permission'

const { t } = useI18n()

const menus = computed((): MenuGroup[] => {
  return allMenus
    .map(group => ({
      ...group,
      child: group.child.filter(item => hasPermission(item.permission))
    }))
    .filter(group => group.child.length > 0)
})
</script>
<style lang="less" scoped>
.welcome-page {
  padding: 32px;
  max-width: 1000px;
  box-sizing: border-box;
}

.welcome-header {
  margin-bottom: 32px;
  h2 {
    font-size: 26px;
    font-weight: 700;
    color: var(--el-text-color-primary);
    margin: 0 0 8px;
  }
  p {
    font-size: 14px;
    color: var(--el-text-color-secondary);
    margin: 0;
  }
}

.menu-sections {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.menu-section {
  background: var(--el-bg-color);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--el-border-color-lighter);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--el-text-color-regular);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--el-border-color-light);

  .el-icon {
    font-size: 17px;
    color: var(--el-color-primary);
  }
}

.section-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--el-fill-color-light);
  text-decoration: none;
  color: var(--el-text-color-primary);
  font-size: 14px;
  transition: all 0.2s;
  border: 1px solid transparent;

  .item-arrow {
    font-size: 13px;
    color: var(--el-text-color-placeholder);
    transition: transform 0.2s, color 0.2s;
  }

  &:hover {
    background: var(--el-color-primary-light-9);
    border-color: var(--el-color-primary-light-5);
    color: var(--el-color-primary);

    .item-arrow {
      color: var(--el-color-primary);
      transform: translateX(3px);
    }
  }
}
</style>