'use client'

// React Imports
import { useEffect } from 'react'

// Next Imports
import { useRouter } from 'next/navigation'

// Config Imports
import themeConfig from '@configs/themeConfig'

const RootPage = () => {
  const router = useRouter()
  console.log('RootPage')

  useEffect(() => {
    // Check for authentication token
    const token = typeof window !== 'undefined' ? localStorage.getItem('auth_token') : null
    const user = typeof window !== 'undefined' ? localStorage.getItem('auth_user') : null

    if (token && user) {
      // Token exists and is valid, redirect to dashboard
      router.replace(themeConfig.homePageUrl)
    } else {
      // No token or invalid, redirect to login
      router.replace('/login')
    }
  }, [router])

  // Show nothing while redirecting
  return null
}

export default RootPage



