"use client";
import React, {useEffect} from 'react';
import {useRouter} from 'next/navigation';
import {useAuthStore} from '@/shared/store/authStore';
import {isBrowser} from "motion/react";

const PrivateRoute = ({children}: { children: React.ReactNode }) => {
  const {user, isAuthenticated} = useAuthStore();
  const router = useRouter();

  useEffect(() => {
    if (isBrowser && (!user || !isAuthenticated)) {
      router.push('/auth/login');
    }
  }, [user, isAuthenticated, router]);

  if (!isAuthenticated) {
    return null;
  }

  return <>{children}</>;
};

export default PrivateRoute;