<template>
  <el-card shadow="never" class="section-card">
    <template #header>
      <div class="section-header">
        <span class="section-title">{{ title }}</span>
        <el-button v-if="!loading" type="primary" link @click="$emit('more')" class="more-btn">
          查看更多 <el-icon class="el-icon--right"><ArrowRight /></el-icon>
        </el-button>
      </div>
    </template>
    
    <div class="section-body">
      <StateLoading v-if="loading" :rows="3" />
      <div v-else-if="items && items.length" class="list-container">
        <div 
          v-for="item in items.slice(0, 5)" 
          :key="item.title + item.path" 
          class="list-item" 
          @click="go(item.path)"
        >
          <div class="item-main">
            <div class="item-title">{{ item.title }}</div>
            <div class="item-subtitle">{{ item.subtitle }}</div>
          </div>
          <div class="item-meta">
            <el-tag 
              size="small" 
              :type="item.overdue ? 'danger' : 'info'" 
              :effect="item.overdue ? 'dark' : 'light'"
              class="status-tag"
            >
              {{ item.status || "待处理" }}
            </el-tag>
          </div>
        </div>
      </div>
      <div v-else class="empty-state">
        <StateEmpty :description="emptyText || '暂无数据'" />
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { ArrowRight } from "@element-plus/icons-vue";
import StateEmpty from "../../../components/StateEmpty.vue";
import StateLoading from "../../../components/StateLoading.vue";

defineProps<{
  title: string;
  items: any[];
  loading?: boolean;
  emptyText?: string;
}>();

const emit = defineEmits(["more"]);
const router = useRouter();

const go = (path: string) => {
  if (!path) return;
  router.push(path);
};
</script>

<style scoped>
.section-card {
  border: 1px solid var(--ctms-border-color);
  border-radius: 8px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

:deep(.el-card__header) {
  padding: 16px 20px;
  border-bottom: 1px solid var(--ctms-border-color);
  background-color: #fafafa;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ctms-text-main);
}

.more-btn {
  font-size: 13px;
  color: var(--ctms-primary);
}

.section-body {
  flex: 1;
  padding: 0;
}

.list-container {
  display: flex;
  flex-direction: column;
}

.list-item {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 1px solid var(--ctms-border-color);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover {
  background-color: var(--ctms-primary-light);
}

.item-main {
  flex: 1;
  overflow: hidden;
  margin-right: 16px;
}

.item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ctms-text-main);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-subtitle {
  font-size: 12px;
  color: var(--ctms-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-tag {
  border-radius: 4px;
}

.empty-state {
  padding: 8px 0;
}
</style>
