import { useRef as f, useEffect as h } from "react";
import { useMapContext as P } from "./MapContext.js";
const C = 1e-6, Z = 1e-3, N = (b) => {
  const { api: o, boundingBox: a, center: t, zoom: e, zoomAnimation: r = !1 } = b, { enableFractionalZoom: g } = P(), p = f(), c = f(t), d = f(e);
  return h(() => {
    if (o && a) {
      const { top: n, left: i, bottom: l, right: u } = a;
      o.map?.getViewModel().setLookAtData({ bounds: new H.geo.Rect(n, i, l, u) }, r);
    }
  }, [a]), h(() => {
    const n = o.map;
    if (!(n && (t || e !== void 0)))
      return;
    const i = p.current !== n, l = t?.lat !== c.current?.lat || t?.lng !== c.current?.lng, u = e !== d.current;
    if (!(i || l || u))
      return;
    const s = {}, m = o.utils?.getCenter();
    t && m && (Math.abs(m.lat - t.lat) > C || Math.abs(m.lng - t.lng) > C) && (s.position = t);
    const M = g ? o.utils?.getPreciseZoom() : o.utils?.getZoom();
    e !== void 0 && M !== void 0 && Math.abs(M - e) > Z && (s.zoom = e), Object.keys(s).length > 0 && n.getViewModel().setLookAtData(s, r), p.current = n, c.current = t, d.current = e;
  }, [o, t, e, r, g]), null;
};
export {
  N as default
};
//# sourceMappingURL=MapPosition.js.map
