<template>
  <section class="payment-section">
    <div class="payment-card">
      <div class="payment-badge">联调演示 &middot; Mock 支付</div>
      <div class="payment-amount">¥{{ amount }}</div>
      <div class="payment-label">{{ doctorLabel }}</div>
      <div class="qr-placeholder" />
      <div class="qr-note">微信 / 支付宝 扫码支付</div>
    </div>
    <div class="tips-box">
      <div class="tl">支付说明</div>
      <div class="tt">当前为联调演示支付，不会产生真实扣费。支付成功后系统将自动确认预约。</div>
    </div>
    <button class="btn-accent" :disabled="store.cardActionSubmitting" @click="$emit('action', { actionName: 'mock_payment_paid', payload: { orderId } })">模拟支付完成</button>
  </section>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import type { CardInstance } from '../api/types';
import { useTerminalStore } from '../state/terminalStore';

const props = defineProps<{ card: CardInstance }>();
defineEmits<{ action: [data: { actionName: string; payload: Record<string, unknown> }] }>();

const store = useTerminalStore();

const amount = computed(() => props.card.cardData.amountYuan ?? props.card.cardData.amount ?? '25.00');
const orderId = computed(() => String(props.card.cardData.orderId ?? 'unknown'));
const doctorLabel = computed(() => {
  const dept = store.selection.departmentName;
  const doc = store.selection.doctorName;
  if (dept && doc) return `${dept} · ${doc}`;
  if (doc) return doc;
  return '';
});
</script>

<style scoped>
.payment-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.payment-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 20px;
  text-align: center;
}

.payment-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 12px;
}

.payment-amount {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.payment-label {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-bottom: 16px;
}

.qr-placeholder {
  margin: 0 auto 16px;
  width: 130px;
  height: 130px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  position: relative;
}

.qr-placeholder::before {
  content: '';
  width: 96px;
  height: 96px;
  background:
    repeating-linear-gradient(0deg, var(--accent), var(--accent) 6px, transparent 6px, transparent 12px),
    repeating-linear-gradient(90deg, var(--accent), var(--accent) 6px, transparent 6px, transparent 12px);
  border-radius: 4px;
  opacity: 0.3;
}

.qr-note {
  font-size: 10px;
  color: var(--warn-text);
  text-align: center;
}

.tips-box {
  padding: 12px 14px;
  background: var(--accent-faint);
  border-radius: var(--radius-sm);
}

.tips-box .tl {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.tips-box .tt {
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.5;
}

.btn-accent {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--surface);
  border-radius: var(--radius-sm);
  font-size: var(--fs-body);
  font-weight: 500;
  text-align: center;
  transition: background 0.15s ease;
}

.btn-accent:hover {
  background: color-mix(in oklch, var(--accent) 85%, black);
}
</style>
