<template>
  <div class="min-h-screen w-full flex items-center justify-center">
    <UCard variant="subtle" class="w-full max-w-sm text-center">
      <div class="flex flex-col items-center gap-4 py-4">
        <UIcon name="i-lucide-loader-circle" class="size-10 text-primary animate-spin" />
        <p class="text-xl font-medium text-muted">
          {{ $t('auth.redirecting') }}
        </p>
      </div>
    </UCard>
  </div>
</template>

<script setup lang="ts">
definePageMeta({ auth: false, layout: 'auth' })

const { t: $t } = useI18n()

onMounted(async () => {
  const logger = useLogger().withTag('auth callback')
  try {
    // Check if we're in a popup window opened by nuxt-auth-utils
    if (window.opener) {
      window.close()
      return
    }
    // Regular redirect flow (not a popup)
    await navigateTo('/')
  } catch (e) {
    logger.error('Error during login', e)
  }
})
</script>
