import { P as p, i as g, j as _ } from "./reactcomponent-44b70bf6.mjs";
import { useState as A, useEffect as j } from "react";
import "react-dom";
function C(n, e, t, r) {
  function s(i) {
    return i instanceof t ? i : new t(function(o) {
      o(i);
    });
  }
  return new (t || (t = Promise))(function(i, o) {
    function c(a) {
      try {
        u(r.next(a));
      } catch (h) {
        o(h);
      }
    }
    function l(a) {
      try {
        u(r.throw(a));
      } catch (h) {
        o(h);
      }
    }
    function u(a) {
      a.done ? i(a.value) : s(a.value).then(c, l);
    }
    u((r = r.apply(n, e || [])).next());
  });
}
function $(n) {
  return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
var D = function n(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 (!n(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 o = i[s];
      if (!n(e[o], t[o]))
        return !1;
    }
    return !0;
  }
  return e !== e && t !== t;
}, U = /* @__PURE__ */ $(D);
const k = "__googleMapsScriptId";
var y;
(function(n) {
  n[n.INITIALIZED = 0] = "INITIALIZED", n[n.LOADING = 1] = "LOADING", n[n.SUCCESS = 2] = "SUCCESS", n[n.FAILURE = 3] = "FAILURE";
})(y || (y = {}));
class m {
  /**
   * 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 = k, language: o, libraries: c = [], mapIds: l, nonce: u, region: a, retries: h = 3, url: w = "https://maps.googleapis.com/maps/api/js", version: f }) {
    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 || k, this.language = o, this.libraries = c, this.mapIds = l, this.nonce = u, this.region = a, this.retries = h, this.url = w, this.version = f, m.instance) {
      if (!U(this.options, m.instance.options))
        throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(m.instance.options)}`);
      return m.instance;
    }
    m.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 ? y.FAILURE : this.done ? y.SUCCESS : this.loading ? y.LOADING : y.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 o, c, l, u = "The Google Maps JavaScript API", a = "google", h = "importLibrary", w = "__ib__", f = document, d = window;
      d = d[a] || (d[a] = {});
      const b = d.maps || (d.maps = {}), S = /* @__PURE__ */ new Set(), I = new URLSearchParams(), P = () => (
        // @ts-ignore
        o || (o = new Promise((v, E) => C(this, void 0, void 0, function* () {
          var M;
          yield c = f.createElement("script"), c.id = this.id, I.set("libraries", [...S] + "");
          for (l in i)
            I.set(l.replace(/[A-Z]/g, (R) => "_" + R[0].toLowerCase()), i[l]);
          I.set("callback", a + ".maps." + w), c.src = this.url + "?" + I, b[w] = v, c.onerror = () => o = E(Error(u + " could not load.")), c.nonce = this.nonce || ((M = f.querySelector("script[nonce]")) === null || M === void 0 ? void 0 : M.nonce) || "", f.head.append(c);
        })))
      );
      b[h] ? console.warn(u + " only loads once. Ignoring:", i) : b[h] = (v, ...E) => S.add(v) && P().then(() => b[h](v, ...E));
    })(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 o = new ErrorEvent("error", { error: i });
      this.loadErrorCallback(o);
    });
  }
  /**
   * 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();
      }
  }
}
N.propTypes = {
  apiKey: p.string.isRequired,
  onInitialized: p.func.isRequired,
  center: p.object,
  zoom: p.number,
  bounds: p.object,
  heading: p.number,
  tilt: p.number,
  mapsIndoorsInstance: p.object,
  mapOptions: p.object,
  gmMapId: p.string
};
function N({ apiKey: n, onInitialized: e, center: t, zoom: r, bounds: s, heading: i, tilt: o, mapsIndoorsInstance: c, mapOptions: l, gmMapId: u }) {
  const [a, h] = A();
  return j(() => {
    a && (g(s) || c.getMapView().fitBounds(s, l == null ? void 0 : l.fitBoundsPadding), !g(t) && g(s) && a.getMap().setCenter(t), !g(r) && g(s) && a.getMap().setZoom(r), g(i) || a.getMap().setHeading(i), g(o) || a.getMap().setTilt(o));
  }, [a, t, r, i, o, s, l]), j(() => {
    new m({
      apiKey: n,
      version: "quarterly",
      libraries: ["geometry", "places"]
    }).load().then(() => {
      const f = {
        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: o ?? 0,
        mapId: u,
        gestureHandling: "greedy",
        ...l
      };
      g(l == null ? void 0 : l.showMapMarkers) || (f.showMapMarkers = l.showMapMarkers);
      const d = new window.mapsindoors.mapView.GoogleMapsView(f);
      h(d), e(d);
    });
  }, []), /* @__PURE__ */ _.jsx("div", { className: "mapsindoors-map google-maps-map-container", id: "map" });
}
export {
  N as default
};
//# sourceMappingURL=GoogleMapsMap-c70be16b.mjs.map
