import { css as I, LitElement as M, svg as z, html as m, unsafeCSS as ce, nothing as X } from "lit";
import { customElement as O, property as p, state as k, query as We } from "lit/decorators.js";
import { convert as Ve } from "geo-coordinates-parser";
import { classMap as D } from "lit/directives/class-map.js";
import { repeat as qe } from "lit/directives/repeat.js";
import "@turf/clone";
import { styleMap as Ne } from "lit/directives/style-map.js";
import { featureCollection as q, polygon as Ze, feature as Qe } from "@turf/helpers";
import $e from "@turf/union";
import he from "maplibre-gl";
import ke from "@turf/bbox";
import Ke from "@turf/difference";
import Ye from "@turf/flatten";
var He = Object.getOwnPropertyDescriptor, Je = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? He(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let ee = class extends M {
  render() {
    return z`
      <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 = I`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
ee = Je([
  O("maptiler-geocode-clear-icon")
], ee);
var Xe = Object.getOwnPropertyDescriptor, et = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? Xe(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let te = class extends M {
  render() {
    return z`
      <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 = I`
    svg {
      display: block;
      fill: #e15042;
    }
  `;
te = et([
  O("maptiler-geocode-fail-icon")
], te);
var tt = Object.getOwnPropertyDescriptor, it = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? tt(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let ie = class extends M {
  render() {
    return m`
      <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 = I`
    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 = it([
  O("maptiler-geocode-loading-icon")
], ie);
var st = Object.getOwnPropertyDescriptor, rt = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? st(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let se = class extends M {
  render() {
    return z`
      <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 = I`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
se = rt([
  O("maptiler-geocode-reverse-geocoding-icon")
], se);
var ot = Object.getOwnPropertyDescriptor, at = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? ot(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let re = class extends M {
  render() {
    return z`
      <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>
    `;
  }
};
re.styles = I`
    circle {
      stroke-width: 1.875;
      fill: none;
    }

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

    svg {
      display: block;
      stroke: var(--color-icon-button);
    }
  `;
re = at([
  O("maptiler-geocode-search-icon")
], re);
function lt(t, e, i) {
  const a = e[1], s = e[0], o = a - s;
  return t === a && i ? t : ((t - s) % o + o) % o + s;
}
function N(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;
}
let U;
async function nt(t, e, i) {
  for (const a of e ?? [])
    if (!(t && (a.minZoom != null && a.minZoom > t[0] || a.maxZoom != null && a.maxZoom < t[0]))) {
      if (a.type === "fixed")
        return a.coordinates.join(",");
      if (a.type === "client-geolocation")
        if (U && a.cachedLocationExpiry && U.time + a.cachedLocationExpiry > Date.now()) {
          if (U.coords)
            return U.coords;
        } else {
          let s;
          try {
            return s = await new Promise((o, r) => {
              i.signal.addEventListener("abort", () => {
                r(Error("aborted"));
              }), navigator.geolocation.getCurrentPosition(
                (u) => {
                  o([u.coords.longitude, u.coords.latitude].map((y) => y.toFixed(6)).join(","));
                },
                (u) => {
                  r(u);
                },
                a
              );
            }), s;
          } catch {
          } finally {
            a.cachedLocationExpiry && (U = {
              time: Date.now(),
              coords: s
            });
          }
          if (i.signal.aborted)
            return;
        }
      if (a.type === "server-geolocation")
        return "ip";
      if (t && a.type === "map-center")
        return t[1].toFixed(6) + "," + t[2].toFixed(6);
    }
}
const ct = ".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 ht = Object.defineProperty, pt = Object.getOwnPropertyDescriptor, Ie = (t) => {
  throw TypeError(t);
}, L = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? pt(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = (a ? r(e, i, s) : r(s)) || s);
  return a && s && ht(e, i, s), s;
}, Me = (t, e, i) => e.has(t) || Ie("Cannot " + i), f = (t, e, i) => (Me(t, e, "read from private field"), i ? i.call(t) : e.get(t)), dt = (t, e, i) => e.has(t) ? Ie("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), E = (t, e, i) => (Me(t, e, "access private method"), i), d, Z, B, g, Oe, Te, pe, oe;
const Fe = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Se = Fe ? "@2x" : "", S = Fe ? 2 : 1;
let F, Ce, w = class extends M {
  constructor() {
    super(...arguments), dt(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, Z) && (this.index = f(this, d, Z).length, E(this, d, pe).call(this));
  }
  render() {
    return m`
      <li
        tabindex="-1"
        role="option"
        aria-selected=${this.itemStyle === "selected"}
        aria-checked=${this.itemStyle === "picked"}
        class=${this.itemStyle}
        @click=${() => this.dispatchEvent(new CustomEvent("select"))}
      >
        ${F && this.spriteIcon ? m`
              <div
                class="sprite-icon"
                style=${Ne({
      width: `${this.spriteIcon.width / S}px`,
      height: `${this.spriteIcon.height / S}px`,
      backgroundImage: `url(${this.iconsBaseUrl}sprite${Se}.png)`,
      backgroundPosition: `-${this.spriteIcon.x / S}px -${this.spriteIcon.y / S}px`,
      backgroundSize: `${F.width / S}px ${F.height / S}px`
    })}
                title=${f(this, d, g)}
              />
            ` : this.imageUrl ? m` <img src=${this.imageUrl} alt=${this.category} title=${f(this, d, g)} @error=${E(this, d, Te)} />` : this.feature?.address ? m` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("road.") ? m` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("address.") ? m` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("postal_code.") ? m` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("poi.") ? m` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : f(this, d, B) ? m` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : m` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> `}

        <span class="texts">
          <span>
            <span class="primary"> ${f(this, d, B) ? 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, B) ? m` <span class="secondary"> ${f(this, d, g)} </span> ` : X}
          </span>

          <span class="line2"> ${f(this, d, B) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span>
        </span>
      </li>
    `;
  }
};
d = /* @__PURE__ */ new WeakSet();
Z = function() {
  return this.feature?.properties?.categories;
};
B = function() {
  return this.feature?.place_type[0] === "reverse";
};
g = function() {
  return this.feature?.properties?.categories?.join(", ") ?? this.feature?.place_type_name?.[0] ?? this.feature?.place_type[0];
};
Oe = function() {
  Ce ??= fetch(`${this.iconsBaseUrl}sprite${Se}.json`).then((t) => t.json()).then((t) => {
    F = t;
  }).catch(() => {
    F = null;
  });
};
Te = function() {
  this.imageUrl && this.missingIconsCache.add(this.imageUrl), E(this, d, pe).call(this);
};
pe = function() {
  F !== void 0 ? E(this, d, oe).call(this) : (E(this, d, Oe).call(this), Ce?.then(() => {
    E(this, d, oe).call(this);
  }));
};
oe = function() {
  do {
    if (this.index--, this.category = f(this, d, Z)?.[this.index], this.spriteIcon = this.category ? F?.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)));
};
w.styles = I`
    ${ce(ct)}
  `;
L([
  p({ type: Object })
], w.prototype, "feature", 2);
L([
  p({ type: String })
], w.prototype, "itemStyle", 2);
L([
  p({ type: String })
], w.prototype, "showPlaceType", 2);
L([
  p({ attribute: !1 })
], w.prototype, "missingIconsCache", 2);
L([
  p({ type: String })
], w.prototype, "iconsBaseUrl", 2);
L([
  k()
], w.prototype, "category", 2);
L([
  k()
], w.prototype, "imageUrl", 2);
L([
  k()
], w.prototype, "spriteIcon", 2);
L([
  k()
], w.prototype, "index", 2);
w = L([
  O("maptiler-geocoder-feature-item")
], w);
const ut = "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 ft = Object.defineProperty, mt = Object.getOwnPropertyDescriptor, Ee = (t) => {
  throw TypeError(t);
}, c = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? mt(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = (a ? r(e, i, s) : r(s)) || s);
  return a && s && ft(e, i, s), s;
}, de = (t, e, i) => e.has(t) || Ee("Cannot " + i), b = (t, e, i) => (de(t, e, "read from private field"), i ? i.call(t) : e.get(t)), C = (t, e, i) => e.has(t) ? Ee("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), W = (t, e, i, a) => (de(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (de(t, e, "access private method"), i), Q, V, G, ae, R, l, K, Pe, Ue, ue, x, fe, Y, me, ge, $, ye, H, Be, le, Ge, Re, ze, je, De;
let n = class extends M {
  constructor() {
    super(...arguments), C(this, l), 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, C(this, Q, !1), C(this, V, !1), C(this, G), C(this, ae, /* @__PURE__ */ new Set()), C(this, R);
  }
  firstUpdated() {
    W(this, Q, !0);
  }
  /**
   * Set the options of this instance.
   *
   * @param options options to set
   */
  setOptions(t) {
    const e = { ...t };
    for (const i of Object.keys(e))
      gt.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, l, ge).call(this, t, { external: !0 }), h(this, l, me).call(this);
  }
  /**
   * Set the content of search input box and immediately submit it.
   *
   * @param value text to set and submit
   */
  submitQuery(t) {
    h(this, l, ye).call(this, t);
  }
  /**
   * Clear search result list.
   */
  clearList() {
    h(this, l, $).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, R, t);
  }
  /** @internal */
  handleMapClick(t) {
    this.reverseActive && h(this, l, 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, l, $).call(this), this.selectedItemIndex = -1), ["searchValue", "minLength"].some((e) => t.has(e)) && b(this, l, ue) && (h(this, l, $).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, l, x).call(this, "select", { feature: b(this, l, K) }), ["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, l, H).call(this, this.picked.id, { byId: !0 }) : Promise.resolve()).then(
      () => {
        h(this, l, x).call(this, "pick", { feature: this.picked });
      },
      (e) => {
        e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, l, x).call(this, "pick", { feature: this.picked }));
      }
    ), ["listFeatures", "focusedDelayed"].some((e) => t.has(e)) && (b(this, l, Pe) ? (h(this, l, x).call(this, "featuresshow"), W(this, V, !0)) : b(this, V) && h(this, l, x).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, l, x).call(this, "reversetoggle", { reverse: this.reverseActive });
  }
  render() {
    return m`
      <form @submit=${h(this, l, fe)} class=${D({ "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, l, le)}
            @input=${h(this, l, Ge)}
            @change=${() => this.picked = void 0}
            placeholder=${this.placeholder ?? "Search"}
            aria-label=${this.placeholder ?? "Search"}
          />

          <div class="clear-button-container ${D({ displayable: this.searchValue !== "" })}">
            ${b(this, l, Ue) ? m`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : m`
                  <button type="button" @click=${h(this, l, De)} title=${this.clearButtonTitle ?? "clear"}>
                    <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon>
                  </button>
                `}
          </div>

          ${this.enableReverse === "button" ? m`
                <button
                  type="button"
                  class=${D({ 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>
              ` : X}

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

        ${this.error ? m`
              <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 ? X : this.listFeatures.length === 0 ? m`
                  <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>
                ` : m`
                  <ul class="options ${D({ "open-on-top": this.openListOnTop })}" @mouseleave=${h(this, l, je)} @keydown=${h(this, l, le)} role="listbox">
                    ${qe(
      this.listFeatures,
      (t) => t.id + (t.address ? "," + t.address : ""),
      (t, e) => m`
                        <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, l, ze).call(this, e);
      }}
                          @select=${() => {
        h(this, l, Re).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>
    `;
  }
};
Q = /* @__PURE__ */ new WeakMap();
V = /* @__PURE__ */ new WeakMap();
G = /* @__PURE__ */ new WeakMap();
ae = /* @__PURE__ */ new WeakMap();
R = /* @__PURE__ */ new WeakMap();
l = /* @__PURE__ */ new WeakSet();
K = function() {
  return this.listFeatures?.[this.selectedItemIndex];
};
Pe = function() {
  return !!this.listFeatures?.length && (this.focusedDelayed || this.keepListOpen);
};
Ue = function() {
  return this.abortController !== void 0;
};
ue = function() {
  return this.searchValue.length < (this.minLength ?? 2);
};
x = function(t, ...[e]) {
  b(this, Q) && this.dispatchEvent(
    new CustomEvent(t, {
      bubbles: !0,
      composed: !0,
      detail: e
    })
  );
};
fe = function(t) {
  t?.preventDefault(), this.focused = !1, clearTimeout(b(this, G)), 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, l, H).call(this, this.searchValue, { exact: !0, external: t === void 0 }).then(() => {
    this.picked = void 0;
  }).catch((e) => this.error = e);
};
Y = function(t) {
  try {
    return Ve(t, 6);
  } catch {
    return !1;
  }
};
me = function() {
  setTimeout(() => {
    this.input.focus(), this.focused = !0, this.input.select();
  });
};
ge = function(t, { external: e = !1 } = {}) {
  if (this.searchValue = t, h(this, l, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, l, Y).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) {
    if (clearTimeout(b(this, G)), b(this, l, ue))
      return;
    const i = this.searchValue;
    W(this, G, window.setTimeout(() => {
      h(this, l, H).call(this, i, { external: e }).catch((a) => this.error = a);
    }, this.debounceSearch ?? 200));
  } else
    h(this, l, $).call(this);
};
$ = function() {
  this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, l, x).call(this, "featuresclear"));
};
ye = function(t) {
  this.searchValue = t, h(this, l, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, l, Y).call(this, t) }), this.selectedItemIndex = -1, h(this, l, fe).call(this);
};
H = async function(t, { byId: e = !1, exact: i = !1, external: a = !1 } = {}) {
  this.error = void 0, this.abortController?.abort();
  const s = new AbortController();
  this.abortController = s;
  try {
    const o = this.apiUrl ?? "https://api.maptiler.com/geocoding", r = h(this, l, Y).call(this, t), u = new URL(o + "/" + encodeURIComponent(r ? `${r.decimalLongitude},${r.decimalLatitude}` : t) + ".json"), y = u.searchParams;
    this.language !== void 0 && y.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? "");
    const [T] = b(this, R) ?? [void 0];
    let _ = (!r || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map(
      (v) => typeof v == "string" ? v : T === void 0 || (v[0] ?? 0) <= T && T < (v[1] ?? 1 / 0) ? v[2] : void 0
    ).filter((v) => v !== void 0);
    _ && (_ = [...new Set(_)], y.set("types", _.join(",")));
    const ve = !r || this.reverseGeocodingExcludeTypes === void 0 ? this.excludeTypes : this.reverseGeocodingExcludeTypes;
    if (ve && y.set("excludeTypes", String(ve)), this.bbox && y.set("bbox", this.bbox.map((v) => v.toFixed(6)).join(",")), this.country && y.set("country", Array.isArray(this.country) ? this.country.join(",") : this.country), this.worldview && y.set("worldview", this.worldview), !e && !r) {
      const v = this.proximity ?? [{ type: "server-geolocation" }], be = await nt(b(this, R), v, s);
      be && y.set("proximity", be), (i || this.showResultsWhileTyping === !1) && y.set("autocomplete", "false"), y.set("fuzzyMatch", String(this.fuzzyMatch !== !1));
    }
    const xe = this.limit ?? 5, J = this.reverseGeocodingLimit ?? xe;
    J > 1 && _?.length !== 1 && console.warn("[MapTilerGeocodingControl] Warning: For reverse geocoding when limit > 1 then types must contain single value."), r ? (J === 1 || this.exhaustiveReverseGeocoding || _?.length === 1) && y.set("limit", String(J)) : y.set("limit", String(xe)), this.apiKey && y.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, l, $).call(this), this.picked = this.cachedFeatures[0]) : (this.listFeatures = this.cachedFeatures, h(this, l, x).call(this, "featureslisted", { features: this.listFeatures, external: a }), this.listFeatures[this.selectedItemIndex]?.id !== b(this, l, K)?.id && (this.selectedItemIndex = -1));
      return;
    }
    h(this, l, 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, l, x).call(this, "response", { url: j, featureCollection: P }), e ? (this.clearListOnPick && h(this, l, $).call(this), this.picked = P.features[0], this.cachedFeatures = [this.picked]) : (this.listFeatures = P.features.filter(this.filter ?? (() => !0)), r && this.listFeatures.unshift({
      type: "Feature",
      properties: {},
      /* eslint-disable @typescript-eslint/restrict-template-expressions */
      id: `reverse_${r.decimalLongitude}_${r.decimalLatitude}`,
      text: `${r.decimalLatitude}, ${r.decimalLongitude}`,
      place_name: r.toCoordinateFormat("DMS"),
      /* eslint-enable @typescript-eslint/restrict-template-expressions */
      place_type: ["reverse"],
      place_type_name: ["reverse"],
      center: [r.decimalLongitude, r.decimalLatitude],
      bbox: [r.decimalLongitude, r.decimalLatitude, r.decimalLongitude, r.decimalLatitude],
      geometry: {
        type: "Point",
        coordinates: [r.decimalLongitude, r.decimalLatitude]
      }
    }), h(this, l, x).call(this, "featureslisted", { features: this.listFeatures, external: a }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== b(this, l, K)?.id && (this.selectedItemIndex = -1), r && this.input.focus());
  } catch (o) {
    if (o && typeof o == "object" && "name" in o && o.name === "AbortError")
      return;
    throw o;
  } finally {
    s === this.abortController && (this.abortController = void 0);
  }
};
Be = function(t) {
  this.reverseActive = this.enableReverse === "always", h(this, l, $).call(this), this.picked = void 0, h(this, l, ye).call(this, `${t[1].toFixed(6)}, ${lt(t[0], [-180, 180], !0).toFixed(6)}`), h(this, l, me).call(this);
};
le = 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, l, ge).call(this, t.target.value);
};
Re = function(t) {
  (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name);
};
ze = function(t) {
  this.selectedItemIndex = t;
};
je = function() {
  (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1);
};
De = function() {
  this.searchValue = "", h(this, l, x).call(this, "queryclear"), this.picked = void 0, this.input.focus();
};
n.styles = I`
    ${ce(ut)}
  `;
c([
  p({ attribute: !1 })
], n.prototype, "adjustUrl", 2);
c([
  p({ type: String })
], n.prototype, "apiKey", 2);
c([
  p({ type: String })
], n.prototype, "apiUrl", 2);
c([
  p({ type: Array })
], n.prototype, "bbox", 2);
c([
  p({ type: String })
], n.prototype, "clearButtonTitle", 2);
c([
  p({ type: Boolean })
], n.prototype, "clearListOnPick", 2);
c([
  p({ type: Boolean })
], n.prototype, "clearOnBlur", 2);
c([
  p({ type: Boolean })
], n.prototype, "collapsed", 2);
c([
  p({ attribute: !1 })
], n.prototype, "country", 2);
c([
  p({ type: Number })
], n.prototype, "debounceSearch", 2);
c([
  p({ type: String })
], n.prototype, "enableReverse", 2);
c([
  p({ type: String })
], n.prototype, "errorMessage", 2);
c([
  p({ type: Boolean })
], n.prototype, "excludeTypes", 2);
c([
  p({ type: Boolean })
], n.prototype, "exhaustiveReverseGeocoding", 2);
c([
  p({ type: Boolean })
], n.prototype, "fetchFullGeometryOnPick", 2);
c([
  p({ type: Object })
], n.prototype, "fetchParameters", 2);
c([
  p({ attribute: !1 })
], n.prototype, "filter", 2);
c([
  p({ type: Object })
], n.prototype, "fuzzyMatch", 2);
c([
  p({ type: String })
], n.prototype, "iconsBaseUrl", 2);
c([
  p({ type: Boolean })
], n.prototype, "keepListOpen", 2);
c([
  p({ attribute: !1 })
], n.prototype, "language", 2);
c([
  p({ type: Number })
], n.prototype, "limit", 2);
c([
  p({ type: Number })
], n.prototype, "minLength", 2);
c([
  p({ type: String })
], n.prototype, "noResultsMessage", 2);
c([
  p({ type: Boolean })
], n.prototype, "openListOnTop", 2);
c([
  p({ type: String })
], n.prototype, "placeholder", 2);
c([
  p({ type: Array })
], n.prototype, "proximity", 2);
c([
  p({ type: Boolean })
], n.prototype, "reverseActive", 2);
c([
  p({ type: String })
], n.prototype, "reverseButtonTitle", 2);
c([
  p({ type: Object })
], n.prototype, "reverseGeocodingExcludeTypes", 2);
c([
  p({ type: Number })
], n.prototype, "reverseGeocodingLimit", 2);
c([
  p({ type: Array })
], n.prototype, "reverseGeocodingTypes", 2);
c([
  p({ type: Object })
], n.prototype, "selectFirst", 2);
c([
  p({ type: String })
], n.prototype, "showPlaceType", 2);
c([
  p({ type: Object })
], n.prototype, "showResultsWhileTyping", 2);
c([
  p({ type: Array })
], n.prototype, "types", 2);
c([
  p({ type: String })
], n.prototype, "worldview", 2);
c([
  We("input")
], n.prototype, "input", 2);
c([
  k()
], n.prototype, "searchValue", 2);
c([
  k()
], n.prototype, "listFeatures", 2);
c([
  k()
], n.prototype, "selectedItemIndex", 2);
c([
  k()
], n.prototype, "picked", 2);
c([
  k()
], n.prototype, "cachedFeatures", 2);
c([
  k()
], n.prototype, "lastSearchUrl", 2);
c([
  k()
], n.prototype, "error", 2);
c([
  k()
], n.prototype, "abortController", 2);
c([
  k()
], n.prototype, "focused", 2);
c([
  k()
], n.prototype, "focusedDelayed", 2);
n = c([
  O("maptiler-geocoder")
], n);
const gt = [
  "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"
], yt = "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 vt = Object.getOwnPropertyDescriptor, xt = (t, e, i, a) => {
  for (var s = a > 1 ? void 0 : a ? vt(e, i) : e, o = t.length - 1, r; o >= 0; o--)
    (r = t[o]) && (s = r(s) || s);
  return s;
};
let ne = class extends M {
  render() {
    return z`
      <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>
    `;
  }
};
ne.styles = I`
    ${ce(yt)}
  `;
ne = xt([
  O("maptiler-geocode-marker")
], ne);
function we(t) {
  const e = Ke(
    q([
      Ze([
        [
          [180, 90],
          [-180, 90],
          [-180, -90],
          [180, -90],
          [180, 90]
        ]
      ]),
      t
    ])
  );
  if (!e)
    return;
  e.properties = { isMask: !0 };
  const i = N(ke(t)), a = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, o = i[2] > 180, r = Ye(t);
  if (r.features.length > 1 && (s || o))
    for (const u of r.features) {
      const y = N(ke(u));
      if (o && y[0] < -180 + a)
        for (const T of u.geometry.coordinates)
          for (const _ of T)
            _[0] += 360 - a;
      if (s && y[2] > 180 - a)
        for (const T of u.geometry.coordinates)
          for (const _ of T)
            _[0] -= 360 - a;
    }
  return q([r.features.length < 2 ? t : $e(r) ?? t, e]);
}
const bt = {
  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
}, kt = {
  fill: {
    paint: {
      "fill-color": "#000",
      "fill-opacity": 0.1
    },
    filter: ["all", ["==", ["geometry-type"], "Polygon"], ["has", "isMask"]]
  },
  line: {
    layout: {
      "line-cap": "square"
    },
    paint: {
      "line-width": ["case", ["==", ["geometry-type"], "Polygon"], 2, 3],
      "line-dasharray": [1, 1],
      "line-color": "#3170fe"
    },
    filter: ["!", ["has", "isMask"]]
  }
}, A = "mtlr-gc-full-geom", _e = "mtlr-gc-full-geom-fill", Le = "mtlr-gc-full-geom-line", wt = he.Evented, _t = he.Marker, Lt = he.Popup;
class Rt extends wt {
  #e = {};
  #t;
  #i;
  constructor(e = {}) {
    super(), this.setOptions(e);
  }
  /** @internal Not to be called directly */
  onAdd(e) {
    this.#t = e, this.#i = e._container.ownerDocument.createElement("maptiler-geocoder"), this.#i.classList.add("maplibregl-geocoder"), this.#v(), this.#w();
    const i = e._container.ownerDocument.createElement("div");
    return i.classList.add("maplibregl-ctrl-geocoder", "maplibregl-ctrl", "maplibregl-ctrl-group"), i.style.position = "relative", i.style.zIndex = "3", i.appendChild(this.#i), setTimeout(() => this.#i?.setOptions({ openListOnTop: i.matches(".maplibregl-ctrl-bottom-left *, .maplibregl-ctrl-bottom-right *") })), i;
  }
  /** @internal Not to be called directly */
  onRemove() {
    this.#_(), this.#t = void 0, this.#i = void 0;
  }
  getOptions() {
    return { ...this.#e };
  }
  setOptions(e) {
    Object.assign(this.#e, e), this.#v();
  }
  setQuery(e) {
    this.#i?.setQuery(e);
  }
  submitQuery(e) {
    this.#i?.submitQuery(e);
  }
  clearMap() {
    this.#o = [], this.#p(void 0, void 0);
  }
  clearList() {
    this.#i?.clearList();
  }
  setReverseMode(e) {
    this.setOptions({ reverseActive: e });
  }
  focus(e) {
    this.#i?.focus(e);
  }
  blur() {
    this.#i?.blur();
  }
  /** Markers currently displayed on the map */
  #l = /* @__PURE__ */ new Map();
  /** Marker representing the selected feature */
  #c;
  /** Marker representing the picked feature */
  #r;
  /** Features currently marked on the map */
  #o;
  /** Used to restore features on style switch */
  #a;
  /** Remember last feature that the map flew to as to not do it again */
  #m;
  #g = {
    reversetoggle: (e) => {
      const i = this.#t?.getCanvasContainer();
      i && (i.style.cursor = e.detail.reverse ? "crosshair" : ""), this.#s("reversetoggle", e.detail);
    },
    querychange: (e) => {
      const i = e.detail.reverseCoords;
      this.#k(i ? [i.decimalLongitude, i.decimalLatitude] : void 0), this.#s("querychange", e.detail);
    },
    queryclear: () => {
      this.#k(void 0), this.#s("queryclear");
    },
    request: (e) => {
      this.#s("request", e.detail);
    },
    response: (e) => {
      this.#s("response", e.detail);
    },
    select: (e) => {
      const i = e.detail.feature;
      i && this.#d && this.#e.flyToSelected && this.#x(i.center, this.#h(i)), this.#o && i && this.#O(i), this.#s("select", e.detail);
    },
    pick: (e) => {
      const i = e.detail.feature;
      i && i.id !== this.#m && this.#d && (this.#L(i), this.#p(this.#o, i)), this.#m = i?.id, this.#s("pick", e.detail);
    },
    featuresshow: () => {
      this.#s("featuresshow");
    },
    featureshide: () => {
      this.#s("featureshide");
    },
    featureslisted: (e) => {
      const i = e.detail.features;
      this.#o = i, this.#p(this.#o, void 0), this.#$(e), this.#s("featureslisted", e.detail);
    },
    featuresclear: () => {
      this.#o = void 0, this.#p(void 0, void 0), this.#s("featuresclear");
    },
    focusin: () => {
      this.#s("focusin");
    },
    focusout: () => {
      this.#s("focusout");
    }
  };
  #y = {
    render: () => {
      const e = this.#t?.getZoom(), i = this.#t?.getCenter();
      this.#i?.handleMapChange(e && i ? [e, i.lng, i.lat] : void 0);
    },
    click: (e) => {
      this.#i?.handleMapClick([e.lngLat.lng, e.lngLat.lat]);
    },
    styledata: () => {
      setTimeout(() => {
        this.#a && this.#u();
      });
    }
  };
  #v() {
    this.#i && (this.#i.setOptions(this.#e), this.#i.fetchFullGeometryOnPick = this.#e.pickedResultStyle !== "marker-only");
  }
  #w() {
    if (!(!this.#i || !this.#t)) {
      for (const [e, i] of Object.entries(this.#g))
        this.#i.addEventListener(e, i);
      for (const [e, i] of Object.entries(this.#y))
        this.#t.on(e, i);
    }
  }
  #_() {
    if (!(!this.#i || !this.#t)) {
      for (const [e, i] of Object.entries(this.#g))
        this.#i.removeEventListener(e, i);
      for (const [e, i] of Object.entries(this.#y))
        this.#t.off(e, i);
    }
  }
  #s(e, i) {
    return super.fire({ type: e, ...i ?? {} });
  }
  #L(e) {
    e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#x(e.center, this.#h(e)) : this.#b(N(e.bbox), 50, this.#h(e));
  }
  #$({ detail: { features: e, external: i } }) {
    if (!e || e.length === 0 || !this.#d || this.#e.flyToFeatures === !1 || this.#e.flyToFeatures === "never" || !i && (this.#e.flyToFeatures === void 0 || this.#e.flyToFeatures === "external"))
      return;
    const a = e.every((r) => r.matching_text), s = e.reduce(
      (r, u) => a || !u.matching_text ? [Math.min(r[0], u.bbox[0]), Math.min(r[1], u.bbox[1]), Math.max(r[2], u.bbox[2]), Math.max(r[3], u.bbox[3])] : r,
      [180, 90, -180, -90]
    ), o = e.map((r) => this.#h(r)).filter((r) => r !== void 0).reduce((r, u) => r === void 0 ? u : Math.max(r, u), void 0);
    this.#b(N(s), 50, o);
  }
  #h(e) {
    if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3])
      return;
    const i = e.id.replace(/\..*/, ""), a = this.#e.zoom ?? bt;
    return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, o) => {
      const r = a[i + "." + o];
      return s === void 0 ? r : r === void 0 ? s : Math.max(s, r);
    }, void 0) : void 0) ?? a[i];
  }
  get #d() {
    return !!this.#e.flyTo || this.#e.flyTo === void 0;
  }
  get #I() {
    return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
  }
  get #M() {
    return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
  }
  #x(e, i) {
    this.#t?.flyTo({ center: e, ...i ? { zoom: i } : {}, ...this.#I });
  }
  #b(e, i, a) {
    this.#t?.fitBounds(
      [
        [e[0], e[1]],
        [e[2], e[3]]
      ],
      { padding: i, ...a ? { maxZoom: a } : {}, ...this.#M }
    );
  }
  #k(e) {
    if (!(this.#e.marker === !1 || this.#e.marker === null || !this.#t)) {
      if (!e) {
        this.#r?.remove(), this.#r = void 0;
        return;
      }
      this.#r || (this.#e.marker instanceof Function ? this.#r = this.#e.marker(this.#t) ?? void 0 : (this.#r = this.#f(this.#e.marker).setLngLat(e).addTo(this.#t), this.#r.getElement().classList.add("marker-reverse"))), this.#r?.setLngLat(e);
    }
  }
  #p(e, i) {
    if (!this.#t)
      return;
    for (const s of this.#l.values())
      s.remove();
    this.#l = /* @__PURE__ */ new Map(), this.#n(void 0);
    const a = () => {
      if (!i || !this.#t || this.#e.marker === !1 || this.#e.marker === null) return;
      const s = this.#e.marker instanceof Function ? this.#e.marker(this.#t, i) : this.#f(this.#e.marker).setLngLat(i.center).addTo(this.#t);
      s && this.#l.set(i, s);
    };
    if (i?.geometry.type === "GeometryCollection") {
      const s = i.geometry.geometries.filter(
        (o) => o.type === "Polygon" || o.type === "MultiPolygon"
      );
      if (s.length > 0) {
        const o = $e(q(s.map((r) => Qe(r))));
        if (o) {
          const r = we({ ...i, geometry: o.geometry });
          r && this.#n(r);
        }
      } else {
        const o = i.geometry.geometries.filter(
          (r) => r.type === "LineString" || r.type === "MultiLineString"
        );
        o.length > 0 && this.#n({
          ...i,
          geometry: { type: "GeometryCollection", geometries: o }
        });
      }
    } else if (i?.geometry.type.endsWith("Polygon")) {
      const s = we(i);
      s && this.#n(s), this.#e.pickedResultStyle === "full-geometry-including-polygon-center-marker" && a();
    } else i?.geometry.type.endsWith("LineString") ? this.#n(i) : i?.geometry.type.endsWith("Point") && a();
    if (this.#e.showResultMarkers !== !1 && this.#e.showResultMarkers !== null)
      for (const s of e ?? []) {
        if (s.id === i?.id || s.place_type.includes("reverse"))
          continue;
        let o;
        if (this.#e.showResultMarkers instanceof Function) {
          if (o = this.#e.showResultMarkers(this.#t, s), !o)
            continue;
        } else
          o = this.#f(this.#e.showResultMarkers).setLngLat(s.center).setPopup(
            new Lt({
              offset: [1, -27],
              closeButton: !1,
              closeOnMove: !0,
              className: "maptiler-gc-popup"
            }).setText(s.place_type[0] === "reverse" ? s.place_name : s.place_name.replace(/,.*/, ""))
          ).addTo(this.#t), o.getElement().classList.add("marker-interactive");
        const r = o.getElement();
        r.addEventListener("click", (u) => {
          u.stopPropagation(), this.#s("markerclick", { feature: s, marker: o });
        }), r.addEventListener("mouseenter", () => {
          this.#s("markermouseenter", { feature: s, marker: o }), o.togglePopup();
        }), r.addEventListener("mouseleave", () => {
          this.#s("markermouseleave", { feature: s, marker: o }), o.togglePopup();
        }), r.classList.toggle("marker-fuzzy", !!s.matching_text), this.#l.set(s, o);
      }
  }
  #O(e) {
    this.#c?.getElement().classList.toggle("marker-selected", !1), this.#c = void 0, this.#e.markerOnSelected !== !1 && (this.#c = this.#l.get(e), this.#c?.getElement().classList.toggle("marker-selected", !0));
  }
  #u() {
    if (!this.#t?.loaded) {
      this.#t?.once("load", () => {
        this.#u();
      });
      return;
    }
    const e = this.#T(), i = this.#t.getSource(A);
    !e?.fill && !e?.line || !i && !this.#a || (i ? i.setData(this.#a ?? q([])) : this.#a && this.#t.addSource(A, {
      type: "geojson",
      data: this.#a
    }), !this.#t.getLayer(_e) && e.fill && this.#t.addLayer({
      ...e.fill,
      id: _e,
      type: "fill",
      source: A
    }), !this.#t.getLayer(Le) && e.line && this.#t.addLayer({
      ...e.line,
      id: Le,
      type: "line",
      source: A
    }));
  }
  #n(e) {
    this.#a = e, this.#u();
  }
  #f(e) {
    return typeof e != "object" && (e = { element: this.#t?._container.ownerDocument.createElement("maptiler-geocode-marker"), offset: [1, -13] }), new _t(e);
  }
  #T() {
    const { fullGeometryStyle: e } = this.#e;
    if (e === !0 || e === void 0) return kt;
    if (!(e === !1 || e === null))
      return e;
  }
}
export {
  kt as DEFAULT_GEOMETRY_STYLE,
  Rt as GeocodingControl,
  Rt as MaplibreglGeocodingControl,
  ee as MaptilerGeocodeClearIconElement,
  te as MaptilerGeocodeFailIconElement,
  ie as MaptilerGeocodeLoadingIconElement,
  ne as MaptilerGeocodeMarkerElement,
  se as MaptilerGeocodeReverseGeocodingIconElement,
  re as MaptilerGeocodeSearchIconElement,
  n as MaptilerGeocoderElement,
  _e as RESULT_LAYER_FILL,
  Le as RESULT_LAYER_LINE,
  A as RESULT_SOURCE,
  bt as ZOOM_DEFAULTS
};
//# sourceMappingURL=maplibregl.js.map
