<template>
  <div class="dashboard-container">
    <h1 class="welcome-title">Welcome to Funtime Design System</h1>
    <p class="subtitle">Select a module to get started</p>
    
    <el-row :gutter="24">
      <el-col :xs="24" :sm="12" :md="8" :lg="8" v-for="module in modules" :key="module.id">
        <el-card class="module-card" shadow="hover" @click="navigateTo(module.path)">
          <div class="module-icon">
            <component :is="module.icon" v-if="module.icon" />
          </div>
          <h3 class="module-title">{{ module.title }}</h3>
          <p class="module-desc">{{ module.description }}</p>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from 'axios'

interface ModuleItem {
  id: number
  title: string
  description: string
  icon: string
  path: string
}

const router = useRouter()
const modules = ref<ModuleItem[]>([])

const navigateTo = (path: string) => {
  router.push(path)
}

onMounted(async () => {
  try {
    const res = await axios.get('/api/modules')
    if (res.data.code === 0) {
      modules.value = res.data.data
    }
  } catch (error) {
    console.error('Failed to fetch modules:', error)
  }
})
</script>

<style scoped>
.dashboard-container {
  padding: 40px 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}
.welcome-title {
  text-align: center;
  margin-bottom: 12px;
  font-size: 32px;
  font-weight: 600;
  color: #303133;
}
.subtitle {
  text-align: center;
  margin-bottom: 60px;
  font-size: 16px;
  color: #909399;
}
.module-card {
  cursor: pointer;
  transition: all 0.3s ease;
  height: 100%;
  border: none;
  border-radius: 12px;
  margin-bottom: 20px;
}
.module-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}
.card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}
.icon-wrapper {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #ecf5ff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 36px;
  color: #409eff;
  margin-bottom: 24px;
  transition: all 0.3s;
}
.module-card:hover .icon-wrapper {
  background-color: #409eff;
  color: #ffffff;
  transform: scale(1.1);
}
.module-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}
.module-desc {
  margin: 0;
  font-size: 14px;
  color: #606266;
  line-height: 1.6;
  text-align: center;
}
</style>
