import { useEffect } from "react";
import { usePageTrackingContext } from "../app/context/PageTrackingContext";

/**
 * Hook to track the current page for user activity logging
 * Call this hook at the top level of each page component
 * @param pageTitle - Persian title of the current page
 */
export function usePageTracking(pageTitle: string) {
  const { setCurrentPage } = usePageTrackingContext();

  useEffect(() => {
    // Set current page when component mounts
    setCurrentPage(pageTitle);

    // Clear current page when component unmounts
    return () => {
      setCurrentPage(null);
    };
  }, [pageTitle, setCurrentPage]);
}
