import { useRef, useEffect } from "react";
/* global google */

const useMap = (mapDiv, lat = 25, lng = -25, zoom = 0) => {
  const map = useRef(null);
  useEffect(() => {
    if (map.current) {
      return;
    }

    map.current = new google.maps.Map(mapDiv.current, {
      center: { lat, lng },
      zoom,
      disableDefaultUI: true,
      fullscreenControl: false,
    });
  }, [mapDiv, lat, lng, zoom]);

  return map;
};

export default useMap;
