'use client';

import { useState, useEffect } from 'react';
import { usePathname } from 'next/navigation';
import PageTransitionLoader from '@/app/components/PageTransitionLoader';

export default function NavigationEventsProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  const pathname = usePathname();
  const [isLoading, setIsLoading] = useState(false);

  useEffect(() => {
    setIsLoading(true);

    const timeout = setTimeout(() => {
      setIsLoading(false);
    }, 500); // simulate a delay to show the loader (adjust timing as you want)

    return () => clearTimeout(timeout);
  }, [pathname]);

  return (
    <>
      <PageTransitionLoader isLoading={isLoading} />
      {children}
    </>
  );
}
