<template>
  <div class="min-h-screen flex items-center justify-center bg-black/40">
    <div class="flex flex-col items-center gap-4">
      <svg class="animate-spin h-10 w-10 text-white/80" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
        <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
        <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
      </svg>
      <p class="text-white/60 text-sm">Loading...</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { isOnboardingComplete } from '@/composables/useOnboarding'

const router = useRouter()

onMounted(async () => {
  const devMode = import.meta.env.VITE_DEV_MODE
  if (devMode === 'setup' || devMode === 'existing') {
    router.replace('/login').catch(() => {})
    return
  }

  let seenOnboarding = false
  try {
    const result = await Promise.race([
      isOnboardingComplete(),
      new Promise<boolean>((resolve) => setTimeout(() => resolve(false), 5000)),
    ])
    seenOnboarding = result
  } catch {
    seenOnboarding = localStorage.getItem('neode_onboarding_complete') === '1'
  }
  router.replace(seenOnboarding ? '/login' : '/onboarding/intro').catch(() => {})
})
</script>
