<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getNoticeListApi } from '@/api/notice'
import type { Notice } from '@/types'
import { Bell, Calendar } from '@element-plus/icons-vue'

const notices = ref<Notice[]>([])
onMounted(async () => {
  notices.value = (await getNoticeListApi()) || []
})
</script>

<template>
  <div class="page container">
    <div class="page-header">
      <h2 class="page-title">
        <el-icon><Bell /></el-icon>
        商城公告
      </h2>
      <p class="page-subtitle">了解商城最新动态和优惠活动</p>
    </div>

    <div class="notice-list">
      <div
        v-for="(n, idx) in notices"
        :key="n.id"
        class="notice-card"
        :style="{ animationDelay: idx * 80 + 'ms' }"
      >
        <div class="card-left">
          <div class="notice-icon">
            <el-icon><Bell /></el-icon>
          </div>
          <div class="notice-line"></div>
        </div>
        <div class="card-body">
          <div class="notice-header">
            <h3>{{ n.title }}</h3>
            <el-tag v-if="n.isTop" type="danger" size="small" effect="dark">置顶</el-tag>
          </div>
          <p class="notice-content">{{ n.content }}</p>
          <div class="notice-footer">
            <span class="notice-time">
              <el-icon size="14"><Calendar /></el-icon>
              {{ n.createTime }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <div v-if="!notices.length" class="empty-state">
      <div class="empty-illustration">
        <el-icon :size="80" color="#E5E7EB"><Bell /></el-icon>
      </div>
      <h3>暂无公告</h3>
      <p>请稍后查看</p>
    </div>
  </div>
</template>

<style scoped>
.page {
  padding: 24px 0 60px;
}
.page-header {
  margin-bottom: 24px;
}
.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}
.page-subtitle {
  color: var(--color-text-muted);
  font-size: 14px;
}

.notice-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.notice-card {
  display: flex;
  gap: 16px;
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-fast);
  animation: fadeInUp 0.5s ease forwards;
  opacity: 0;
}
.notice-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.notice-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.notice-line {
  flex: 1;
  width: 2px;
  background: var(--color-border-light);
  border-radius: 1px;
}
.card-body {
  flex: 1;
}
.notice-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.notice-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}
.notice-content {
  color: var(--color-text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
  font-size: 15px;
}
.notice-footer {
  display: flex;
  align-items: center;
}
.notice-time {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* Empty State */
.empty-state {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 80px 40px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}
.empty-illustration {
  margin-bottom: 20px;
}
.empty-state h3 {
  font-size: 20px;
  color: var(--color-text);
  margin-bottom: 8px;
}
.empty-state p {
  color: var(--color-text-muted);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
@media (max-width: 768px) {
  .notice-card {
    padding: 20px;
    gap: 12px;
  }
  .card-left {
    display: none;
  }
}
</style>
