<script setup lang="ts">
import ModalAuthentication from '~/components/ModalAuthentication.vue'

const toast = useToast()
const router = useRouter()
const modal = useModal()
const loginState = useLoginState()

useHead({
  titleTemplate(title) {
    return title ? `${ title } - 眩生花 AI 助手` : '眩生花 AI 助手'
  },
})

useSeoMeta({
  viewport: 'width=device-width, initial-scale=1.0, user-scalable=no',
})

onMounted(() => {
  loginState.checkSession().then(res => {
    if (!res && loginState.token) {
      toast.add({
        title: '登录失效',
        description: '登录已过期，请重新登录',
        color: 'red',
        icon: 'i-tabler-alert-triangle',
      })
      modal.open(ModalAuthentication)
    }
  })
})
</script>

<template>
  <div>
    <NuxtLoadingIndicator/>

    <NuxtLayout>
      <NuxtPage/>
    </NuxtLayout>

    <UModals/>
    <USlideovers/>
    <UNotifications/>
  </div>
</template>
