<template>
  <el-dialog v-model="visible" title="访客通行凭证" width="400px" center>
    <div v-if="currentVisitor" class="qr">
      <div class="status-badge" :class="currentVisitor.status">
        {{ getStatusLabel(currentVisitor.status) }}
      </div>
      <vab-icon icon="qr-code-line" class="qr-code" />
      <div class="code-text">8392 1029 4857</div>
      <p class="tip">请向门岗出示此码或身份证</p>
      <el-divider />
      <div class="info-row">
        <span>访客：</span><strong>{{ currentVisitor.visitorName }}</strong>
      </div>
      <div class="info-row">
        <span>访问对象：</span><strong>{{ currentVisitor.studentName }}</strong>
      </div>
      <div class="info-row">
        <span>有效时间：</span><span>{{ currentVisitor.visitTime }} (24小时内)</span>
      </div>
    </div>
  </el-dialog>
</template>

<script setup>
import { ref } from 'vue'

const visible = ref(false)
const currentVisitor = ref(null)

const open = (visitor) => {
  currentVisitor.value = visitor
  visible.value = true
}

const getStatusLabel = (status) => {
  const map = { pending: '待访问', active: '访问中', left: '已离开' }
  return map[status]
}

defineExpose({
  open
})
</script>

<style lang="scss" scoped>
.qr {
  text-align: center;
  position: relative;
  padding: 20px;

  .status-badge {
    position: absolute;
    top: 0;
    right: 0;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: #fff;
    
    &.pending { background: #909399; }
    &.active { background: #67c23a; }
    &.left { background: #909399; }
  }

  .qr-code {
    font-size: 150px;
    color: #333;
  }
  
  .code-text {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 2px;
    margin: 10px 0;
  }

  .tip {
    font-size: 12px;
    color: #999;
    margin-bottom: 20px;
  }

  .info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
  }
}
</style>
