<script setup lang="ts">
import { useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'
import { Collection, Setting, SwitchButton } from '@element-plus/icons-vue'
import { useAuthStore } from '@/stores/auth'

const router = useRouter()
const auth = useAuthStore()

async function logout() {
  try {
    await ElMessageBox.confirm('确认退出当前账号？', '退出登录', {
      type: 'warning',
      confirmButtonText: '退出',
      cancelButtonText: '取消',
    })
  } catch {
    return
  }
  auth.clearSession()
  await router.replace('/login')
}
</script>

<template>
  <div class="quiz-shell">
    <header class="quiz-header">
      <button class="quiz-brand" @click="router.push('/quiz')">
        <Collection class="w-5 h-5" />
        <span>QuickQuiz</span>
      </button>
      <div class="quiz-actions">
        <ElButton :icon="Setting" circle @click="router.push('/admin')" />
        <ElButton :icon="SwitchButton" circle @click="logout" />
      </div>
    </header>
    <RouterView />
  </div>
</template>

<style scoped>
.quiz-shell {
  min-height: 100vh;
}

.quiz-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--qq-line);
  background: rgba(247, 248, 244, 0.94);
  backdrop-filter: blur(12px);
}

.quiz-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--qq-ink);
  font-weight: 800;
  cursor: pointer;
}

.quiz-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
</style>
