var Xe = Object.defineProperty;
var Ye = (n, i, o) => i in n ? Xe(n, i, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[i] = o;
var te = (n, i, o) => Ye(n, typeof i != "symbol" ? i + "" : i, o);
import { jsx as $e, Fragment as Ve } from "react/jsx-runtime";
import { PureComponent as Ze, Children as Ue, isValidElement as We, cloneElement as qe, memo as Oe, useContext as Se, useState as r, useEffect as t, useMemo as Ce } from "react";
import { applyUpdatersToPropsAndRegisterEvents as Ae, unregisterEvents as Me } from "./index-map-helper.js";
import { MapContext as Be } from "./index-map-context.js";
const je = {
  onAnimationChanged: "animation_changed",
  onClick: "click",
  onClickableChanged: "clickable_changed",
  onCursorChanged: "cursor_changed",
  onDblClick: "dblclick",
  onDrag: "drag",
  onDragEnd: "dragend",
  onDraggableChanged: "draggable_changed",
  onDragStart: "dragstart",
  onFlatChanged: "flat_changed",
  onIconChanged: "icon_changed",
  onMouseDown: "mousedown",
  onMouseOut: "mouseout",
  onMouseOver: "mouseover",
  onMouseUp: "mouseup",
  onPositionChanged: "position_changed",
  onRightClick: "rightclick",
  onShapeChanged: "shape_changed",
  onTitleChanged: "title_changed",
  onVisibleChanged: "visible_changed",
  onZindexChanged: "zindex_changed"
}, Fe = {
  animation(n, i) {
  },
  clickable(n, i) {
    n.gmpClickable = i;
  },
  cursor(n, i) {
  },
  draggable(n, i) {
    n.draggable = i;
  },
  icon(n, i) {
  },
  label(n, i) {
  },
  map(n, i) {
    n.map = i;
  },
  opacity(n, i) {
  },
  options(n, i) {
  },
  position(n, i) {
    n.position = i;
  },
  shape(n, i) {
  },
  title(n, i) {
    n.title = i;
  },
  visible(n, i) {
  },
  zIndex(n, i) {
    n.zIndex = i;
  }
}, ne = {};
function De({
  position: n,
  options: i,
  clusterer: o,
  noClustererRedraw: W,
  children: q,
  draggable: l,
  visible: Ge,
  animation: He,
  clickable: a,
  cursor: Ie,
  icon: Je,
  label: Ke,
  opacity: Ne,
  shape: Qe,
  title: g,
  zIndex: m,
  onClick: d,
  onDblClick: p,
  onDrag: v,
  onDragEnd: c,
  onDragStart: f,
  onMouseOut: L,
  onMouseOver: u,
  onMouseUp: h,
  onMouseDown: _,
  onRightClick: k,
  onClickableChanged: b,
  onCursorChanged: x,
  onAnimationChanged: y,
  onDraggableChanged: E,
  onFlatChanged: P,
  onIconChanged: w,
  onPositionChanged: z,
  onShapeChanged: A,
  onTitleChanged: M,
  onVisibleChanged: j,
  onZindexChanged: F,
  onLoad: se,
  onUnmount: ie
}) {
  const B = Se(Be), [e, Re] = r(null), [G, re] = r(null), [H, oe] = r(null), [I, le] = r(null), [J, ae] = r(null), [K, ge] = r(null), [N, me] = r(null), [Q, de] = r(null), [R, pe] = r(null), [T, ve] = r(null), [ce, fe] = r(null), [X, Le] = r(null), [Y, ue] = r(null), [$, he] = r(null), [V, _e] = r(null), [Z, ke] = r(null), [O, be] = r(null), [S, xe] = r(null), [ye, Ee] = r(null), [C, Pe] = r(null), [D, we] = r(null), [ee, ze] = r(null);
  t(() => {
    e !== null && (e.map = B);
  }, [B]), t(() => {
  }, [e, i]), t(() => {
    typeof l < "u" && e !== null && (e.draggable = l);
  }, [e, l]), t(() => {
    n && e !== null && (e.position = n);
  }, [e, n]), t(() => {
  }, [e, Ge]), t(() => {
  }, [e, He]), t(() => {
    e && a !== void 0 && (e.gmpClickable = a);
  }, [e, a]), t(() => {
  }, [e, Ie]), t(() => {
  }, [e, Je]), t(() => {
  }, [e, Ke]), t(() => {
  }, [e, Ne]), t(() => {
  }, [e, Qe]), t(() => {
    e && g !== void 0 && (e.title = g);
  }, [e, g]), t(() => {
    e && m !== void 0 && (e.zIndex = m);
  }, [e, m]), t(() => {
    e && p && (G !== null && google.maps.event.removeListener(G), re(google.maps.event.addListener(e, "dblclick", p)));
  }, [p]), t(() => {
    e && c && (H !== null && google.maps.event.removeListener(H), oe(google.maps.event.addListener(e, "dragend", c)));
  }, [c]), t(() => {
    e && f && (I !== null && google.maps.event.removeListener(I), le(google.maps.event.addListener(e, "dragstart", f)));
  }, [f]), t(() => {
    e && _ && (J !== null && google.maps.event.removeListener(J), ae(google.maps.event.addListener(e, "mousedown", _)));
  }, [_]), t(() => {
    e && L && (K !== null && google.maps.event.removeListener(K), ge(google.maps.event.addListener(e, "mouseout", L)));
  }, [L]), t(() => {
    e && u && (N !== null && google.maps.event.removeListener(N), me(google.maps.event.addListener(e, "mouseover", u)));
  }, [u]), t(() => {
    e && h && (Q !== null && google.maps.event.removeListener(Q), de(google.maps.event.addListener(e, "mouseup", h)));
  }, [h]), t(() => {
    e && k && (R !== null && google.maps.event.removeListener(R), pe(google.maps.event.addListener(e, "rightclick", k)));
  }, [k]), t(() => {
    e && d && (T !== null && google.maps.event.removeListener(T), ve(google.maps.event.addListener(e, "click", d)));
  }, [d]), t(() => {
    e && v && (ce !== null && google.maps.event.removeListener(ce), fe(google.maps.event.addListener(e, "drag", v)));
  }, [v]), t(() => {
    e && b && (X !== null && google.maps.event.removeListener(X), Le(google.maps.event.addListener(e, "clickable_changed", b)));
  }, [b]), t(() => {
    e && x && (Y !== null && google.maps.event.removeListener(Y), ue(google.maps.event.addListener(e, "cursor_changed", x)));
  }, [x]), t(() => {
    e && y && ($ !== null && google.maps.event.removeListener($), he(google.maps.event.addListener(e, "animation_changed", y)));
  }, [y]), t(() => {
    e && E && (V !== null && google.maps.event.removeListener(V), _e(google.maps.event.addListener(e, "draggable_changed", E)));
  }, [E]), t(() => {
    e && P && (Z !== null && google.maps.event.removeListener(Z), ke(google.maps.event.addListener(e, "flat_changed", P)));
  }, [P]), t(() => {
    e && w && (O !== null && google.maps.event.removeListener(O), be(google.maps.event.addListener(e, "icon_changed", w)));
  }, [w]), t(() => {
    e && z && (S !== null && google.maps.event.removeListener(S), xe(google.maps.event.addListener(e, "position_changed", z)));
  }, [z]), t(() => {
    e && A && (ye !== null && google.maps.event.removeListener(ye), Ee(google.maps.event.addListener(e, "shape_changed", A)));
  }, [A]), t(() => {
    e && M && (C !== null && google.maps.event.removeListener(C), Pe(google.maps.event.addListener(e, "title_changed", M)));
  }, [M]), t(() => {
    e && j && (D !== null && google.maps.event.removeListener(D), we(google.maps.event.addListener(e, "visible_changed", j)));
  }, [j]), t(() => {
    e && F && (ee !== null && google.maps.event.removeListener(ee), ze(google.maps.event.addListener(e, "zindex_changed", F)));
  }, [F]), t(() => {
    const U = {
      ...i || ne,
      ...o ? ne : {
        map: B
      },
      position: n
    }, s = new google.maps.marker.AdvancedMarkerElement(U);
    return o || (s.map = B), n && (s.position = n), typeof l < "u" && (s.draggable = l), typeof a < "u" && (s.gmpClickable = a), typeof g == "string" && (s.title = g), typeof m == "number" && (s.zIndex = m), p && re(google.maps.event.addListener(s, "dblclick", p)), c && oe(google.maps.event.addListener(s, "dragend", c)), f && le(google.maps.event.addListener(s, "dragstart", f)), _ && ae(google.maps.event.addListener(s, "mousedown", _)), L && ge(google.maps.event.addListener(s, "mouseout", L)), u && me(google.maps.event.addListener(s, "mouseover", u)), h && de(google.maps.event.addListener(s, "mouseup", h)), k && pe(google.maps.event.addListener(s, "rightclick", k)), d && ve(google.maps.event.addListener(s, "click", d)), v && fe(google.maps.event.addListener(s, "drag", v)), b && Le(google.maps.event.addListener(s, "clickable_changed", b)), x && ue(google.maps.event.addListener(s, "cursor_changed", x)), y && he(google.maps.event.addListener(s, "animation_changed", y)), E && _e(google.maps.event.addListener(s, "draggable_changed", E)), P && ke(google.maps.event.addListener(s, "flat_changed", P)), w && be(google.maps.event.addListener(s, "icon_changed", w)), z && xe(google.maps.event.addListener(s, "position_changed", z)), A && Ee(google.maps.event.addListener(s, "shape_changed", A)), M && Pe(google.maps.event.addListener(s, "title_changed", M)), j && we(google.maps.event.addListener(s, "visible_changed", j)), F && ze(google.maps.event.addListener(s, "zindex_changed", F)), Re(s), se && se(s), () => {
      G !== null && google.maps.event.removeListener(G), H !== null && google.maps.event.removeListener(H), I !== null && google.maps.event.removeListener(I), J !== null && google.maps.event.removeListener(J), K !== null && google.maps.event.removeListener(K), N !== null && google.maps.event.removeListener(N), Q !== null && google.maps.event.removeListener(Q), R !== null && google.maps.event.removeListener(R), T !== null && google.maps.event.removeListener(T), X !== null && google.maps.event.removeListener(X), Y !== null && google.maps.event.removeListener(Y), $ !== null && google.maps.event.removeListener($), V !== null && google.maps.event.removeListener(V), Z !== null && google.maps.event.removeListener(Z), O !== null && google.maps.event.removeListener(O), S !== null && google.maps.event.removeListener(S), C !== null && google.maps.event.removeListener(C), D !== null && google.maps.event.removeListener(D), ee !== null && google.maps.event.removeListener(ee), ie && ie(s), o || s && (s.map = null);
    };
  }, []);
  const Te = Ce(() => q ? Ue.map(q, (U) => We(U) ? qe(U, {
    anchor: e
  }) : U) : null, [q, e]);
  return $e(Ve, {
    children: Te
  }) || null;
}
const ot = Oe(De);
class et extends Ze {
  constructor() {
    super(...arguments);
    te(this, "registeredEvents", []);
    te(this, "marker");
  }
  componentDidMount() {
    const o = {
      ...this.props.options || ne,
      ...this.props.clusterer ? ne : {
        map: this.context
      },
      position: this.props.position
    };
    this.marker = new google.maps.marker.AdvancedMarkerElement(o), this.props.clusterer || (this.marker.map = this.context), this.registeredEvents = Ae({
      updaterMap: Fe,
      eventMap: je,
      prevProps: {},
      nextProps: this.props,
      instance: this.marker
    }), this.props.onLoad && this.props.onLoad(this.marker);
  }
  componentDidUpdate(o) {
    this.marker && (Me(this.registeredEvents), this.registeredEvents = Ae({
      updaterMap: Fe,
      eventMap: je,
      prevProps: o,
      nextProps: this.props,
      instance: this.marker
    }));
  }
  componentWillUnmount() {
    this.marker && (this.props.onUnmount && this.props.onUnmount(this.marker), Me(this.registeredEvents), this.props.clusterer || this.marker && (this.marker.map = null));
  }
  render() {
    let o = null;
    return this.props.children && (o = Ue.map(this.props.children, (W) => We(W) ? qe(W, {
      anchor: this.marker
    }) : W)), o || null;
  }
}
te(et, "contextType", Be);
export {
  et as Marker,
  ot as MarkerF
};
