// utils/zoomAndCenterUtils.js
/* export const zoomIn = (e, map) => {
  if (!map) {
    console.error("map is not defined in zoomIn");
    return;
  }
  map.flyTo(e.latlng, map.getZoom() + 1);
  localStorage.setItem("mapZoom", map.getZoom());
  localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
}; */

export const zoomIn = (e, map) => {
  if (!map) {
    console.error("map is not defined in zoomIn");
    return;
  }

  const currentZoom = map.getZoom();

  if (currentZoom < 14) {
    map.flyTo(e.latlng, 14);
    localStorage.setItem("mapZoom", 16);
    localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
  }
};

export const zoomOut = (map) => {
  if (!map) {
    console.error("map is not defined in zoomOut");
    return;
  }

  const currentZoom = map.getZoom();

  if (currentZoom > 7) {
    const x = 51.41321407879154;
    const y = 7.739617925303934;
    const zoom = 7;

    map.flyTo([x, y], zoom);
    localStorage.setItem("mapZoom", zoom);
    localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
  }
};

export const centerHere = (e, map) => {
  if (!map) {
    console.error("map is not defined in centerHere");
    return;
  }
  map.panTo(e.latlng);
  localStorage.setItem("mapZoom", map.getZoom());
  localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
};
