/**
 * Auth Plugin - Client Side Only
 *
 * Initializes authentication state from localStorage before any navigation occurs.
 * This ensures the auth middleware has the correct state when checking authentication.
 */

import { useAuthStore } from '~/store/auth'

export default defineNuxtPlugin(() => {
  const authStore = useAuthStore()

  // Initialize auth from localStorage on app load
  authStore.initializeAuth()

  console.log('[Auth Plugin] Initialized auth state:', {
    isAuthenticated: authStore.isAuthenticated,
    isTokenValid: authStore.isTokenValid,
    hasUser: !!authStore.currentUser
  })
})
