<template>
  <div class="dashboard-page">
    <div class="stat-cards">
      <div class="stat-card">
        <div class="stat-icon pending"><el-icon><Clock /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.pending }}</p>
          <p class="stat-label">待处理订单</p>
        </div>
      </div>
      <div class="stat-card">
        <div class="stat-icon total"><el-icon><List /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.total }}</p>
          <p class="stat-label">总订单数</p>
        </div>
      </div>
      <div class="stat-card">
        <div class="stat-icon products"><el-icon><Goods /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.products }}</p>
          <p class="stat-label">商品数量</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { Clock, List, Goods } from '@element-plus/icons-vue'
import { supplierApi } from '../../api'

const stats = ref({ pending: '--', total: '--', products: '--' })

onMounted(async () => {
  try {
    const [ordersRes, inventoryRes]: any[] = await Promise.all([
      supplierApi.getOrders(),
      supplierApi.getInventory(),
    ])
    const orders = ordersRes.data || []
    const inventory = inventoryRes.data || []
    stats.value.pending = orders.filter((o: any) => o.status === 'pending_confirm').length
    stats.value.total = orders.length
    stats.value.products = inventory.length
  } catch {}
})
</script>

<style scoped lang="scss">
.dashboard-page { padding: 0; }

.stat-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.stat-card {
  background: #2d2d44;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 200px;
  min-width: 200px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.stat-icon.pending { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.stat-icon.total { background: rgba(78, 110, 242, 0.15); color: #4e6ef2; }
.stat-icon.products { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.stat-info { flex: 1; }
.stat-value { font-size: 28px; font-weight: 700; color: #fff; }
.stat-label { font-size: 14px; color: rgba(255, 255, 255, 0.5); margin-top: 4px; }

@media (max-width: 768px) {
  .stat-cards { gap: 12px; }
  .stat-card {
    padding: 16px;
    gap: 12px;
    flex: 1 1 calc(50% - 6px);
    min-width: 140px;
  }
  .stat-icon { width: 40px; height: 40px; font-size: 20px; border-radius: 10px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 12px; }
}
</style>
