'use client'

import { useEffect, ReactNode } from 'react'
import { useRouter } from 'next/navigation'

const APP_MODE = process.env.NEXT_PUBLIC_APP_MODE || 'landing'

interface ModeGuardProps {
  children: ReactNode
}

export default function ModeGuard({ children }: ModeGuardProps) {
  const router = useRouter()

  useEffect(() => {
    if (APP_MODE === 'landing') {
      router.replace('/')
    }
  }, [router])

  if (APP_MODE === 'landing') {
    return null
  }

  return <>{children}</>
}

export function isAppMode(): boolean {
  return APP_MODE === 'app'
}
