import { Navigate } from 'react-router-dom'
import { useModules } from '../contexts/ModulesContext'

interface ModuleGuardProps {
  moduleId: string
  children: React.ReactNode
  redirectTo?: string
}

export function ModuleGuard({ moduleId, children, redirectTo = '/modules' }: ModuleGuardProps) {
  const { isActive } = useModules()
  if (!isActive(moduleId)) return <Navigate to={redirectTo} replace />
  return <>{children}</>
}
