<script setup lang="ts">
import { Clock } from '@element-plus/icons-vue'

import type { ClaimKuaishouCloudFlowInfo } from '@/types/claim'

defineProps<{
  ticketCode: string
  canSubmitTicket: boolean
  submitting: boolean
  isBindingPreparing: boolean
  flow: ClaimKuaishouCloudFlowInfo
}>()

defineEmits<{
  'update:ticketCode': [value: string]
  submitTicket: []
}>()
</script>

<template>
  <section class="content-card">
    <h2>第 1 步：提交核销码</h2>
    <p class="muted">
      请先从快手小店复制核销码。验证通过后，系统会自动准备 Cloud
      绑定资源，不需要再让客服手工点"准备绑定资源"。
    </p>

    <el-input
      :model-value="ticketCode"
      placeholder="粘贴快手核销码"
      size="large"
      :disabled="!canSubmitTicket"
      @update:model-value="$emit('update:ticketCode', $event)"
      @keyup.enter="$emit('submitTicket')"
    />

    <el-button
      type="primary"
      size="large"
      :loading="submitting"
      :disabled="!canSubmitTicket"
      @click="$emit('submitTicket')"
    >
      验证核销码并继续
    </el-button>

    <div class="status-banner info">
      <el-icon><Clock /></el-icon>
      <span>{{
        isBindingPreparing
          ? '绑定资源会在核销通过后自动准备。'
          : '核销完成后会自动进入扫码绑定步骤。'
      }}</span>
    </div>

    <div v-if="flow.guideImages.length > 0" class="guide-section">
      <el-collapse>
        <el-collapse-item title="查看核销码图文指引" name="guide">
          <div class="guide-grid">
            <figure
              v-for="(imageUrl, index) in flow.guideImages"
              :key="imageUrl"
              class="guide-figure"
            >
              <img :src="imageUrl" :alt="`步骤 ${index + 1}`" />
              <figcaption>步骤 {{ index + 1 }}</figcaption>
            </figure>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </section>
</template>

<style scoped>
.content-card {
  width: 100%;
  max-width: 680px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 20px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(12px);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.content-card h2 {
  margin: 0;
  color: #0f172a;
}

.muted {
  margin: 0;
  color: #64748b;
  line-height: 1.6;
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 14px;
}

.status-banner.info {
  background: #eff6ff;
  color: #1d4ed8;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-figure {
  margin: 0;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  overflow: hidden;
}

.guide-figure img {
  width: 100%;
  display: block;
}

.guide-figure figcaption {
  padding: 10px 12px 14px;
  color: #475569;
  font-size: 13px;
}

@media (max-width: 720px) {
  .content-card {
    max-width: 100%;
  }

  .guide-grid {
    grid-template-columns: 1fr;
  }
}
</style>
