<template>
  <div
    class="project-card"
    :style="{ '--delay': delay }"
    @click="$emit('click', project)"
  >
    <div class="card-glow"></div>
    <button
      v-if="showDelete"
      class="card-delete-btn"
      @click.stop="$emit('delete', project)"
    >
      <el-icon><Delete /></el-icon>
    </button>
    <div class="card-header">
      <div class="card-avatar">
        <el-icon><Folder /></el-icon>
      </div>
    </div>
    <h3 class="card-title">{{ project.name }}</h3>
    <p class="card-desc">{{ project.description || '暂无描述' }}</p>
    <div class="card-footer">
      <span class="card-date">
        <el-icon><Calendar /></el-icon>
        {{ formattedDate }}
      </span>
      <div class="card-status">
        <span class="status-dot"></span>
        {{ statusText }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  project: {
    type: Object,
    required: true
  },
  index: {
    type: Number,
    default: 0
  },
  showDelete: {
    type: Boolean,
    default: true
  },
  statusText: {
    type: String,
    default: '活跃'
  }
})

defineEmits(['click', 'delete'])

const delay = computed(() => `${props.index * 0.1}s`)

const formattedDate = computed(() => {
  if (!props.project.created_at) return ''
  const d = new Date(props.project.created_at)
  return d.toLocaleDateString('zh-CN', { month: 'short', day: 'numeric', year: 'numeric' })
})
</script>

<style scoped>
.project-card {
  position: relative;
  padding: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  overflow: hidden;
  animation: cardFadeIn 0.5s ease backwards;
  animation-delay: var(--delay);
}

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

.project-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-4px);
}

.card-glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.project-card:hover .card-glow { opacity: 1; }

.card-delete-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--danger);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.2s ease;
  z-index: 10;
}

.card-delete-btn:hover {
  transform: scale(1.1);
  background: #dc2626;
}

.project-card:hover .card-delete-btn {
  opacity: 1;
  transform: scale(1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-avatar {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary-muted);
  border-radius: var(--radius-md);
  font-size: 20px;
  color: var(--accent-primary);
}

.card-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.card-desc {
  font-size: 14px;
  color: var(--text-tertiary);
  line-height: 1.5;
  margin-bottom: 20px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.card-date {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.card-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--success);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
}
</style>
