<script setup lang="ts">
import PageHeader from '@/components/PageHeader.vue'
import { dateZhCN, zhCN } from 'naive-ui'
import { useNowUser } from '@/stores/now-user.ts'
import { onMounted } from 'vue'
import { useHead } from '@unhead/vue'

const NOWUSER = useNowUser()

useHead({
  titleTemplate: '%s | NayHome',
})

onMounted(async () => {
  const user_id = localStorage.getItem('user-id')
  const access_token = localStorage.getItem('access-token')
  if (user_id && access_token) {
    try {
      await NOWUSER.loadUserInfo(Number(user_id), access_token)
    } catch {
      localStorage.removeItem('user-id')
      localStorage.removeItem('access-token')
      console.log('已移除 localstorage 中存储的验证信息。')
    }
  }
})
</script>

<template>
  <n-config-provider id="aapp" :date-locale="dateZhCN" :locale="zhCN">
    <div class="header-container">
      <page-header />
    </div>
    <div class="content-container">
      <n-message-provider>
        <router-view></router-view>
      </n-message-provider>
    </div>
    <div class="footer-container">🌸 Nya Home ~</div>
    <n-global-style />
  </n-config-provider>
</template>

<style scoped></style>
