import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

const DASHBOARD_LAYOUT_CONTENT_ID = 'dashboard-layout-content';

const PATHS_TO_AVOID = ['/employee-lifecycle/tasks'];

const useScrollReset = () => {
  const location = useLocation();

  useEffect(() => {
    const shouldSkip = PATHS_TO_AVOID.some(path =>
      location.pathname.includes(path),
    );
    if (shouldSkip) return;

    const dashboardContent = document.getElementById(
      DASHBOARD_LAYOUT_CONTENT_ID,
    );
    if (dashboardContent) {
      dashboardContent.scrollTo({ top: 0, behavior: 'smooth' });
    } else {
      window.scrollTo({ top: 0, behavior: 'smooth' });
    }
  }, [location]);
};

export default useScrollReset;
