<template>
  <div class="book-cover-card" @click="emit('click', book)">
    <div class="book-cover" :class="{ 'is-selected': selected }">
      <!-- 已选角标 -->
      <div v-if="selected" class="selected-check">
        <svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
          <polyline
            points="4,10 8.5,15 16,6"
            stroke="white"
            stroke-width="2.5"
            stroke-linecap="round"
            stroke-linejoin="round"
          />
        </svg>
      </div>
      <!-- 年份 / 级别徽标（未选中时展示） -->
      <div v-else class="cover-badges">
        <span v-if="book.year" class="badge">{{ book.year }}</span>
        <span v-if="book.level" class="badge">{{ book.level }}</span>
      </div>
      <div class="cover-title">ENGLISH</div>
    </div>
    <p class="book-name">{{ book.name }}</p>
    <p class="book-subtitle">{{ book.subtitle }}</p>
  </div>
</template>

<script setup lang="ts">
export interface BookItem {
  id: number
  year: string | null
  level: string | null
  name: string
  subtitle: string
}

withDefaults(
  defineProps<{
    book: BookItem
    selected?: boolean
  }>(),
  { selected: false }
)

const emit = defineEmits<{
  (e: 'click', book: BookItem): void
}>()
</script>

<style scoped lang="scss">
.book-cover-card {
  display: flex;
  flex-direction: column;
  cursor: pointer;

  &:hover .book-cover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }
}

.book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  background: linear-gradient(160deg, #56d6f0 0%, #3bbce0 40%, #6ee7f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.15s;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 3px solid transparent;

  &::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50% 50% 0 0;
  }

  &.is-selected {
    border-color: var(--color-text-brand);
    box-shadow: 0 0 0 3px rgba(45, 111, 224, 0.18);
  }
}

/* 已选角标 */
.selected-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-brand);
  display: flex;
  align-items: center;
  justify-content: center;

  svg {
    width: 18px;
    height: 18px;
  }
}

/* 年份 / 级别徽标 */
.cover-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  z-index: 1;
}

.badge {
  background: #3bbce0;
  color: #fff;
  font-size: 18px;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}

.cover-title {
  position: relative;
  z-index: 1;
  font-size: 26px;
  letter-spacing: 2px;
  background: linear-gradient(
    180deg,
    #ff6bb5 0%,
    #ffcc00 30%,
    #3ddb7d 60%,
    #3d78f2 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.book-name {
  margin-top: 12px;
  font-size: 22px;
  color: #222;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-subtitle {
  margin-top: 4px;
  font-size: 20px;
  color: #888;
  text-align: center;
}
</style>
