<template>
  <div class="home-page">
    <!-- Header -->
    <div class="header">
      <div class="logo">
        <img src="@/assets/images/home/logo@2x.png" alt="STORLEAD" />
      </div>
      <div class="user-info">
        <img src="@/assets/images/home/Group@2x.png" alt="User" class="user-avatar" />
        <span class="username">张小明</span>
      </div>
    </div>

    <!-- Main Content -->
    <div class="main-content">
      <!-- Recently Used Section -->
      <div class="section">
        <h2 class="section-title">最近使用</h2>
        <div class="icon-grid">
          <div class="icon-item" v-for="item in recentlyUsed" :key="item.name" @click="handleClick(item)">
            <div class="icon-wrapper" >
              <img :src="item.icon" :alt="item.name" />
            </div>
            <span class="icon-label">{{ item.name }}</span>
          </div>
        </div>
      </div>

      <!-- Pending My Approval Section -->
      <div class="section">
        <h2 class="section-title">待我审批</h2>
        <div class="icon-grid">
          <div class="icon-item" v-for="item in pendingApproval" :key="item.name" @click="handleClick(item)">
            <div class="icon-wrapper" >
              <img :src="item.icon" :alt="item.name" />
            </div>
            <span class="icon-label">{{ item.name }}</span>
          </div>
        </div>
      </div>

      <!-- My Approvals Section -->
      <div class="section">
        <h2 class="section-title">我的审批</h2>
        <div class="icon-grid">
          <div class="icon-item" v-for="item in myApprovals" :key="item.name" @click="handleClick(item)">
            <div class="icon-wrapper" >
              <img :src="item.icon" :alt="item.name" />
            </div>
            <span class="icon-label">{{ item.name }}</span>
          </div>
        </div>
      </div>

      <!-- My Tasks Section -->
      <div class="section">
        <h2 class="section-title">我的任务</h2>
        <div class="icon-grid">
          <div class="icon-item" v-for="item in myTasks" :key="item.name" @click="handleClick(item)">
            <div class="icon-wrapper" :style="{ backgroundColor: item.color }">
              <img :src="item.icon" :alt="item.name" />
            </div>
            <span class="icon-label">{{ item.name }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="Index" lang="ts">
import { ref } from 'vue';

interface MenuItem {
  name: string;
  icon: string;
  color: string;
  route?: string;
}

// Recently Used Items
const recentlyUsed = ref<MenuItem[]>([
  { name: '立项', icon: '/src/assets/images/home/立项@2x.png', color: '#5DCDFF' },
  { name: '项目变更', icon: '/src/assets/images/home/项目变更@2x.png', color: '#6B8CFF' },
  { name: '进出场单', icon: '/src/assets/images/home/进出场单@2x.png', color: '#FF9F5A' },
  { name: '文档', icon: '/src/assets/images/home/文档@2x.png', color: '#5FD4A8' },
  { name: '申购', icon: '/src/assets/images/home/申购@2x.png', color: '#7B6CFF' },
  { name: 'BOM变更', icon: '/src/assets/images/home/BOM变更@2x.png', color: '#FF6B9D' },
  { name: '兑换', icon: '/src/assets/images/home/兑换@2x.png', color: '#C77CFF' },
  { name: '兑换付款', icon: '/src/assets/images/home/兑换付款@2x.png', color: '#FFB84D' },
]);

// Pending My Approval Items
const pendingApproval = ref<MenuItem[]>([
  { name: '立项', icon: '/src/assets/images/home/project_initiation.png', color: '#5DCDFF' },
  { name: '项目变更', icon: '/src/assets/images/home/project_change.png', color: '#6B8CFF' },
  { name: '进出场单', icon: '/src/assets/images/home/entry_exit_form.png', color: '#FF9F5A' },
  { name: '文档', icon: '/src/assets/images/home/document.png', color: '#5FD4A8' },
  { name: '申购', icon: '/src/assets/images/home/purchase_request.png', color: '#7B6CFF' },
  { name: 'BOM变更', icon: '/src/assets/images/home/bom_change.png', color: '#FF6B9D' },
  { name: '兑换', icon: '/src/assets/images/home/redeem.png', color: '#C77CFF' },
  { name: '兑换付款', icon: '/src/assets/images/home/redeem_payment.png', color: '#FFB84D' },
]);

// My Approvals Items
const myApprovals = ref<MenuItem[]>([
  { name: '配置品审批', icon: '/src/assets/images/home/configuration_approval.png', color: '#6B8CFF' },
  { name: '投标入场', icon: '/src/assets/images/home/entry_approval.png', color: '#5FD4A8' },
  { name: '投标入场', icon: '/src/assets/images/home/entry_approval.png', color: '#7B6CFF' },
  { name: '配置付款', icon: '/src/assets/images/home/configuration_payment.png', color: '#FFB84D' },
  { name: '项目汇总', icon: '/src/assets/images/home/project_summary.png', color: '#5DCDFF' },
  { name: '工单生成', icon: '/src/assets/images/home/work_order_service.png', color: '#5FD4A8' },
]);

// My Tasks Items
const myTasks = ref<MenuItem[]>([
  { name: '配置付款', icon: '/src/assets/images/home/configuration_payment.png', color: '#FFB84D' },
  { name: '项目汇总', icon: '/src/assets/images/home/project_summary.png', color: '#5DCDFF' },
  { name: '工单生成', icon: '/src/assets/images/home/work_order_service.png', color: '#5FD4A8' },
]);

const handleClick = (item: MenuItem) => {
  console.log('Clicked:', item.name);
  // Add navigation logic here
  if (item.route) {
    // router.push(item.route);
  }
};

onMounted(() => {
  console.log('Home page mounted');
});
</script>

<style scoped lang="scss">
.home-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #F5F7FA 0%, #FFFFFF 100%);
  overflow-y: scroll;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background: linear-gradient(90deg, #1E88E5 0%, #42A5F5 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

  .logo {
    img {
      height: 32px;
    }
  }

  .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
    cursor: pointer;

    .user-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      border: 2px solid rgba(255, 255, 255, 0.3);
    }

    .username {
      font-size: 14px;
      font-weight: 500;
    }
  }
}

.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 40px 20px;
}

.section {
  margin-bottom: 48px;

  .section-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 24px;
    padding-left: 12px;
    border-left: 4px solid #1E88E5;
  }

  .icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 32px 24px;
    background: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);

    @media (max-width: 768px) {
      grid-template-columns: repeat(4, 1fr);
      gap: 24px 16px;
      padding: 24px;
    }

    @media (max-width: 480px) {
      grid-template-columns: repeat(3, 1fr);
      gap: 20px 12px;
      padding: 20px;
    }
  }

  .icon-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: transform 0.2s ease;

    &:hover {
      transform: translateY(-4px);

      .icon-wrapper {
        // box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
      }
    }

    .icon-wrapper {
      width: 64px;
      height: 64px;
      border-radius: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s ease;
    //   box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

      img {
        width: 64px;
        height: 64px;
        object-fit: contain;
      }
    }

    .icon-label {
      font-size: 14px;
      color: #666;
      text-align: center;
      font-weight: 500;
      white-space: nowrap;
    }
  }
}
</style>
