<template>
  <view class="project-card panel" @tap="$emit('open')">
    <view class="project-card__cover">
      <text>{{ indexLabel }}</text>
    </view>
    <view class="project-card__body">
      <view class="project-card__top">
        <text class="project-card__title">{{ title }}</text>
        <text class="status-pill" :class="statusClass(project.status)">{{ statusText(project.status) }}</text>
      </view>
      <text class="project-card__desc">{{ project.description || "等待 Agent 制作内容" }}</text>
      <view class="project-card__meta">
        <text>{{ project.type || "AI 短剧" }}</text>
        <text>{{ formatDateTime(project.updatedAt || project.createdAt) }}</text>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { computed } from "vue";
import type { ProjectSummary } from "@/types/api";
import { formatDateTime, statusClass, statusText } from "@/utils/format";

const props = defineProps<{
  project: ProjectSummary;
  index?: number;
}>();

defineEmits<{
  (event: "open"): void;
}>();

const title = computed(() => props.project.name || props.project.title || `项目 ${props.project.id}`);
const indexLabel = computed(() => String((props.index || 0) + 1).padStart(2, "0"));
</script>

<style scoped lang="scss">
.project-card {
  display: flex;
  gap: 22rpx;
  padding: 22rpx;
}

.project-card__cover {
  width: 118rpx;
  height: 118rpx;
  border-radius: 20rpx;
  background:
    linear-gradient(155deg, rgba(91, 92, 246, 0.95), rgba(30, 167, 255, 0.82)),
    #101828;
  color: #ffffff;
  font-size: 27rpx;
  font-weight: 860;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 16rpx;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1rpx rgba(255, 255, 255, 0.16);
}

.project-card__body {
  min-width: 0;
  flex: 1;
}

.project-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16rpx;
}

.project-card__title {
  min-width: 0;
  flex: 1;
  color: #101828;
  font-size: 30rpx;
  font-weight: 820;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-card__desc {
  display: -webkit-box;
  margin-top: 12rpx;
  color: #667085;
  font-size: 25rpx;
  line-height: 1.5;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.project-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16rpx;
  margin-top: 14rpx;
  color: #98a2b3;
  font-size: 22rpx;
}
</style>
