'use client'

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

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

// Type Imports
import type { ChildrenType } from '@core/types'

// Component Imports
import AuthRedirect from '@/components/AuthRedirect'

// Context Imports
import { useAuth } from '@/contexts/authContext'

export default function AuthGuard({ children }: ChildrenType) {
  const { isAuthenticated, isLoading } = useAuth()
  const router = useRouter()

  useEffect(() => {
    if (!isLoading && !isAuthenticated) {
      // Authentication will be handled by AuthRedirect component
    }
  }, [isAuthenticated, isLoading, router])

  if (isLoading) {
    // Show loading state while checking authentication
    return null // or a loading spinner
  }

  return <>{isAuthenticated ? children : <AuthRedirect />}</>
}
