import { P as f, u as _, i as d, j as A } from "./reactcomponent-b64d1356.mjs";
import { useState as j, useEffect as C } from "react";
import "react-dom";
function D(o, e, t, r) {
  function s(i) {
    return i instanceof t ? i : new t(function(n) {
      n(i);
    });
  }
  return new (t || (t = Promise))(function(i, n) {
    function c(a) {
      try {
        p(r.next(a));
      } catch (u) {
        n(u);
      }
    }
    function l(a) {
      try {
        p(r.throw(a));
      } catch (u) {
        n(u);
      }
    }
    function p(a) {
      a.done ? i(a.value) : s(a.value).then(c, l);
    }
    p((r = r.apply(o, e || [])).next());
  });
}
function T(o) {
  return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
}
var O = function o(e, t) {
  if (e === t)
    return !0;
  if (e && t && typeof e == "object" && typeof t == "object") {
    if (e.constructor !== t.constructor)
      return !1;
    var r, s, i;
    if (Array.isArray(e)) {
      if (r = e.length, r != t.length)
        return !1;
      for (s = r; s-- !== 0; )
        if (!o(e[s], t[s]))
          return !1;
      return !0;
    }
    if (e.constructor === RegExp)
      return e.source === t.source && e.flags === t.flags;
    if (e.valueOf !== Object.prototype.valueOf)
      return e.valueOf() === t.valueOf();
    if (e.toString !== Object.prototype.toString)
      return e.toString() === t.toString();
    if (i = Object.keys(e), r = i.length, r !== Object.keys(t).length)
      return !1;
    for (s = r; s-- !== 0; )
      if (!Object.prototype.hasOwnProperty.call(t, i[s]))
        return !1;
    for (s = r; s-- !== 0; ) {
      var n = i[s];
      if (!o(e[n], t[n]))
        return !1;
    }
    return !0;
  }
  return e !== e && t !== t;
}, $ = /* @__PURE__ */ T(O);
const P = "__googleMapsScriptId";
var I;
(function(o) {
  o[o.INITIALIZED = 0] = "INITIALIZED", o[o.LOADING = 1] = "LOADING", o[o.SUCCESS = 2] = "SUCCESS", o[o.FAILURE = 3] = "FAILURE";
})(I || (I = {}));
class w {
  /**
   * Creates an instance of Loader using [[LoaderOptions]]. No defaults are set
   * using this library, instead the defaults are set by the Google Maps
   * JavaScript API server.
   *
   * ```
   * const loader = Loader({apiKey, version: 'weekly', libraries: ['places']});
   * ```
   */
  constructor({ apiKey: e, authReferrerPolicy: t, channel: r, client: s, id: i = P, language: n, libraries: c = [], mapIds: l, nonce: p, region: a, retries: u = 3, url: h = "https://maps.googleapis.com/maps/api/js", version: g }) {
    if (this.callbacks = [], this.done = !1, this.loading = !1, this.errors = [], this.apiKey = e, this.authReferrerPolicy = t, this.channel = r, this.client = s, this.id = i || P, this.language = n, this.libraries = c, this.mapIds = l, this.nonce = p, this.region = a, this.retries = u, this.url = h, this.version = g, w.instance) {
      if (!$(this.options, w.instance.options))
        throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(w.instance.options)}`);
      return w.instance;
    }
    w.instance = this;
  }
  get options() {
    return {
      version: this.version,
      apiKey: this.apiKey,
      channel: this.channel,
      client: this.client,
      id: this.id,
      libraries: this.libraries,
      language: this.language,
      region: this.region,
      mapIds: this.mapIds,
      nonce: this.nonce,
      url: this.url,
      authReferrerPolicy: this.authReferrerPolicy
    };
  }
  get status() {
    return this.errors.length ? I.FAILURE : this.done ? I.SUCCESS : this.loading ? I.LOADING : I.INITIALIZED;
  }
  get failed() {
    return this.done && !this.loading && this.errors.length >= this.retries + 1;
  }
  /**
   * CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
   *
   * @ignore
   * @deprecated
   */
  createUrl() {
    let e = this.url;
    return e += "?callback=__googleMapsCallback&loading=async", this.apiKey && (e += `&key=${this.apiKey}`), this.channel && (e += `&channel=${this.channel}`), this.client && (e += `&client=${this.client}`), this.libraries.length > 0 && (e += `&libraries=${this.libraries.join(",")}`), this.language && (e += `&language=${this.language}`), this.region && (e += `&region=${this.region}`), this.version && (e += `&v=${this.version}`), this.mapIds && (e += `&map_ids=${this.mapIds.join(",")}`), this.authReferrerPolicy && (e += `&auth_referrer_policy=${this.authReferrerPolicy}`), e;
  }
  deleteScript() {
    const e = document.getElementById(this.id);
    e && e.remove();
  }
  /**
   * Load the Google Maps JavaScript API script and return a Promise.
   * @deprecated, use importLibrary() instead.
   */
  load() {
    return this.loadPromise();
  }
  /**
   * Load the Google Maps JavaScript API script and return a Promise.
   *
   * @ignore
   * @deprecated, use importLibrary() instead.
   */
  loadPromise() {
    return new Promise((e, t) => {
      this.loadCallback((r) => {
        r ? t(r.error) : e(window.google);
      });
    });
  }
  importLibrary(e) {
    return this.execute(), google.maps.importLibrary(e);
  }
  /**
   * Load the Google Maps JavaScript API script with a callback.
   * @deprecated, use importLibrary() instead.
   */
  loadCallback(e) {
    this.callbacks.push(e), this.execute();
  }
  /**
   * Set the script on document.
   */
  setScript() {
    var e, t;
    if (document.getElementById(this.id)) {
      this.callback();
      return;
    }
    const r = {
      key: this.apiKey,
      channel: this.channel,
      client: this.client,
      libraries: this.libraries.length && this.libraries,
      v: this.version,
      mapIds: this.mapIds,
      language: this.language,
      region: this.region,
      authReferrerPolicy: this.authReferrerPolicy
    };
    Object.keys(r).forEach(
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      (i) => !r[i] && delete r[i]
    ), !((t = (e = window == null ? void 0 : window.google) === null || e === void 0 ? void 0 : e.maps) === null || t === void 0) && t.importLibrary || ((i) => {
      let n, c, l, p = "The Google Maps JavaScript API", a = "google", u = "importLibrary", h = "__ib__", g = document, m = window;
      m = m[a] || (m[a] = {});
      const b = m.maps || (m.maps = {}), M = /* @__PURE__ */ new Set(), E = new URLSearchParams(), S = () => (
        // @ts-ignore
        n || (n = new Promise((y, v) => D(this, void 0, void 0, function* () {
          var k;
          yield c = g.createElement("script"), c.id = this.id, E.set("libraries", [...M] + "");
          for (l in i)
            E.set(l.replace(/[A-Z]/g, (R) => "_" + R[0].toLowerCase()), i[l]);
          E.set("callback", a + ".maps." + h), c.src = this.url + "?" + E, b[h] = y, c.onerror = () => n = v(Error(p + " could not load.")), c.nonce = this.nonce || ((k = g.querySelector("script[nonce]")) === null || k === void 0 ? void 0 : k.nonce) || "", g.head.append(c);
        })))
      );
      b[u] ? console.warn(p + " only loads once. Ignoring:", i) : b[u] = (y, ...v) => M.add(y) && S().then(() => b[u](y, ...v));
    })(r);
    const s = this.libraries.map((i) => this.importLibrary(i));
    s.length || s.push(this.importLibrary("core")), Promise.all(s).then(() => this.callback(), (i) => {
      const n = new ErrorEvent("error", { error: i });
      this.loadErrorCallback(n);
    });
  }
  /**
   * Reset the loader state.
   */
  reset() {
    this.deleteScript(), this.done = !1, this.loading = !1, this.errors = [], this.onerrorEvent = null;
  }
  resetIfRetryingFailed() {
    this.failed && this.reset();
  }
  loadErrorCallback(e) {
    if (this.errors.push(e), this.errors.length <= this.retries) {
      const t = this.errors.length * Math.pow(2, this.errors.length);
      console.error(`Failed to load Google Maps script, retrying in ${t} ms.`), setTimeout(() => {
        this.deleteScript(), this.setScript();
      }, t);
    } else
      this.onerrorEvent = e, this.callback();
  }
  callback() {
    this.done = !0, this.loading = !1, this.callbacks.forEach((e) => {
      e(this.onerrorEvent);
    }), this.callbacks = [];
  }
  execute() {
    if (this.resetIfRetryingFailed(), !this.loading)
      if (this.done)
        this.callback();
      else {
        if (window.google && window.google.maps && window.google.maps.version) {
          console.warn("Google Maps already loaded outside @googlemaps/js-api-loader. This may result in undesirable behavior as options and script parameters may not match."), this.callback();
          return;
        }
        this.loading = !0, this.setScript();
      }
  }
}
U.propTypes = {
  apiKey: f.string.isRequired,
  onInitialized: f.func.isRequired,
  center: f.object,
  zoom: f.number,
  bounds: f.object,
  heading: f.number,
  tilt: f.number,
  mapsIndoorsInstance: f.object,
  mapOptions: f.object,
  gmMapId: f.string
};
function U({ apiKey: o, onInitialized: e, center: t, zoom: r, bounds: s, heading: i, tilt: n, mapsIndoorsInstance: c, mapOptions: l, gmMapId: p }) {
  const [a, u] = j(), [h, g] = j(), [m, b] = j(!1), M = _();
  return C(() => {
    h && (d(s) || c.getMapView().fitBounds(s, l == null ? void 0 : l.fitBoundsPadding), !d(t) && d(s) && h.getMap().setCenter(t), !d(r) && d(s) && h.getMap().setZoom(r), d(i) || h.getMap().setHeading(i), d(n) || h.getMap().setTilt(n));
  }, [h, t, r, i, n, s, l]), C(() => {
    c && h && a && !m && M && (h.getMap().setOptions({
      zoomControl: !0,
      zoomControlOptions: {
        style: a.maps.ZoomControlStyle.DEFAULT,
        position: a.maps.ControlPosition.RIGHT_BOTTOM
      }
    }), b(!0));
  }, [c, h, a]), C(() => {
    new w({
      apiKey: o,
      version: "quarterly",
      libraries: ["geometry", "places"]
    }).load().then((S) => {
      u(S);
      const y = {
        element: document.getElementById("map"),
        disableDefaultUI: !0,
        // Disable Map Type control, Street view control and Zoom controls.
        center: t ?? { lat: 0, lng: 0 },
        // The MapsIndoors SDK needs a starting point and a zoom level to avoid timing issues when setting a venue.
        zoom: r ?? 21,
        heading: i ?? 0,
        tilt: n ?? 0,
        mapId: p,
        ...l
      };
      d(l == null ? void 0 : l.showMapMarkers) || (y.showMapMarkers = l.showMapMarkers);
      const v = new window.mapsindoors.mapView.GoogleMapsView(y);
      g(v), e(v);
    });
  }, []), /* @__PURE__ */ A.jsx("div", { className: "mapsindoors-map google-maps-map-container", id: "map" });
}
export {
  U as default
};
//# sourceMappingURL=GoogleMapsMap-35a3940b.mjs.map
