'use client';

import { useEffect } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { ROUTES } from '@/constants';
import { isSessionFlow, isSessionFlowAllowedPath } from '@/utils/sessionFlow';

export function SessionFlowGuard({ children }: { children: React.ReactNode }) {
  const pathname = usePathname();
  const router = useRouter();

  useEffect(() => {
    if (!isSessionFlow() || !pathname) return;
    if (!isSessionFlowAllowedPath(pathname)) {
      router.replace(ROUTES.MOBILE_ACCOUNT);
    }
  }, [pathname, router]);

  return <>{children}</>;
}
