import { j as g } from "../../../../../_virtual/jsx-runtime.js";
import { useRef as n, useEffect as p } from "react";
import { a as c, b as y } from "../../../../sdk/dist/shared/chunk-DQXDGV67.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-UU2MSQXY.js";
import "../../../../sdk/dist/shared/chunk-T3LIA4YB.js";
import "../../../../sdk/dist/shared/chunk-UMHXXXVP.js";
import { useBrickStyle as R } from "../hooks/use-brick-style.js";
import { tx as w } from "../../../../style-system/dist/twind.js";
import { LatLng as x, Point as b, Map as k, TileLayer as L, Marker as j } from "../../../../../node_modules/.pnpm/leaflet@2.0.0-alpha/node_modules/leaflet/dist/leaflet-src.js";
/* empty css                                                                                          */
import M from "../components/BrickRoot.js";
function P({ brick: a, editable: u }) {
  const T = R(a), h = Object.values(T), e = a.props, m = n(null), f = n(null), t = n(null), r = n(null), v = n(!1), i = e.lat ?? c.lat, s = e.lng ?? c.lng;
  p(() => {
    async function o() {
      if (f.current)
        try {
          const l = new k(f.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([i, s], e.zoom ?? c.zoom);
          new L("https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png", {
            zIndex: 40
          }).addTo(l);
          const z = new j([i, s]).addTo(l);
          e.tooltip && z.bindTooltip(e.tooltip, {
            permanent: !0,
            direction: "bottom",
            sticky: !0,
            // Keep the tooltip open
            offset: new b(0, 10)
            // Adjust tooltip position
          }).openTooltip(), v.current = !0, t.current = l, r.current = z;
        } catch {
        }
    }
    return o(), () => {
      t.current && (t.current.remove(), t.current = null), r.current && (r.current = null);
    };
  }, []), p(() => {
    if (t.current && r.current) {
      const o = new x(i, s);
      t.current.setView(o, e.zoom ?? c.zoom), r.current.setLatLng(o), e.tooltip ? r.current.bindTooltip(e.tooltip, {
        permanent: !0,
        direction: "bottom",
        sticky: !0,
        // Keep the tooltip open
        offset: new b(0, 10)
        // Adjust tooltip position
      }).openTooltip() : r.current.unbindTooltip();
    }
  }, [i, s, e.tooltip, e.zoom]);
  const d = n(null);
  return p(() => {
    if (m.current && u) {
      const o = new ResizeObserver(() => {
        clearTimeout(d.current ?? void 0), d.current = setTimeout(() => {
          t.current && t.current.invalidateSize();
        }, 100);
      });
      return o.observe(m.current), () => {
        setTimeout(() => {
          o.disconnect();
        }, 200);
      };
    }
  }, []), /* @__PURE__ */ g.jsx(
    M,
    {
      brick: a,
      editable: u,
      manifest: y,
      className: w("rounded-[inherit] relative overflow-hidden", ...h),
      ref: m,
      children: /* @__PURE__ */ g.jsx("div", { ref: f, className: w("h-full w-full rounded-[inherit] absolute inset-0 z-40") })
    }
  );
}
export {
  P as default
};
//# sourceMappingURL=map.js.map
