<template>
  <ScreenLayout :show-back-btn="false">
    <div class="page-success">
      <div class="success-content">
        <div class="success-icon">
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
            <polyline points="22 4 12 14.01 9 11.01" />
          </svg>
        </div>

        <h1 class="success-title">登记成功</h1>
        <p class="success-message">欢迎您的到来</p>

        <div class="visitor-info">
          <div class="info-item">
            <span class="info-label">访客姓名</span>
            <span class="info-value">{{ visitorName }}</span>
          </div>
          <div class="info-item">
            <span class="info-label">登记时间</span>
            <span class="info-value">{{ currentTime }}</span>
          </div>
        </div>

        <div class="next-hint">
          <p>请前往{{ visitedPerson || '被访人' }}处</p>
          <p>感谢您的配合，祝您访问愉快</p>
        </div>
      </div>

      <button class="btn-return" @click="goToIdle">
        返回首页
      </button>
    </div>
  </ScreenLayout>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useVisitorStore } from '@/stores/visitor'
import { formatDateTime } from '@/utils/time'
import ScreenLayout from '@/layouts/ScreenLayout.vue'

const router = useRouter()
const visitorStore = useVisitorStore()

const currentTime = ref(formatDateTime())

const visitorName = computed(() => visitorStore.registrationInfo.visitorName || '访客')
const visitedPerson = computed(() => visitorStore.registrationInfo.visitedPerson || '')

const goToIdle = () => {
  visitorStore.clearVisitorData()
  router.push('/idle')
}

// 更新时间
let timer = null

onMounted(() => {
  timer = setInterval(() => {
    currentTime.value = formatDateTime()
  }, 1000)

  // 3秒后自动返回待机页
  setTimeout(() => {
    goToIdle()
  }, 10000)
})
</script>

<style scoped>
.page-success {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e9f8ff 0%, #dff8f5 50%, #f7fbff 100%);
  padding: 40px;
}

.success-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  animation: fadeInUp 0.6s ease-out;
}

.success-icon {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--success);
  border-radius: 50%;
  color: white;
  animation: scaleIn 0.5s ease-out 0.2s backwards;
}

.success-icon svg {
  width: 60px;
  height: 60px;
}

.success-title {
  font-size: 48px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.success-message {
  font-size: 24px;
  color: var(--text-secondary);
  margin: 0;
}

.visitor-info {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px 40px;
  box-shadow: var(--shadow-md);
  margin: 20px 0;
}

.info-item {
  display: flex;
  justify-content: space-between;
  gap: 40px;
  padding: 12px 0;
}

.info-item:not(:last-child) {
  border-bottom: 1px solid var(--border-light);
}

.info-label {
  font-size: 16px;
  color: var(--text-muted);
}

.info-value {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

.next-hint {
  margin-top: 20px;
}

.next-hint p {
  font-size: 18px;
  color: var(--text-secondary);
  margin: 8px 0;
}

.btn-return {
  width: 280px;
  height: 64px;
  font-size: 22px;
  font-weight: 500;
  background: var(--bg-card);
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.btn-return:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
</style>
