<template>
  <section class="error-card">
    <div class="error-icon">
      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <circle cx="12" cy="12" r="10" />
        <line x1="12" y1="8" x2="12" y2="12" />
        <line x1="12" y1="16" x2="12.01" y2="16" />
      </svg>
    </div>
    <div class="error-title">处理失败</div>
    <div class="error-desc">{{ message }}</div>
    <div v-if="traceId" class="error-trace">traceId: {{ traceId }}</div>
    <div class="error-btns">
      <button class="btn-accent" @click="onRetry">重试</button>
      <button class="btn-outline" @click="onRestart">重新开始</button>
    </div>
  </section>
</template>

<script setup lang="ts">
defineProps<{ message: string; traceId?: string }>();
const emit = defineEmits<{ retry: []; restart: [] }>();

function onRetry() {
  emit('retry');
}

function onRestart() {
  emit('restart');
}
</script>

<style scoped>
.error-card {
  border: 1px solid color-mix(in oklch, var(--danger) 30%, transparent);
  background: color-mix(in oklch, var(--danger) 4%, transparent);
  border-radius: var(--radius-md);
  padding: 24px 20px;
  text-align: center;
}

.error-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: color-mix(in oklch, var(--danger) 15%, transparent);
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  color: var(--danger);
}

.error-title {
  font-size: var(--fs-h3);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.error-desc {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-bottom: 6px;
  line-height: 1.5;
}

.error-trace {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-bottom: 16px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 4px;
  word-break: break-all;
}

.error-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-accent {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--surface);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background 0.15s ease;
}

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

.btn-outline {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--muted);
  background: transparent;
  transition: background 0.15s ease;
}

.btn-outline:hover {
  background: var(--bg);
}
</style>
