import { useEffect } from 'react';
import DelegateTooltip from './DelegateTooltip';
import StateTooltip from './StateTooltip';
export default function Tooltip({
  delegate,
  candidatesTotal,
  allDelegatesAwarded,
  setActiveCand
}) {
  const {
    id
  } = delegate;
  useEffect(() => {
    setActiveCand(id || delegate.stateFips);
    return () => {
      setActiveCand(undefined);
    };
  }, [delegate]);
  if (id) {
    return <DelegateTooltip candidateId={id} data={delegate} delegates={candidatesTotal} allDelegatesAwarded={allDelegatesAwarded} />;
  }
  return <StateTooltip delegate={delegate} />;
}