import { useEffect } from 'react';
import { usePathName } from '../DashboardTable';

const useSetCurrentCardInfoAfterMount = (
  data: any,
  setCardInfo: (elem: any) => void,
): void => {
  const currentCardId = usePathName().match(/\d+/g)?.[0];
  useEffect(() => {
    if (currentCardId) {
      setCardInfo(
        data?.find((card: any) => {
          return card.id === +currentCardId;
        }),
      );
    } else {
      setCardInfo(null);
    }
  }, [currentCardId, data, setCardInfo]);
};

export default useSetCurrentCardInfoAfterMount;
