import { css as M, LitElement as O, svg as R, html as g, unsafeCSS as ce, nothing as J } from "lit";
import { customElement as C, property as p, state as w, query as We } from "lit/decorators.js";
import { convert as Ve } from "geo-coordinates-parser";
import { classMap as A } from "lit/directives/class-map.js";
import { repeat as qe } from "lit/directives/repeat.js";
import Ne from "@turf/clone";
import { styleMap as Ze } from "lit/directives/style-map.js";
import X from "@turf/bbox";
import { featureCollection as q, polygon as Qe, feature as Ke } from "@turf/helpers";
import $e from "@turf/union";
import { Evented as He, Control as Ye, DomEvent as be, Popup as Je, GeoJSON as Xe, DivIcon as et, Marker as tt } from "leaflet";
import it from "@turf/difference";
import st from "@turf/flatten";
var ot = Object.getOwnPropertyDescriptor, rt = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? ot(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let ee = class extends O {
  render() {
    return R`
      <svg viewBox="0 0 14 14" width="13" height="13">
        <path
          d="M13.12.706a.982.982 0 0 0-1.391 0L6.907 5.517 2.087.696a.982.982 0 1 0-1.391 1.39l4.821 4.821L.696 11.73a.982.982 0 1 0 1.39 1.39l4.821-4.821 4.822 4.821a.982.982 0 1 0 1.39-1.39L8.298 6.908l4.821-4.822a.988.988 0 0 0 0-1.38Z"
        />
      </svg>
    `;
  }
};
ee.styles = M`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
ee = rt([
  C("maptiler-geocode-clear-icon")
], ee);
var at = Object.getOwnPropertyDescriptor, nt = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? at(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let te = class extends O {
  render() {
    return R`
      <svg viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M15 0C6.705 0 0 6.705 0 15C0 23.295 6.705 30 15 30C23.295 30 30 23.295 30 15C30 6.705 23.295 0 15 0ZM22.5 20.385L20.385 22.5L15 17.115L9.615 22.5L7.5 20.385L12.885 15L7.5 9.615L9.615 7.5L15 12.885L20.385 7.5L22.5 9.615L17.115 15L22.5 20.385Z"
        />
      </svg>
    `;
  }
};
te.styles = M`
    svg {
      display: block;
      fill: #e15042;
    }
  `;
te = nt([
  C("maptiler-geocode-fail-icon")
], te);
var lt = Object.getOwnPropertyDescriptor, ct = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? lt(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let ie = class extends O {
  render() {
    return g`
      <div>
        <svg viewBox="0 0 18 18" width="24" height="24" class="loading-icon">
          <path fill="#333" d="M4.4 4.4l.8.8c2.1-2.1 5.5-2.1 7.6 0l.8-.8c-2.5-2.5-6.7-2.5-9.2 0z" />
          <path opacity=".1" d="M12.8 12.9c-2.1 2.1-5.5 2.1-7.6 0-2.1-2.1-2.1-5.5 0-7.7l-.8-.8c-2.5 2.5-2.5 6.7 0 9.2s6.6 2.5 9.2 0 2.5-6.6 0-9.2l-.8.8c2.2 2.1 2.2 5.6 0 7.7z" />
        </svg>
      </div>
    `;
  }
};
ie.styles = M`
    div {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      pointer-events: none;

      display: flex;
      align-items: center;
    }

    .loading-icon {
      animation: rotate 0.8s infinite cubic-bezier(0.45, 0.05, 0.55, 0.95);
    }

    @keyframes rotate {
      from {
        -webkit-transform: rotate(0);
        transform: rotate(0);
      }
      to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
  `;
ie = ct([
  C("maptiler-geocode-loading-icon")
], ie);
var ht = Object.getOwnPropertyDescriptor, pt = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? ht(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let se = class extends O {
  render() {
    return R`
      <svg viewBox="0 0 60.006 21.412" width="14" height="20">
        <path
          d="M30.003-26.765C13.46-26.765 0-14.158 0 1.337c0 23.286 24.535 42.952 28.39 46.04.24.192.402.316.471.376.323.282.732.424 1.142.424.41 0 .82-.142 1.142-.424.068-.06.231-.183.471-.376 3.856-3.09 28.39-22.754 28.39-46.04 0-15.495-13.46-28.102-30.003-28.102Zm1.757 12.469c4.38 0 7.858 1.052 10.431 3.158 2.595 2.105 3.89 4.913 3.89 8.422 0 2.34-.53 4.362-1.593 6.063-1.063 1.702-3.086 3.616-6.063 5.742-2.042 1.51-3.337 2.659-3.89 3.446-.532.787-.8 1.82-.8 3.096v1.914h-8.449V15.18c0-2.041.434-3.815 1.306-5.325.872-1.51 2.467-3.118 4.785-4.82 2.233-1.594 3.7-2.89 4.402-3.889a5.582 5.582 0 0 0 1.087-3.35c0-1.382-.51-2.435-1.531-3.158-1.02-.723-2.45-1.087-4.28-1.087-3.19 0-6.826 1.047-10.91 3.131l-3.472-6.986c4.742-2.659 9.77-3.992 15.087-3.992Zm-1.88 37.324c1.765 0 3.124.472 4.08 1.408.98.936 1.47 2.276 1.47 4.02 0 1.68-.49 3.007-1.47 3.985-.977.957-2.336 1.435-4.08 1.435-1.787 0-3.171-.465-4.15-1.4-.978-.958-1.47-2.298-1.47-4.02 0-1.787.48-3.14 1.436-4.054.957-.915 2.355-1.374 4.184-1.374Z"
        />
      </svg>
    `;
  }
};
se.styles = M`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
se = pt([
  C("maptiler-geocode-reverse-geocoding-icon")
], se);
var dt = Object.getOwnPropertyDescriptor, ut = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? dt(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let oe = class extends O {
  render() {
    return R`
      <svg
        xmlns="http://www.w3.org/2000/svg"
        width="13"
        height="13"
        viewBox="0 0 13 13"
      >
        <circle cx="4.789" cy="4.787" r="3.85" />
        <path d="M12.063 12.063 7.635 7.635" />
      </svg>
    `;
  }
};
oe.styles = M`
    circle {
      stroke-width: 1.875;
      fill: none;
    }

    path {
      stroke-width: 1.875;
      stroke-linecap: round;
    }

    svg {
      display: block;
      stroke: var(--color-icon-button);
    }
  `;
oe = ut([
  C("maptiler-geocode-search-icon")
], oe);
function ft(t, e, i) {
  const r = e[1], s = e[0], a = r - s;
  return t === r && i ? t : ((t - s) % a + a) % a + s;
}
function U(t) {
  const e = [...t];
  return e[2] < e[0] && (Math.abs((e[0] + e[2] + 360) / 2) > Math.abs((e[0] - 360 + e[2]) / 2) ? e[0] -= 360 : e[2] += 360), e;
}
function we(t, e) {
  const i = Ne(t);
  for (const r of i.features)
    if (r.geometry.type == "MultiPolygon")
      for (const s of r.geometry.coordinates)
        ke(s, e);
    else
      ke(r.geometry.coordinates, e);
  return i;
}
function ke(t, e) {
  for (const i of t)
    for (const r of i)
      r[0] += e;
}
let B;
async function mt(t, e, i) {
  for (const r of e ?? [])
    if (!(t && (r.minZoom != null && r.minZoom > t[0] || r.maxZoom != null && r.maxZoom < t[0]))) {
      if (r.type === "fixed")
        return r.coordinates.join(",");
      if (r.type === "client-geolocation")
        if (B && r.cachedLocationExpiry && B.time + r.cachedLocationExpiry > Date.now()) {
          if (B.coords)
            return B.coords;
        } else {
          let s;
          try {
            return s = await new Promise((a, o) => {
              i.signal.addEventListener("abort", () => {
                o(Error("aborted"));
              }), navigator.geolocation.getCurrentPosition(
                (u) => {
                  a([u.coords.longitude, u.coords.latitude].map((m) => m.toFixed(6)).join(","));
                },
                (u) => {
                  o(u);
                },
                r
              );
            }), s;
          } catch {
          } finally {
            r.cachedLocationExpiry && (B = {
              time: Date.now(),
              coords: s
            });
          }
          if (i.signal.aborted)
            return;
        }
      if (r.type === "server-geolocation")
        return "ip";
      if (t && r.type === "map-center")
        return t[1].toFixed(6) + "," + t[2].toFixed(6);
    }
}
const gt = ".sprite-icon{align-self:center;justify-self:center;opacity:.75;background-repeat:no-repeat}li{text-align:left;cursor:default;display:grid;grid-template-columns:40px 1fr;color:var(--color-text);padding:8px 0;font-size:14px;line-height:18px;min-width:fit-content;outline:0}li:first-child{padding-top:10px}li:last-child{padding-bottom:10px}li.picked{background-color:#e7edff}li.picked .secondary{color:#96a4c7;padding-left:4px}li.picked .line2{color:#96a4c7}li.selected{background-color:#f3f6ff;animation:backAndForth 5s linear infinite}li.selected .primary{color:#2b8bfb}li.selected .secondary{color:#a2adc7;padding-left:4px}li.selected .line2{color:#a2adc7}li>img{align-self:center;justify-self:center;opacity:.75}.texts{padding:0 17px 0 0}.texts>*{white-space:nowrap;display:block;min-width:fit-content}.primary{font-weight:600}.secondary{color:#aeb6c7;padding-left:4px}.line2{color:#aeb6c7}@keyframes backAndForth{0%{transform:translate(0)}10%{transform:translate(0)}45%{transform:translate(calc(-100% + 270px))}55%{transform:translate(calc(-100% + 270px))}90%{transform:translate(0)}to{transform:translate(0)}}";
var yt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, Le = (t) => {
  throw TypeError(t);
}, L = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? vt(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = (r ? o(e, i, s) : o(s)) || s);
  return r && s && yt(e, i, s), s;
}, Ie = (t, e, i) => e.has(t) || Le("Cannot " + i), f = (t, e, i) => (Ie(t, e, "read from private field"), i ? i.call(t) : e.get(t)), xt = (t, e, i) => e.has(t) ? Le("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), E = (t, e, i) => (Ie(t, e, "access private method"), i), d, N, G, y, Me, Oe, he, re;
const Ce = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Te = Ce ? "@2x" : "", F = Ce ? 2 : 1;
let T, Fe, k = class extends O {
  constructor() {
    super(...arguments), xt(this, d), this.itemStyle = "default", this.showPlaceType = "if-needed", this.missingIconsCache = /* @__PURE__ */ new Set(), this.iconsBaseUrl = "", this.index = 0;
  }
  willUpdate(t) {
    t.has("feature") && f(this, d, N) && (this.index = f(this, d, N).length, E(this, d, he).call(this));
  }
  render() {
    return g`
      <li
        tabindex="-1"
        role="option"
        aria-selected=${this.itemStyle === "selected"}
        aria-checked=${this.itemStyle === "picked"}
        class=${this.itemStyle}
        @click=${() => this.dispatchEvent(new CustomEvent("select"))}
      >
        ${T && this.spriteIcon ? g`
              <div
                class="sprite-icon"
                style=${Ze({
      width: `${this.spriteIcon.width / F}px`,
      height: `${this.spriteIcon.height / F}px`,
      backgroundImage: `url(${this.iconsBaseUrl}sprite${Te}.png)`,
      backgroundPosition: `-${this.spriteIcon.x / F}px -${this.spriteIcon.y / F}px`,
      backgroundSize: `${T.width / F}px ${T.height / F}px`
    })}
                title=${f(this, d, y)}
              />
            ` : this.imageUrl ? g` <img src=${this.imageUrl} alt=${this.category} title=${f(this, d, y)} @error=${E(this, d, Oe)} />` : this.feature?.address ? g` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("road.") ? g` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("address.") ? g` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("postal_code.") ? g` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("poi.") ? g` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : f(this, d, G) ? g` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : g` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> `}

        <span class="texts">
          <span>
            <span class="primary"> ${f(this, d, G) ? this.feature?.place_name : this.feature?.place_name.replace(/,.*/, "")} </span>

            ${this.showPlaceType === "always" || this.showPlaceType !== "never" && !this.feature?.address && !this.feature?.id.startsWith("road.") && !this.feature?.id.startsWith("address.") && !this.feature?.id.startsWith("postal_code.") && (!this.feature?.id.startsWith("poi.") || !this.imageUrl) && !f(this, d, G) ? g` <span class="secondary"> ${f(this, d, y)} </span> ` : J}
          </span>

          <span class="line2"> ${f(this, d, G) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span>
        </span>
      </li>
    `;
  }
};
d = /* @__PURE__ */ new WeakSet();
N = function() {
  return this.feature?.properties?.categories;
};
G = function() {
  return this.feature?.place_type[0] === "reverse";
};
y = function() {
  return this.feature?.properties?.categories?.join(", ") ?? this.feature?.place_type_name?.[0] ?? this.feature?.place_type[0];
};
Me = function() {
  Fe ??= fetch(`${this.iconsBaseUrl}sprite${Te}.json`).then((t) => t.json()).then((t) => {
    T = t;
  }).catch(() => {
    T = null;
  });
};
Oe = function() {
  this.imageUrl && this.missingIconsCache.add(this.imageUrl), E(this, d, he).call(this);
};
he = function() {
  T !== void 0 ? E(this, d, re).call(this) : (E(this, d, Me).call(this), Fe?.then(() => {
    E(this, d, re).call(this);
  }));
};
re = function() {
  do {
    if (this.index--, this.category = f(this, d, N)?.[this.index], this.spriteIcon = this.category ? T?.icons[this.category] : void 0, this.spriteIcon)
      break;
    this.imageUrl = this.category ? this.iconsBaseUrl + this.category.replace(/ /g, "_") + ".svg" : void 0;
  } while (this.index > -1 && (!this.imageUrl || this.missingIconsCache.has(this.imageUrl)));
};
k.styles = M`
    ${ce(gt)}
  `;
L([
  p({ type: Object })
], k.prototype, "feature", 2);
L([
  p({ type: String })
], k.prototype, "itemStyle", 2);
L([
  p({ type: String })
], k.prototype, "showPlaceType", 2);
L([
  p({ attribute: !1 })
], k.prototype, "missingIconsCache", 2);
L([
  p({ type: String })
], k.prototype, "iconsBaseUrl", 2);
L([
  w()
], k.prototype, "category", 2);
L([
  w()
], k.prototype, "imageUrl", 2);
L([
  w()
], k.prototype, "spriteIcon", 2);
L([
  w()
], k.prototype, "index", 2);
k = L([
  C("maptiler-geocoder-feature-item")
], k);
const bt = "form{font-family:Open Sans,Ubuntu,Helvetica Neue,Arial,Helvetica,sans-serif;position:relative;background-color:#fff;z-index:10;border-radius:4px;margin:0;transition:max-width .25s;box-shadow:0 2px 5px #33335926;--color-text: #444952;--color-icon-button: #444952;pointer-events:all}form,form *,form *:after,form *:before{box-sizing:border-box}form.can-collapse{max-width:29px}form.can-collapse input::placeholder{transition:opacity .25s;opacity:0}form{width:270px;max-width:270px}form:focus-within,form:hover{width:270px;max-width:270px}form input::placeholder,form:focus-within input::placeholder,form:hover input::placeholder{opacity:1}input{font:inherit;font-size:14px;flex-grow:1;min-height:29px;background-color:transparent;color:#444952;white-space:nowrap;overflow:hidden;border:0;margin:0;padding:0}input:focus{color:#444952;outline:0;outline:none;box-shadow:none}ul,div.error,div.no-results{background-color:#fff;border-radius:4px;left:0;list-style:none;margin:0;padding:0;position:absolute;width:100%;top:calc(100% + 6px);overflow:hidden}ul{font-size:14px;line-height:16px;box-shadow:0 5px 10px #33335926}div.error,div.no-results{font:inherit;line-height:18px;font-size:12px;display:flex;gap:16px}div.error{padding:16px;font-weight:600;color:#e25041;background-color:#fbeae8}div.error div{flex-grow:1}div.error maptiler-geocode-fail-icon{flex-shrink:0;width:20px;height:20px}div.error button{flex-shrink:0}div.error button maptiler-geocode-clear-icon{--color-icon-button: #e25041}div.error button:hover maptiler-geocode-clear-icon,div.error button:active maptiler-geocode-clear-icon{--color-icon-button: inherit}div.no-results{padding:14px 24px 14px 16px;font-weight:400;color:#6b7c93;box-shadow:0 5px 10px #33335926}div.no-results maptiler-geocode-fail-icon{margin-top:4px;flex-shrink:0;width:20px;height:20px}ul.options.open-on-top{top:auto;bottom:calc(100% + 6px)}button{padding:0;margin:0;border:0;background-color:transparent;height:auto;width:auto}button:hover{background-color:transparent}button:hover,button:active{--color-icon-button: #2b8bfb}.input-group{display:flex;align-items:stretch;gap:7px;padding-inline:8px;border-radius:4px;overflow:hidden}.input-group:focus-within{outline:#2b8bfb solid 2px}.search-button{flex-shrink:0}.clear-button-container{display:flex;display:none;position:relative;align-items:stretch}.clear-button-container.displayable{display:flex;flex-shrink:0}:host(.maptiler-geocoder):not(:empty){box-shadow:none}:host(.maptiler-geocoder) .input-group{border:white solid 2px}:host(.maptiler-geocoder) .input-group:focus-within{border:#2b8bfb solid 2px;outline:0;outline:none}:host(.maptiler-geocoder) form.can-collapse{max-width:33px}:host(.maptiler-geocoder) form,:host(.maptiler-geocoder) form:focus-within,:host(.maptiler-geocoder) form:hover{width:270px;max-width:270px}:host(.leaflet-geocoder) .input-group{border:white solid 1px}:host(.leaflet-geocoder) form.can-collapse{max-width:30px}";
var wt = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Se = (t) => {
  throw TypeError(t);
}, c = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? kt(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = (r ? o(e, i, s) : o(s)) || s);
  return r && s && wt(e, i, s), s;
}, pe = (t, e, i) => e.has(t) || Se("Cannot " + i), b = (t, e, i) => (pe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), S = (t, e, i) => e.has(t) ? Se("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), W = (t, e, i, r) => (pe(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (pe(t, e, "access private method"), i), Z, V, z, ae, D, n, Q, Ee, Pe, de, x, ue, K, fe, me, I, ge, H, Be, ne, Ge, Ue, ze, De, Re;
let l = class extends O {
  constructor() {
    super(...arguments), S(this, n), this.clearListOnPick = !1, this.clearOnBlur = !1, this.collapsed = !1, this.excludeTypes = !1, this.exhaustiveReverseGeocoding = !1, this.fetchFullGeometryOnPick = !1, this.keepListOpen = !1, this.openListOnTop = !1, this.reverseActive = !1, this.searchValue = "", this.selectedItemIndex = -1, this.cachedFeatures = [], this.lastSearchUrl = "", this.focused = !1, this.focusedDelayed = !1, S(this, Z, !1), S(this, V, !1), S(this, z), S(this, ae, /* @__PURE__ */ new Set()), S(this, D);
  }
  firstUpdated() {
    W(this, Z, !0);
  }
  /**
   * Set the options of this instance.
   *
   * @param options options to set
   */
  setOptions(t) {
    const e = { ...t };
    for (const i of Object.keys(e))
      _t.includes(i) || delete e[i];
    Object.assign(this, e);
  }
  /**
   * Set the content of search input box.
   *
   * @param value text to set
   */
  setQuery(t) {
    h(this, n, me).call(this, t, { external: !0 }), h(this, n, fe).call(this);
  }
  /**
   * Set the content of search input box and immediately submit it.
   *
   * @param value text to set and submit
   */
  submitQuery(t) {
    h(this, n, ge).call(this, t);
  }
  /**
   * Clear search result list.
   */
  clearList() {
    h(this, n, I).call(this), this.picked = void 0, this.selectedItemIndex = -1;
  }
  /**
   * Focus the search input box.
   *
   * @param options [FocusOptions](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#options)
   */
  focus(t) {
    this.input.focus(t);
  }
  /**
   * Blur the search input box.
   */
  blur() {
    this.input.blur();
  }
  addEventListener(t, e, i) {
    super.addEventListener(t, e, i);
  }
  removeEventListener(t, e, i) {
    super.removeEventListener(t, e, i);
  }
  /** @internal */
  handleMapChange(t) {
    W(this, D, t);
  }
  /** @internal */
  handleMapClick(t) {
    this.reverseActive && h(this, n, Be).call(this, t);
  }
  willUpdate(t) {
    t.has("error") && this.error && console.error("[MapTilerGeocodingControl] Error:", this.error), t.has("enableReverse") && (this.reverseActive = this.enableReverse === "always"), ["picked"].some((e) => t.has(e)) && this.picked && (this.clearListOnPick && h(this, n, I).call(this), this.selectedItemIndex = -1), ["searchValue", "minLength"].some((e) => t.has(e)) && b(this, n, de) && (h(this, n, I).call(this), this.error = void 0), ["focused"].some((e) => t.has(e)) && setTimeout(() => {
      this.focusedDelayed = this.focused, this.clearOnBlur && !this.focused && (this.searchValue = "");
    }, 100), ["selectFirst", "listFeatures", "selectedItemIndex", "picked"].some((e) => t.has(e)) && this.selectFirst !== !1 && this.listFeatures?.length && this.selectedItemIndex == -1 && !this.picked && (this.selectedItemIndex = 0), ["listFeatures", "selectedItemIndex"].some((e) => t.has(e)) && h(this, n, x).call(this, "select", { feature: b(this, n, Q) }), ["picked"].some((e) => t.has(e)) && this.picked && this.picked.id !== t.get("picked")?.id && (this.fetchFullGeometryOnPick && !this.picked.address && this.picked.geometry.type === "Point" && this.picked.place_type[0] !== "reverse" ? h(this, n, H).call(this, this.picked.id, { byId: !0 }) : Promise.resolve()).then(
      () => {
        h(this, n, x).call(this, "pick", { feature: this.picked });
      },
      (e) => {
        e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, n, x).call(this, "pick", { feature: this.picked }));
      }
    ), ["listFeatures", "focusedDelayed"].some((e) => t.has(e)) && (b(this, n, Ee) ? (h(this, n, x).call(this, "featuresshow"), W(this, V, !0)) : b(this, V) && h(this, n, x).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, n, x).call(this, "reversetoggle", { reverse: this.reverseActive });
  }
  render() {
    return g`
      <form @submit=${h(this, n, ue)} class=${A({ "can-collapse": this.collapsed && this.searchValue === "" })}>
        <div class="input-group">
          <button
            class="search-button"
            type="button"
            @click=${() => {
      this.input.focus();
    }}
          >
            <maptiler-geocode-search-icon></maptiler-geocode-search-icon>
          </button>

          <input
            .value=${this.searchValue}
            @focus=${() => this.focused = !0}
            @blur=${() => this.focused = !1}
            @click=${() => this.focused = !0}
            @keydown=${h(this, n, ne)}
            @input=${h(this, n, Ge)}
            @change=${() => this.picked = void 0}
            placeholder=${this.placeholder ?? "Search"}
            aria-label=${this.placeholder ?? "Search"}
          />

          <div class="clear-button-container ${A({ displayable: this.searchValue !== "" })}">
            ${b(this, n, Pe) ? g`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : g`
                  <button type="button" @click=${h(this, n, Re)} title=${this.clearButtonTitle ?? "clear"}>
                    <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon>
                  </button>
                `}
          </div>

          ${this.enableReverse === "button" ? g`
                <button
                  type="button"
                  class=${A({ active: this.reverseActive })}
                  title=${this.reverseButtonTitle ?? "toggle reverse geocoding"}
                  @click=${() => this.reverseActive = !this.reverseActive}
                >
                  <maptiler-geocode-reverse-geocoding-icon></maptiler-geocode-reverse-geocoding-icon>
                </button>
              ` : J}

          <!-- <slot /> -->
        </div>

        ${this.error ? g`
              <div class="error">
                <maptiler-geocode-fail-icon></maptiler-geocode-fail-icon>

                <div>${this.errorMessage ?? "Something went wrong…"}</div>

                <button @click=${() => this.error = void 0}>
                  <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon>
                </button>
              </div>
            ` : !this.focusedDelayed && !this.keepListOpen || this.listFeatures === void 0 ? J : this.listFeatures.length === 0 ? g`
                  <div class="no-results">
                    <maptiler-geocode-fail-icon></maptiler-geocode-fail-icon>

                    <div>
                      ${this.noResultsMessage ?? "Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!"}
                    </div>
                  </div>
                ` : g`
                  <ul class="options ${A({ "open-on-top": this.openListOnTop })}" @mouseleave=${h(this, n, De)} @keydown=${h(this, n, ne)} role="listbox">
                    ${qe(
      this.listFeatures,
      (t) => t.id + (t.address ? "," + t.address : ""),
      (t, e) => g`
                        <maptiler-geocoder-feature-item
                          .feature=${t}
                          .showPlaceType=${this.showPlaceType ?? "if-needed"}
                          itemStyle=${this.selectedItemIndex === e ? "selected" : this.picked?.id === t.id ? "picked" : "default"}
                          @mouseenter=${() => {
        h(this, n, ze).call(this, e);
      }}
                          @select=${() => {
        h(this, n, Ue).call(this, t);
      }}
                          .missingIconsCache=${b(this, ae)}
                          .iconsBaseUrl=${this.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0-rc.6/icons/"}
                        >
                          ${t.place_name}
                        </maptiler-geocoder-feature-item>
                      `
    )}
                  </ul>
                `}
      </form>
    `;
  }
};
Z = /* @__PURE__ */ new WeakMap();
V = /* @__PURE__ */ new WeakMap();
z = /* @__PURE__ */ new WeakMap();
ae = /* @__PURE__ */ new WeakMap();
D = /* @__PURE__ */ new WeakMap();
n = /* @__PURE__ */ new WeakSet();
Q = function() {
  return this.listFeatures?.[this.selectedItemIndex];
};
Ee = function() {
  return !!this.listFeatures?.length && (this.focusedDelayed || this.keepListOpen);
};
Pe = function() {
  return this.abortController !== void 0;
};
de = function() {
  return this.searchValue.length < (this.minLength ?? 2);
};
x = function(t, ...[e]) {
  b(this, Z) && this.dispatchEvent(
    new CustomEvent(t, {
      bubbles: !0,
      composed: !0,
      detail: e
    })
  );
};
ue = function(t) {
  t?.preventDefault(), this.focused = !1, clearTimeout(b(this, z)), this.selectedItemIndex > -1 && this.listFeatures ? (this.picked = this.listFeatures[this.selectedItemIndex], this.searchValue = this.picked.place_type[0] === "reverse" ? this.picked.place_name : this.picked.place_name.replace(/,.*/, ""), this.error = void 0, this.selectedItemIndex = -1) : this.searchValue && h(this, n, H).call(this, this.searchValue, { exact: !0, external: t === void 0 }).then(() => {
    this.picked = void 0;
  }).catch((e) => this.error = e);
};
K = function(t) {
  try {
    return Ve(t, 6);
  } catch {
    return !1;
  }
};
fe = function() {
  setTimeout(() => {
    this.input.focus(), this.focused = !0, this.input.select();
  });
};
me = function(t, { external: e = !1 } = {}) {
  if (this.searchValue = t, h(this, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, K).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) {
    if (clearTimeout(b(this, z)), b(this, n, de))
      return;
    const i = this.searchValue;
    W(this, z, window.setTimeout(() => {
      h(this, n, H).call(this, i, { external: e }).catch((r) => this.error = r);
    }, this.debounceSearch ?? 200));
  } else
    h(this, n, I).call(this);
};
I = function() {
  this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, n, x).call(this, "featuresclear"));
};
ge = function(t) {
  this.searchValue = t, h(this, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, K).call(this, t) }), this.selectedItemIndex = -1, h(this, n, ue).call(this);
};
H = async function(t, { byId: e = !1, exact: i = !1, external: r = !1 } = {}) {
  this.error = void 0, this.abortController?.abort();
  const s = new AbortController();
  this.abortController = s;
  try {
    const a = this.apiUrl ?? "https://api.maptiler.com/geocoding", o = h(this, n, K).call(this, t), u = new URL(a + "/" + encodeURIComponent(o ? `${o.decimalLongitude},${o.decimalLatitude}` : t) + ".json"), m = u.searchParams;
    this.language !== void 0 && m.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? "");
    const [_] = b(this, D) ?? [void 0];
    let $ = (!o || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map(
      (v) => typeof v == "string" ? v : _ === void 0 || (v[0] ?? 0) <= _ && _ < (v[1] ?? 1 / 0) ? v[2] : void 0
    ).filter((v) => v !== void 0);
    $ && ($ = [...new Set($)], m.set("types", $.join(",")));
    const ye = !o || this.reverseGeocodingExcludeTypes === void 0 ? this.excludeTypes : this.reverseGeocodingExcludeTypes;
    if (ye && m.set("excludeTypes", String(ye)), this.bbox && m.set("bbox", this.bbox.map((v) => v.toFixed(6)).join(",")), this.country && m.set("country", Array.isArray(this.country) ? this.country.join(",") : this.country), this.worldview && m.set("worldview", this.worldview), !e && !o) {
      const v = this.proximity ?? [{ type: "server-geolocation" }], xe = await mt(b(this, D), v, s);
      xe && m.set("proximity", xe), (i || this.showResultsWhileTyping === !1) && m.set("autocomplete", "false"), m.set("fuzzyMatch", String(this.fuzzyMatch !== !1));
    }
    const ve = this.limit ?? 5, Y = this.reverseGeocodingLimit ?? ve;
    Y > 1 && $?.length !== 1 && console.warn("[MapTilerGeocodingControl] Warning: For reverse geocoding when limit > 1 then types must contain single value."), o ? (Y === 1 || this.exhaustiveReverseGeocoding || $?.length === 1) && m.set("limit", String(Y)) : m.set("limit", String(ve)), this.apiKey && m.set("key", this.apiKey), this.adjustUrl?.(u);
    const Ae = u.searchParams.get("types") === "" && u.searchParams.get("excludeTypes") !== "true", j = u.toString();
    if (j === this.lastSearchUrl) {
      e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = this.cachedFeatures[0]) : (this.listFeatures = this.cachedFeatures, h(this, n, x).call(this, "featureslisted", { features: this.listFeatures, external: r }), this.listFeatures[this.selectedItemIndex]?.id !== b(this, n, Q)?.id && (this.selectedItemIndex = -1));
      return;
    }
    h(this, n, x).call(this, "request", { urlObj: u }), this.lastSearchUrl = j;
    let P;
    if (Ae)
      P = { type: "FeatureCollection", features: [] };
    else {
      const v = await fetch(j, {
        signal: s.signal,
        ...this.fetchParameters
      });
      if (!v.ok)
        throw new Error(await v.text());
      P = await v.json();
    }
    h(this, n, x).call(this, "response", { url: j, featureCollection: P }), e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = P.features[0], this.cachedFeatures = [this.picked]) : (this.listFeatures = P.features.filter(this.filter ?? (() => !0)), o && this.listFeatures.unshift({
      type: "Feature",
      properties: {},
      /* eslint-disable @typescript-eslint/restrict-template-expressions */
      id: `reverse_${o.decimalLongitude}_${o.decimalLatitude}`,
      text: `${o.decimalLatitude}, ${o.decimalLongitude}`,
      place_name: o.toCoordinateFormat("DMS"),
      /* eslint-enable @typescript-eslint/restrict-template-expressions */
      place_type: ["reverse"],
      place_type_name: ["reverse"],
      center: [o.decimalLongitude, o.decimalLatitude],
      bbox: [o.decimalLongitude, o.decimalLatitude, o.decimalLongitude, o.decimalLatitude],
      geometry: {
        type: "Point",
        coordinates: [o.decimalLongitude, o.decimalLatitude]
      }
    }), h(this, n, x).call(this, "featureslisted", { features: this.listFeatures, external: r }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== b(this, n, Q)?.id && (this.selectedItemIndex = -1), o && this.input.focus());
  } catch (a) {
    if (a && typeof a == "object" && "name" in a && a.name === "AbortError")
      return;
    throw a;
  } finally {
    s === this.abortController && (this.abortController = void 0);
  }
};
Be = function(t) {
  this.reverseActive = this.enableReverse === "always", h(this, n, I).call(this), this.picked = void 0, h(this, n, ge).call(this, `${t[1].toFixed(6)}, ${ft(t[0], [-180, 180], !0).toFixed(6)}`), h(this, n, fe).call(this);
};
ne = function(t) {
  if (!this.listFeatures)
    return;
  const e = t.key === "ArrowDown" ? 1 : t.key === "ArrowUp" ? -1 : 0;
  e && (this.input.focus(), this.focused = !0, t.preventDefault(), this.picked && this.selectedItemIndex === -1 && (this.selectedItemIndex = this.listFeatures.findIndex((i) => i.id === this.picked?.id)), this.selectedItemIndex === (this.picked || this.selectFirst !== !1 ? 0 : -1) && e === -1 && (this.selectedItemIndex = this.listFeatures.length), this.selectedItemIndex += e, this.selectedItemIndex >= this.listFeatures.length && (this.selectedItemIndex = -1), this.selectedItemIndex < 0 && (this.picked || this.selectFirst !== !1) && (this.selectedItemIndex = 0));
};
Ge = function(t) {
  h(this, n, me).call(this, t.target.value);
};
Ue = function(t) {
  (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name);
};
ze = function(t) {
  this.selectedItemIndex = t;
};
De = function() {
  (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1);
};
Re = function() {
  this.searchValue = "", h(this, n, x).call(this, "queryclear"), this.picked = void 0, this.input.focus();
};
l.styles = M`
    ${ce(bt)}
  `;
c([
  p({ attribute: !1 })
], l.prototype, "adjustUrl", 2);
c([
  p({ type: String })
], l.prototype, "apiKey", 2);
c([
  p({ type: String })
], l.prototype, "apiUrl", 2);
c([
  p({ type: Array })
], l.prototype, "bbox", 2);
c([
  p({ type: String })
], l.prototype, "clearButtonTitle", 2);
c([
  p({ type: Boolean })
], l.prototype, "clearListOnPick", 2);
c([
  p({ type: Boolean })
], l.prototype, "clearOnBlur", 2);
c([
  p({ type: Boolean })
], l.prototype, "collapsed", 2);
c([
  p({ attribute: !1 })
], l.prototype, "country", 2);
c([
  p({ type: Number })
], l.prototype, "debounceSearch", 2);
c([
  p({ type: String })
], l.prototype, "enableReverse", 2);
c([
  p({ type: String })
], l.prototype, "errorMessage", 2);
c([
  p({ type: Boolean })
], l.prototype, "excludeTypes", 2);
c([
  p({ type: Boolean })
], l.prototype, "exhaustiveReverseGeocoding", 2);
c([
  p({ type: Boolean })
], l.prototype, "fetchFullGeometryOnPick", 2);
c([
  p({ type: Object })
], l.prototype, "fetchParameters", 2);
c([
  p({ attribute: !1 })
], l.prototype, "filter", 2);
c([
  p({ type: Object })
], l.prototype, "fuzzyMatch", 2);
c([
  p({ type: String })
], l.prototype, "iconsBaseUrl", 2);
c([
  p({ type: Boolean })
], l.prototype, "keepListOpen", 2);
c([
  p({ attribute: !1 })
], l.prototype, "language", 2);
c([
  p({ type: Number })
], l.prototype, "limit", 2);
c([
  p({ type: Number })
], l.prototype, "minLength", 2);
c([
  p({ type: String })
], l.prototype, "noResultsMessage", 2);
c([
  p({ type: Boolean })
], l.prototype, "openListOnTop", 2);
c([
  p({ type: String })
], l.prototype, "placeholder", 2);
c([
  p({ type: Array })
], l.prototype, "proximity", 2);
c([
  p({ type: Boolean })
], l.prototype, "reverseActive", 2);
c([
  p({ type: String })
], l.prototype, "reverseButtonTitle", 2);
c([
  p({ type: Object })
], l.prototype, "reverseGeocodingExcludeTypes", 2);
c([
  p({ type: Number })
], l.prototype, "reverseGeocodingLimit", 2);
c([
  p({ type: Array })
], l.prototype, "reverseGeocodingTypes", 2);
c([
  p({ type: Object })
], l.prototype, "selectFirst", 2);
c([
  p({ type: String })
], l.prototype, "showPlaceType", 2);
c([
  p({ type: Object })
], l.prototype, "showResultsWhileTyping", 2);
c([
  p({ type: Array })
], l.prototype, "types", 2);
c([
  p({ type: String })
], l.prototype, "worldview", 2);
c([
  We("input")
], l.prototype, "input", 2);
c([
  w()
], l.prototype, "searchValue", 2);
c([
  w()
], l.prototype, "listFeatures", 2);
c([
  w()
], l.prototype, "selectedItemIndex", 2);
c([
  w()
], l.prototype, "picked", 2);
c([
  w()
], l.prototype, "cachedFeatures", 2);
c([
  w()
], l.prototype, "lastSearchUrl", 2);
c([
  w()
], l.prototype, "error", 2);
c([
  w()
], l.prototype, "abortController", 2);
c([
  w()
], l.prototype, "focused", 2);
c([
  w()
], l.prototype, "focusedDelayed", 2);
l = c([
  C("maptiler-geocoder")
], l);
const _t = [
  "adjustUrl",
  "apiKey",
  "apiUrl",
  "bbox",
  "clearButtonTitle",
  "clearListOnPick",
  "clearOnBlur",
  "collapsed",
  "country",
  "debounceSearch",
  "enableReverse",
  "errorMessage",
  "excludeTypes",
  "reverseGeocodingExcludeTypes",
  "exhaustiveReverseGeocoding",
  "fetchParameters",
  "fetchFullGeometryOnPick",
  "filter",
  "fuzzyMatch",
  "iconsBaseUrl",
  "keepListOpen",
  "language",
  "limit",
  "reverseGeocodingLimit",
  "minLength",
  "noResultsMessage",
  "openListOnTop",
  "placeholder",
  "proximity",
  "reverseActive",
  "reverseButtonTitle",
  "selectFirst",
  "showPlaceType",
  "showResultsWhileTyping",
  "types",
  "reverseGeocodingTypes",
  "worldview"
], $t = "svg{display:block;fill:var(--maptiler-geocode-marker-fill, #3170fe);stroke:var(--maptiler-geocode-marker-stroke, #3170fe);height:30px}:host(.marker-selected){z-index:2}:host(.marker-selected) svg path{fill:var(--maptiler-geocode-marker-selected-fill, #98b7ff);stroke:var(--maptiler-geocode-marker-selected-stroke, #3170fe)}:host(.marker-reverse) svg path{fill:var(--maptiler-geocode-marker-reverse-fill, silver);stroke:var(--maptiler-geocode-marker-reverse-stroke, gray)}:host(.marker-interactive){cursor:pointer!important}:host(.marker-fuzzy) svg path{fill:var(--maptiler-geocode-marker-fuzzy-fill, silver);stroke:var(--maptiler-geocode-marker-fuzzy-stroke, gray)}:host(.marker-fuzzy.marker-selected) svg path{fill:var(--maptiler-geocode-marker-selected-fuzzy-fill, #ddd);stroke:var(--maptiler-geocode-marker-selected-fuzzy-stroke, silver)}";
var Lt = Object.getOwnPropertyDescriptor, It = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? Lt(e, i) : e, a = t.length - 1, o; a >= 0; a--)
    (o = t[a]) && (s = o(s) || s);
  return s;
};
let le = class extends O {
  render() {
    return R`
      <svg
        viewBox="0 0 70 85"
        fill="none"
        class:in-map={displayIn !== "list"}
      >
        <path
          stroke-width="4"
          d="M 5,33.103579 C 5,17.607779 18.457,5 35,5 C 51.543,5 65,17.607779 65,33.103579 C 65,56.388679 40.4668,76.048179 36.6112,79.137779 C 36.3714,79.329879 36.2116,79.457979 36.1427,79.518879 C 35.8203,79.800879 35.4102,79.942779 35,79.942779 C 34.5899,79.942779 34.1797,79.800879 33.8575,79.518879 C 33.7886,79.457979 33.6289,79.330079 33.3893,79.138079 C 29.5346,76.049279 5,56.389379 5,33.103579 Z M 35.0001,49.386379 C 43.1917,49.386379 49.8323,42.646079 49.8323,34.331379 C 49.8323,26.016779 43.1917,19.276479 35.0001,19.276479 C 26.8085,19.276479 20.1679,26.016779 20.1679,34.331379 C 20.1679,42.646079 26.8085,49.386379 35.0001,49.386379 Z"
        />
      </svg>
    `;
  }
};
le.styles = M`
    ${ce($t)}
  `;
le = It([
  C("maptiler-geocode-marker")
], le);
function _e(t) {
  const e = it(
    q([
      Qe([
        [
          [180, 90],
          [-180, 90],
          [-180, -90],
          [180, -90],
          [180, 90]
        ]
      ]),
      t
    ])
  );
  if (!e)
    return;
  e.properties = { isMask: !0 };
  const i = U(X(t)), r = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, a = i[2] > 180, o = st(t);
  if (o.features.length > 1 && (s || a))
    for (const u of o.features) {
      const m = U(X(u));
      if (a && m[0] < -180 + r)
        for (const _ of u.geometry.coordinates)
          for (const $ of _)
            $[0] += 360 - r;
      if (s && m[2] > 180 - r)
        for (const _ of u.geometry.coordinates)
          for (const $ of _)
            $[0] -= 360 - r;
    }
  return q([o.features.length < 2 ? t : $e(o) ?? t, e]);
}
const Mt = {
  continental_marine: 4,
  country: 4,
  major_landform: 8,
  region: 5,
  subregion: 6,
  county: 7,
  joint_municipality: 8,
  joint_submunicipality: 9,
  municipality: 10,
  municipal_district: 11,
  locality: 12,
  neighbourhood: 13,
  place: 14,
  postal_code: 14,
  road: 16,
  poi: 17,
  address: 18,
  "poi.peak": 15,
  "poi.shop": 18,
  "poi.cafe": 18,
  "poi.restaurant": 18,
  "poi.aerodrome": 13
  // TODO add many more
}, Ot = (t) => {
  const e = t?.geometry.type, i = t?.properties?.isMask, r = i ? 0 : e === "LineString" || e === "MultiLineString" ? 3 : 2;
  return {
    color: "#3170fe",
    fillColor: "#000",
    fillOpacity: i ? 0.1 : 0,
    weight: r,
    dashArray: [r, r],
    lineCap: "butt"
  };
};
class je extends Ye {
}
Object.assign(je.prototype, He.prototype);
class At extends je {
  #e;
  #t;
  constructor(e = {}) {
    super(e);
  }
  /** @internal Not to be called directly */
  onAdd(e) {
    this.#e = e, this.#t = e.getContainer().ownerDocument.createElement("maptiler-geocoder"), this.#t.classList.add("leaflet-geocoder"), this.#m(), this.#x(), this.#I();
    const i = e.getContainer().ownerDocument.createElement("div");
    return i.classList.add("leaflet-ctrl-geocoder", "leaflet-bar"), i.style.zIndex = "850", i.appendChild(this.#t), be.disableClickPropagation(i), be.disableScrollPropagation(i), i;
  }
  /** @internal Not to be called directly */
  onRemove() {
    this.#b(), this.#M(), this.#e = void 0, this.#t = void 0;
  }
  getOptions() {
    return { ...this.options };
  }
  setOptions(e) {
    Object.assign(this.options, e), this.#m();
  }
  setQuery(e) {
    this.#t?.setQuery(e);
  }
  submitQuery(e) {
    this.#t?.submitQuery(e);
  }
  clearMap() {
    this.#r = [], this.#c(void 0, void 0);
  }
  clearList() {
    this.#t?.clearList();
  }
  setReverseMode(e) {
    this.setOptions({ reverseActive: e });
  }
  focus(e) {
    this.#t?.focus(e);
  }
  blur() {
    this.#t?.blur();
  }
  /** Markers currently displayed on the map */
  #a = /* @__PURE__ */ new Map();
  /** Marker representing the selected feature */
  #n;
  /** Marker representing the picked feature */
  #o;
  /** Features currently marked on the map */
  #r;
  /** Remember last feature that the map flew to as to not do it again */
  #d;
  /** Layer used for showing geometry results */
  #s;
  #u = {
    reversetoggle: (e) => {
      const i = this.#e?.getContainer();
      i && (i.style.cursor = e.detail.reverse ? "crosshair" : ""), this.#i("reversetoggle", e.detail);
    },
    querychange: (e) => {
      const i = e.detail.reverseCoords;
      this.#v(i ? { lng: i.decimalLongitude, lat: i.decimalLatitude } : void 0), this.#i("querychange", e.detail);
    },
    queryclear: () => {
      this.#v(void 0), this.#i("queryclear");
    },
    request: (e) => {
      this.#i("request", e.detail);
    },
    response: (e) => {
      this.#i("response", e.detail);
    },
    select: (e) => {
      const i = e.detail.feature;
      i && this.#h && this.options.flyToSelected && this.#g({ lng: i.center[0], lat: i.center[1] }, this.#l(i)), this.#r && i && this.#L(i), this.#i("select", e.detail);
    },
    pick: (e) => {
      const i = e.detail.feature;
      i && i.id !== this.#d && this.#h && (this.#w(i), this.#c(this.#r, i)), this.#d = i?.id, this.#i("pick", e.detail);
    },
    featuresshow: () => {
      this.#i("featuresshow");
    },
    featureshide: () => {
      this.#i("featureshide");
    },
    featureslisted: (e) => {
      const i = e.detail.features;
      this.#r = i, this.#c(this.#r, void 0), this.#k(e), this.#i("featureslisted", e.detail);
    },
    featuresclear: () => {
      this.#r = void 0, this.#c(void 0, void 0), this.#i("featuresclear");
    },
    focusin: () => {
      this.#i("focusin");
    },
    focusout: () => {
      this.#i("focusout");
    }
  };
  #f = {
    render: () => {
      const e = this.#e?.getZoom(), i = this.#e?.getCenter();
      this.#t?.handleMapChange(e && i ? [e, i.lng, i.lat] : void 0);
    },
    click: (e) => {
      this.#t?.handleMapClick([e.latlng.lng, e.latlng.lat]);
    }
  };
  #m() {
    this.#t && (this.#t.setOptions(this.options), this.#t.fetchFullGeometryOnPick = this.options.pickedResultStyle !== "marker-only", this.#t.openListOnTop = this.options.position === "bottomleft" || this.options.position === "bottomright");
  }
  #x() {
    if (!(!this.#t || !this.#e)) {
      for (const [e, i] of Object.entries(this.#u))
        this.#t.addEventListener(e, i);
      this.#e.on(this.#f);
    }
  }
  #b() {
    if (!(!this.#t || !this.#e)) {
      for (const [e, i] of Object.entries(this.#u))
        this.#t.removeEventListener(e, i);
      this.#e.off(this.#f);
    }
  }
  #i(e, i) {
    return super.fire(e, i);
  }
  #w(e) {
    e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#g({ lng: e.center[0], lat: e.center[1] }, this.#l(e)) : this.#y(U(e.bbox), 50, this.#l(e));
  }
  #k({ detail: { features: e, external: i } }) {
    if (!e || e.length === 0 || !this.#h || this.options.flyToFeatures === !1 || this.options.flyToFeatures === "never" || !i && (this.options.flyToFeatures === void 0 || this.options.flyToFeatures === "external"))
      return;
    const r = e.every((o) => o.matching_text), s = e.reduce(
      (o, u) => r || !u.matching_text ? [Math.min(o[0], u.bbox[0]), Math.min(o[1], u.bbox[1]), Math.max(o[2], u.bbox[2]), Math.max(o[3], u.bbox[3])] : o,
      [180, 90, -180, -90]
    ), a = e.map((o) => this.#l(o)).filter((o) => o !== void 0).reduce((o, u) => o === void 0 ? u : Math.max(o, u), void 0);
    this.#y(U(s), 50, a);
  }
  #l(e) {
    if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3])
      return;
    const i = e.id.replace(/\..*/, ""), r = this.options.zoom ?? Mt;
    return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, a) => {
      const o = r[i + "." + a];
      return s === void 0 ? o : o === void 0 ? s : Math.max(s, o);
    }, void 0) : void 0) ?? r[i];
  }
  get #h() {
    return !!this.options.flyTo || this.options.flyTo === void 0;
  }
  get #_() {
    return typeof this.options.flyTo == "boolean" ? {} : this.options.flyTo;
  }
  get #$() {
    return typeof this.options.flyTo == "boolean" ? {} : this.options.flyTo;
  }
  #g(e, i) {
    this.#e?.flyTo(e, i, this.#_ ?? void 0);
  }
  #y(e, i, r) {
    this.#e?.fitBounds(
      [
        [e[1], e[0]],
        [e[3], e[2]]
      ],
      { padding: [i, i], ...r ? { maxZoom: r } : {}, ...this.#$ }
    );
  }
  #v(e) {
    if (!(this.options.marker === !1 || this.options.marker === null || !this.#e)) {
      if (!e) {
        this.#o?.remove(), this.#o = void 0;
        return;
      }
      this.#o || (this.options.marker instanceof Function ? this.#o = this.options.marker(this.#e) ?? void 0 : (this.#o = this.#p(e, this.options.marker).addTo(this.#e), this.#o.getElement()?.classList.add("marker-reverse"))), this.#o?.setLatLng(e);
    }
  }
  #c(e, i) {
    if (!this.#e)
      return;
    for (const s of this.#a.values())
      s.remove();
    this.#a = /* @__PURE__ */ new Map(), this.#s?.clearLayers();
    const r = () => {
      if (!i || !this.#e || this.options.marker === !1 || this.options.marker === null) return;
      const s = this.options.marker instanceof Function ? this.options.marker(this.#e, i) : this.#p({ lng: i.center[0], lat: i.center[1] }, this.options.marker).addTo(this.#e);
      s && this.#a.set(i, s);
    };
    if (i?.geometry.type === "GeometryCollection") {
      const s = i.geometry.geometries.filter(
        (a) => a.type === "Polygon" || a.type === "MultiPolygon"
      );
      if (s.length > 0) {
        const a = $e(q(s.map((o) => Ke(o))));
        if (a) {
          const o = _e({ ...i, geometry: a.geometry });
          if (o) {
            const u = [...o.features], m = U(X(i)), _ = m[2] - m[0];
            m[0] - _ / 4 < -180 && u.push(...we(o, -360).features), m[2] + _ / 4 > 180 && u.push(...we(o, 360).features), this.#s?.addData(q(u));
          }
        }
      } else {
        const a = i.geometry.geometries.filter(
          (o) => o.type === "LineString" || o.type === "MultiLineString"
        );
        a.length > 0 && this.#s?.addData({
          ...i,
          geometry: { type: "GeometryCollection", geometries: a }
        });
      }
    } else if (i?.geometry.type.endsWith("Polygon")) {
      const s = _e(i);
      s && this.#s?.addData(s), this.options.pickedResultStyle === "full-geometry-including-polygon-center-marker" && r();
    } else i?.geometry.type.endsWith("LineString") ? this.#s?.addData(i) : i?.geometry.type.endsWith("Point") && r();
    if (this.options.showResultMarkers !== !1 && this.options.showResultMarkers !== null)
      for (const s of e ?? []) {
        if (s.id === i?.id || s.place_type.includes("reverse"))
          continue;
        let a;
        if (this.options.showResultMarkers instanceof Function) {
          if (a = this.options.showResultMarkers(this.#e, s), !a)
            continue;
        } else
          a = this.#p({ lng: s.center[0], lat: s.center[1] }, this.options.showResultMarkers).bindPopup(
            new Je({
              offset: [0.3, -21],
              closeButton: !1,
              closeOnMove: !0,
              className: "maptiler-gc-popup"
            }).setContent(s.place_type[0] === "reverse" ? s.place_name : s.place_name.replace(/,.*/, ""))
          ).addTo(this.#e), a.getElement()?.classList.add("marker-interactive");
        const o = a.getElement();
        o?.addEventListener("click", (u) => {
          u.stopPropagation(), this.#i("markerclick", { feature: s, marker: a });
        }), o?.addEventListener("mouseenter", () => {
          this.#i("markermouseenter", { feature: s, marker: a }), a.togglePopup();
        }), o?.addEventListener("mouseleave", () => {
          this.#i("markermouseleave", { feature: s, marker: a }), a.togglePopup();
        }), o?.classList.toggle("marker-fuzzy", !!s.matching_text), this.#a.set(s, a);
      }
  }
  #L(e) {
    this.#n?.getElement()?.classList.toggle("marker-selected", !1), this.#n = void 0, this.options.markerOnSelected !== !1 && (this.#n = this.#a.get(e), this.#n?.getElement()?.classList.toggle("marker-selected", !0));
  }
  #I() {
    this.#e && (this.#s = new Xe(void 0, {
      style: this.#O(),
      interactive: !1
    }).addTo(this.#e));
  }
  #M() {
    this.#e && (this.#s?.removeFrom(this.#e), this.#s = void 0);
  }
  #p(e, i) {
    return typeof i != "object" && (i = { icon: new et({ html: this.#e?.getContainer().ownerDocument.createElement("maptiler-geocode-marker"), iconAnchor: [12.3, 30], className: "" }) }), new tt(e, i);
  }
  #O() {
    const { fullGeometryStyle: e } = this.options;
    if (e === !0 || e === void 0) return Ot;
    if (!(e === !1 || e === null))
      return e;
  }
}
export {
  Ot as DEFAULT_GEOMETRY_STYLE,
  At as GeocodingControl,
  At as LeafletGeocodingControl,
  ee as MaptilerGeocodeClearIconElement,
  te as MaptilerGeocodeFailIconElement,
  ie as MaptilerGeocodeLoadingIconElement,
  le as MaptilerGeocodeMarkerElement,
  se as MaptilerGeocodeReverseGeocodingIconElement,
  oe as MaptilerGeocodeSearchIconElement,
  l as MaptilerGeocoderElement,
  Mt as ZOOM_DEFAULTS
};
//# sourceMappingURL=leaflet.public.js.map
