'use client';

import { useState, useEffect } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';

export const usePreloader = () => {
  const pathname = usePathname();
  const searchParams = useSearchParams();
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    // Show preloader on every route change
    setLoading(true);

    // Hide preloader after a short delay to ensure animation visibility
    const timer = setTimeout(() => {
      setLoading(false);
    }, 1000); // 1 second duration for transition

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

  return { loading };
};
