<template>
  <div class="recommend-card" @click="$emit('select')">
    <div class="card-content">
      <h4 class="card-title">{{ task.titleZh }}</h4>
      <p class="card-subtitle">{{ task.subtitle }}</p>
      <p class="card-meta">
        <span>{{ typeLabel }}</span>
        <span class="meta-dot">·</span>
        <span>{{ countLabel }}</span>
        <span class="meta-dot">·</span>
        <span>{{ difficultyLabel }}</span>
        <span class="meta-dot">·</span>
        <span>~{{ task.durationMinutes }}{{ lang.ssMinutesUnit }}</span>
      </p>
    </div>
    <svg class="card-arrow" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M9 18l6-6-6-6" />
    </svg>
  </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { lang } from '@/main'
import type { SpeakingRecommendationTask } from '@/types/englishSpeaking'

const props = defineProps<{
  task: SpeakingRecommendationTask
}>()

defineEmits<{
  (e: 'select'): void
}>()

// 按 taskType 分支渲染：文章卡显示「1 篇」，话题卡显示「N 轮」，不把文章塞进话题形状
const typeLabel = computed(() =>
  props.task.taskType === 'article-reading'
    ? (lang.ssArticleReading as string)
    : (lang.ssTopicDiscussion as string),
)

const countLabel = computed(() =>
  props.task.taskType === 'article-reading'
    ? `${props.task.count} ${props.task.unit}`
    : `${props.task.rounds}${lang.ssRoundsUnit}`,
)

const difficultyLabel = computed(() => {
  const labels: Record<number, string> = {
    1: lang.ssDifficultyBeginner as string,
    2: lang.ssDifficultyIntermediate as string,
    3: lang.ssDifficultyAdvanced as string,
  }
  return labels[props.task.difficulty] || ''
})
</script>

<style lang="scss" scoped>
.recommend-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;

  &:hover {
    border-color: rgba(0, 0, 0, 0.12);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);

    .card-arrow {
      color: #f97316;
    }

    .card-title {
      color: #ea580c;
    }
  }
}

.card-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: #111827;
  line-height: 1.4;
  transition: color 0.2s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-subtitle {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 11px;
  color: #9ca3af;
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
}

.meta-dot {
  margin: 0 4px;
}

.card-arrow {
  position: absolute;
  top: 14px;
  right: 14px;
  color: #d1d5db;
  flex-shrink: 0;
  transition: color 0.2s;
}
</style>
