<template>
  <div class="error-page">
    <div class="error-card">
      <div class="error-code">{{ statusCode }}</div>
      <div class="error-message">{{ statusMessage }}</div>
      <BoButton type="primary" @click="handleHome">返回首页</BoButton>
    </div>
  </div>
</template>

<script setup lang="ts">
import { BoButton } from 'bolt-ui'

const props = defineProps<{
  statusCode: number
  statusMessage?: string
}>()

const statusMessage = computed(() => {
  if (props.statusMessage) return props.statusMessage
  if (props.statusCode === 404) return '页面不存在'
  if (props.statusCode >= 500) return '服务器开小差了'
  return '出错了'
})

function handleHome() {
  clearError({ redirect: '/' })
}
</script>

<style scoped>
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-canvas);
  padding: 2rem;
}

.error-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.error-code {
  font-family: var(--font-display);
  font-size: 5rem;
  color: var(--color-primary);
  line-height: 1;
}

.error-message {
  font-size: 1.125rem;
  color: var(--color-body);
}
</style>
