import { j as g } from "../../../../../_virtual/jsx-runtime.js";
import { useRef as n, useEffect as f } from "react";
import { a, b as y } from "../../../../sdk/dist/shared/chunk-VDX2J22H.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-6PGAWO4H.js";
import "../../../../sdk/dist/shared/chunk-F4JNKU7J.js";
import "../../../../sdk/dist/shared/chunk-7UBMXMNJ.js";
import "../../../../sdk/dist/shared/chunk-JRCVYDCD.js";
import { useBrickStyle as R } from "../hooks/use-brick-style.js";
import { tx as b } from "../../../../style-system/dist/twind.js";
import { LatLng as x, Point as w, Map as k, TileLayer as L, Marker as F } from "../../../../../node_modules/.pnpm/leaflet@2.0.0-alpha/node_modules/leaflet/dist/leaflet-src.js";
/* empty css                                                                                          */
import j from "../components/BrickRoot.js";
function _({ brick: c, editable: u }) {
  const T = R(c), h = Object.values(T), t = c.props, m = n(null), p = n(null), e = n(null), r = n(null), v = n(!1), s = t.lat ?? a.lat, i = t.lng ?? a.lng;
  f(() => {
    async function o() {
      if (p.current)
        try {
          const l = new k(p.current, {
            zoomControl: !1,
            attributionControl: !1,
            dragging: !1,
            // Disable dragging for static maps
            // @ts-ignore @types/leaflet are not in sync with latest leadflet beta, pingchZoom does exist!
            pinchZoom: !1,
            // Disable touch zoom for static maps
            scrollWheelZoom: !1,
            // Disable scroll wheel zoom for static maps
            doubleClickZoom: !1,
            // Disable double click zoom for static maps
            boxZoom: !1,
            // Disable box zoom for static maps
            keyboard: !1,
            // Disable keyboard controls for static maps
            trackResize: u
            // Enable resize tracking
          }).setView([parseFloat(s), parseFloat(i)], t.zoom ?? a.zoom);
          new L("https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png", {
            zIndex: 40
          }).addTo(l);
          const z = new F([parseFloat(s), parseFloat(i)]).addTo(l);
          t.tooltip && z.bindTooltip(t.tooltip, {
            permanent: !0,
            direction: "bottom",
            sticky: !0,
            // Keep the tooltip open
            offset: new w(0, 10)
            // Adjust tooltip position
          }).openTooltip(), v.current = !0, e.current = l, r.current = z;
        } catch {
        }
    }
    return o(), () => {
      e.current && (e.current.remove(), e.current = null), r.current && (r.current = null);
    };
  }, []), f(() => {
    if (e.current && r.current) {
      const o = new x(parseFloat(s), parseFloat(i));
      e.current.setView(o, t.zoom ?? a.zoom), r.current.setLatLng(o), t.tooltip ? r.current.bindTooltip(t.tooltip, {
        permanent: !0,
        direction: "bottom",
        sticky: !0,
        // Keep the tooltip open
        offset: new w(0, 10)
        // Adjust tooltip position
      }).openTooltip() : r.current.unbindTooltip();
    }
  }, [s, i, t.tooltip, t.zoom]);
  const d = n(null);
  return f(() => {
    if (m.current && u) {
      const o = new ResizeObserver(() => {
        clearTimeout(d.current ?? void 0), d.current = setTimeout(() => {
          e.current && e.current.invalidateSize();
        }, 100);
      });
      return o.observe(m.current), () => {
        setTimeout(() => {
          o.disconnect();
        }, 200);
      };
    }
  }, []), /* @__PURE__ */ g.jsx(
    j,
    {
      brick: c,
      editable: u,
      manifest: y,
      className: b("rounded-[inherit] relative overflow-hidden", ...h),
      ref: m,
      children: /* @__PURE__ */ g.jsx("div", { ref: p, className: b("h-full w-full rounded-[inherit] absolute inset-0 z-40") })
    }
  );
}
export {
  _ as default
};
//# sourceMappingURL=map.js.map
