import { css as M, LitElement as S, svg as A, html as m, unsafeCSS as he, nothing as ee } from "lit";
import { customElement as F, property as d, state as b, query as qe } from "lit/decorators.js";
import { convert as Ze } from "geo-coordinates-parser";
import { classMap as V } from "lit/directives/class-map.js";
import { repeat as Ne } from "lit/directives/repeat.js";
import "@turf/clone";
import { styleMap as Qe } from "lit/directives/style-map.js";
import { Feature as $ } from "ol";
import { Control as Ke } from "ol/control";
import { Point as X, Polygon as be, MultiPolygon as we, GeometryCollection as Ye, LineString as ke, MultiLineString as _e } from "ol/geom";
import He from "ol/layer/Vector";
import { transformExtent as Je, getUserProjection as Xe, fromLonLat as et, toLonLat as tt } from "ol/proj";
import it from "ol/source/Vector";
import $e from "@turf/bbox";
import st from "@turf/difference";
import rt from "@turf/flatten";
import { featureCollection as Le, polygon as ot } from "@turf/helpers";
import at from "@turf/union";
import Ie from "ol/style/Fill";
import nt from "ol/style/Icon";
import Me from "ol/style/Stroke";
import lt from "ol/style/Style";
import ct from "ol/style/Text";
var ht = Object.getOwnPropertyDescriptor, dt = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? ht(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let te = class extends S {
  render() {
    return A`
      <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>
    `;
  }
};
te.styles = M`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
te = dt([
  F("maptiler-geocode-clear-icon")
], te);
var pt = Object.getOwnPropertyDescriptor, ut = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? pt(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let ie = class extends S {
  render() {
    return A`
      <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>
    `;
  }
};
ie.styles = M`
    svg {
      display: block;
      fill: #e15042;
    }
  `;
ie = ut([
  F("maptiler-geocode-fail-icon")
], ie);
var ft = Object.getOwnPropertyDescriptor, mt = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? ft(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let se = class extends S {
  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>
    `;
  }
};
se.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);
      }
    }
  `;
se = mt([
  F("maptiler-geocode-loading-icon")
], se);
var gt = Object.getOwnPropertyDescriptor, yt = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? gt(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let re = class extends S {
  render() {
    return A`
      <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>
    `;
  }
};
re.styles = M`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
re = yt([
  F("maptiler-geocode-reverse-geocoding-icon")
], re);
var vt = Object.getOwnPropertyDescriptor, xt = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? vt(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let oe = class extends S {
  render() {
    return A`
      <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 = xt([
  F("maptiler-geocode-search-icon")
], oe);
function bt(t, e, i) {
  const o = e[1], r = e[0], s = o - r;
  return t === o && i ? t : ((t - r) % s + s) % s + r;
}
function Z(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 G;
async function wt(t, e, i) {
  for (const o of e ?? [])
    if (!(t && (o.minZoom != null && o.minZoom > t[0] || o.maxZoom != null && o.maxZoom < t[0]))) {
      if (o.type === "fixed")
        return o.coordinates.join(",");
      if (o.type === "client-geolocation")
        if (G && o.cachedLocationExpiry && G.time + o.cachedLocationExpiry > Date.now()) {
          if (G.coords)
            return G.coords;
        } else {
          let r;
          try {
            return r = await new Promise((s, a) => {
              i.signal.addEventListener("abort", () => {
                a(Error("aborted"));
              }), navigator.geolocation.getCurrentPosition(
                (f) => {
                  s([f.coords.longitude, f.coords.latitude].map((L) => L.toFixed(6)).join(","));
                },
                (f) => {
                  a(f);
                },
                o
              );
            }), r;
          } catch {
          } finally {
            o.cachedLocationExpiry && (G = {
              time: Date.now(),
              coords: r
            });
          }
          if (i.signal.aborted)
            return;
        }
      if (o.type === "server-geolocation")
        return "ip";
      if (t && o.type === "map-center")
        return t[1].toFixed(6) + "," + t[2].toFixed(6);
    }
}
const kt = ".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 _t = Object.defineProperty, $t = Object.getOwnPropertyDescriptor, Se = (t) => {
  throw TypeError(t);
}, _ = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? $t(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = (o ? a(e, i, r) : a(r)) || r);
  return o && r && _t(e, i, r), r;
}, Fe = (t, e, i) => e.has(t) || Se("Cannot " + i), u = (t, e, i) => (Fe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), Lt = (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), U = (t, e, i) => (Fe(t, e, "access private method"), i), p, N, z, g, Oe, Ce, de, ae;
const Te = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Pe = Te ? "@2x" : "", P = Te ? 2 : 1;
let C, Ee, w = class extends S {
  constructor() {
    super(...arguments), Lt(this, p), this.itemStyle = "default", this.showPlaceType = "if-needed", this.missingIconsCache = /* @__PURE__ */ new Set(), this.iconsBaseUrl = "", this.index = 0;
  }
  willUpdate(t) {
    t.has("feature") && u(this, p, N) && (this.index = u(this, p, N).length, U(this, p, de).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"))}
      >
        ${C && this.spriteIcon ? m`
              <div
                class="sprite-icon"
                style=${Qe({
      width: `${this.spriteIcon.width / P}px`,
      height: `${this.spriteIcon.height / P}px`,
      backgroundImage: `url(${this.iconsBaseUrl}sprite${Pe}.png)`,
      backgroundPosition: `-${this.spriteIcon.x / P}px -${this.spriteIcon.y / P}px`,
      backgroundSize: `${C.width / P}px ${C.height / P}px`
    })}
                title=${u(this, p, g)}
              />
            ` : this.imageUrl ? m` <img src=${this.imageUrl} alt=${this.category} title=${u(this, p, g)} @error=${U(this, p, Ce)} />` : this.feature?.address ? m` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : this.feature?.id.startsWith("road.") ? m` <img src=${this.iconsBaseUrl + "road.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : this.feature?.id.startsWith("address.") ? m` <img src=${this.iconsBaseUrl + "street.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : this.feature?.id.startsWith("postal_code.") ? m` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : this.feature?.id.startsWith("poi.") ? m` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : u(this, p, z) ? m` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> ` : m` <img src=${this.iconsBaseUrl + "area.svg"} alt=${u(this, p, g)} title=${u(this, p, g)} /> `}

        <span class="texts">
          <span>
            <span class="primary"> ${u(this, p, z) ? 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) && !u(this, p, z) ? m` <span class="secondary"> ${u(this, p, g)} </span> ` : ee}
          </span>

          <span class="line2"> ${u(this, p, z) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span>
        </span>
      </li>
    `;
  }
};
p = /* @__PURE__ */ new WeakSet();
N = function() {
  return this.feature?.properties?.categories;
};
z = 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() {
  Ee ??= fetch(`${this.iconsBaseUrl}sprite${Pe}.json`).then((t) => t.json()).then((t) => {
    C = t;
  }).catch(() => {
    C = null;
  });
};
Ce = function() {
  this.imageUrl && this.missingIconsCache.add(this.imageUrl), U(this, p, de).call(this);
};
de = function() {
  C !== void 0 ? U(this, p, ae).call(this) : (U(this, p, Oe).call(this), Ee?.then(() => {
    U(this, p, ae).call(this);
  }));
};
ae = function() {
  do {
    if (this.index--, this.category = u(this, p, N)?.[this.index], this.spriteIcon = this.category ? C?.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 = M`
    ${he(kt)}
  `;
_([
  d({ type: Object })
], w.prototype, "feature", 2);
_([
  d({ type: String })
], w.prototype, "itemStyle", 2);
_([
  d({ type: String })
], w.prototype, "showPlaceType", 2);
_([
  d({ attribute: !1 })
], w.prototype, "missingIconsCache", 2);
_([
  d({ type: String })
], w.prototype, "iconsBaseUrl", 2);
_([
  b()
], w.prototype, "category", 2);
_([
  b()
], w.prototype, "imageUrl", 2);
_([
  b()
], w.prototype, "spriteIcon", 2);
_([
  b()
], w.prototype, "index", 2);
w = _([
  F("maptiler-geocoder-feature-item")
], w);
const It = "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 Mt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, Ue = (t) => {
  throw TypeError(t);
}, c = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? St(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = (o ? a(e, i, r) : a(r)) || r);
  return o && r && Mt(e, i, r), r;
}, pe = (t, e, i) => e.has(t) || Ue("Cannot " + i), x = (t, e, i) => (pe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), E = (t, e, i) => e.has(t) ? Ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), W = (t, e, i, o) => (pe(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (pe(t, e, "access private method"), i), Q, q, j, ne, R, n, K, Be, Ge, ue, v, fe, Y, me, ge, I, ye, H, ze, le, je, Re, Ae, De, Ve;
let l = class extends S {
  constructor() {
    super(...arguments), E(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, E(this, Q, !1), E(this, q, !1), E(this, j), E(this, ne, /* @__PURE__ */ new Set()), E(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))
      Ft.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, ge).call(this, t), h(this, n, 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, n, ye).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, R, t);
  }
  /** @internal */
  handleMapClick(t) {
    this.reverseActive && h(this, n, ze).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)) && x(this, n, ue) && (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, v).call(this, "select", { feature: x(this, n, 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, n, H).call(this, this.picked.id, { byId: !0 }) : Promise.resolve()).then(
      () => {
        h(this, n, v).call(this, "pick", { feature: this.picked });
      },
      (e) => {
        e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, n, v).call(this, "pick", { feature: this.picked }));
      }
    ), ["listFeatures", "focusedDelayed"].some((e) => t.has(e)) && (x(this, n, Be) ? (h(this, n, v).call(this, "featuresshow"), W(this, q, !0)) : x(this, q) && h(this, n, v).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, n, v).call(this, "reversetoggle", { reverse: this.reverseActive });
  }
  render() {
    return m`
      <form @submit=${h(this, n, fe)} class=${V({ "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, le)}
            @input=${h(this, n, je)}
            @change=${() => this.picked = void 0}
            placeholder=${this.placeholder ?? "Search"}
            aria-label=${this.placeholder ?? "Search"}
          />

          <div class="clear-button-container ${V({ displayable: this.searchValue !== "" })}">
            ${x(this, n, Ge) ? m`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : m`
                  <button type="button" @click=${h(this, n, Ve)} title=${this.clearButtonTitle ?? "clear"}>
                    <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon>
                  </button>
                `}
          </div>

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

          <!-- <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 ? ee : 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 ${V({ "open-on-top": this.openListOnTop })}" @mouseleave=${h(this, n, De)} @keydown=${h(this, n, le)} role="listbox">
                    ${Ne(
      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, n, Ae).call(this, e);
      }}
                          @select=${() => {
        h(this, n, Re).call(this, t);
      }}
                          .missingIconsCache=${x(this, ne)}
                          .iconsBaseUrl=${this.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0-rc.4/icons/"}
                        >
                          ${t.place_name}
                        </maptiler-geocoder-feature-item>
                      `
    )}
                  </ul>
                `}
      </form>
    `;
  }
};
Q = /* @__PURE__ */ new WeakMap();
q = /* @__PURE__ */ new WeakMap();
j = /* @__PURE__ */ new WeakMap();
ne = /* @__PURE__ */ new WeakMap();
R = /* @__PURE__ */ new WeakMap();
n = /* @__PURE__ */ new WeakSet();
K = function() {
  return this.listFeatures?.[this.selectedItemIndex];
};
Be = function() {
  return !!this.listFeatures?.length && (this.focusedDelayed || this.keepListOpen);
};
Ge = function() {
  return this.abortController !== void 0;
};
ue = function() {
  return this.searchValue.length < (this.minLength ?? 2);
};
v = function(t, ...[e]) {
  x(this, Q) && this.dispatchEvent(
    new CustomEvent(t, {
      bubbles: !0,
      composed: !0,
      detail: e
    })
  );
};
fe = function(t) {
  t?.preventDefault(), this.focused = !1, clearTimeout(x(this, j)), 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 }).then(() => {
    this.picked = void 0;
  }).catch((e) => this.error = e);
};
Y = function(t) {
  try {
    return Ze(t, 6);
  } catch {
    return !1;
  }
};
me = function() {
  setTimeout(() => {
    this.input.focus(), this.focused = !0, this.input.select();
  });
};
ge = function(t) {
  if (this.searchValue = t, h(this, n, v).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Y).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) {
    if (clearTimeout(x(this, j)), x(this, n, ue))
      return;
    const e = this.searchValue;
    W(this, j, window.setTimeout(() => {
      h(this, n, H).call(this, e).catch((i) => this.error = i);
    }, this.debounceSearch ?? 200));
  } else
    h(this, n, I).call(this);
};
I = function() {
  this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, n, v).call(this, "featuresclear"));
};
ye = function(t) {
  this.searchValue = t, h(this, n, v).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Y).call(this, t) }), this.selectedItemIndex = -1, h(this, n, fe).call(this);
};
H = async function(t, { byId: e = !1, exact: i = !1 } = {}) {
  this.error = void 0, this.abortController?.abort();
  const o = new AbortController();
  this.abortController = o;
  try {
    const r = this.apiUrl ?? "https://api.maptiler.com/geocoding", s = h(this, n, Y).call(this, t), a = new URL(r + "/" + encodeURIComponent(s ? `${s.decimalLongitude},${s.decimalLatitude}` : t) + ".json"), f = a.searchParams;
    this.language !== void 0 && f.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? "");
    const [L] = x(this, R) ?? [void 0];
    let k = (!s || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map(
      (y) => typeof y == "string" ? y : L === void 0 || (y[0] ?? 0) <= L && L < (y[1] ?? 1 / 0) ? y[2] : void 0
    ).filter((y) => y !== void 0);
    k && (k = [...new Set(k)], f.set("types", k.join(",")));
    const T = !s || this.reverseGeocodingExcludeTypes === void 0 ? this.excludeTypes : this.reverseGeocodingExcludeTypes;
    if (T && f.set("excludeTypes", String(T)), this.bbox && f.set("bbox", this.bbox.map((y) => y.toFixed(6)).join(",")), this.country && f.set("country", Array.isArray(this.country) ? this.country.join(",") : this.country), this.worldview && f.set("worldview", this.worldview), !e && !s) {
      const y = this.proximity ?? [{ type: "server-geolocation" }], xe = await wt(x(this, R), y, o);
      xe && f.set("proximity", xe), (i || this.showResultsWhileTyping === !1) && f.set("autocomplete", "false"), f.set("fuzzyMatch", String(this.fuzzyMatch !== !1));
    }
    const ve = this.limit ?? 5, J = this.reverseGeocodingLimit ?? ve;
    J > 1 && k?.length !== 1 && console.warn("[MapTilerGeocodingControl] Warning: For reverse geocoding when limit > 1 then types must contain single value."), s ? (J === 1 || this.exhaustiveReverseGeocoding || k?.length === 1) && f.set("limit", String(J)) : f.set("limit", String(ve)), this.apiKey && f.set("key", this.apiKey), this.adjustUrl?.(a);
    const We = a.searchParams.get("types") === "" && a.searchParams.get("excludeTypes") !== "true", D = a.toString();
    if (D === this.lastSearchUrl) {
      e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = this.cachedFeatures[0]) : (this.listFeatures = this.cachedFeatures, h(this, n, v).call(this, "featureslisted", { features: this.listFeatures }), this.listFeatures[this.selectedItemIndex]?.id !== x(this, n, K)?.id && (this.selectedItemIndex = -1));
      return;
    }
    h(this, n, v).call(this, "request", { urlObj: a }), this.lastSearchUrl = D;
    let B;
    if (We)
      B = { type: "FeatureCollection", features: [] };
    else {
      const y = await fetch(D, {
        signal: o.signal,
        ...this.fetchParameters
      });
      if (!y.ok)
        throw new Error(await y.text());
      B = await y.json();
    }
    h(this, n, v).call(this, "response", { url: D, featureCollection: B }), e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = B.features[0], this.cachedFeatures = [this.picked]) : (this.listFeatures = B.features.filter(this.filter ?? (() => !0)), s && this.listFeatures.unshift({
      type: "Feature",
      properties: {},
      /* eslint-disable @typescript-eslint/restrict-template-expressions */
      id: `reverse_${s.decimalLongitude}_${s.decimalLatitude}`,
      text: `${s.decimalLatitude}, ${s.decimalLongitude}`,
      place_name: s.toCoordinateFormat("DMS"),
      /* eslint-enable @typescript-eslint/restrict-template-expressions */
      place_type: ["reverse"],
      place_type_name: ["reverse"],
      center: [s.decimalLongitude, s.decimalLatitude],
      bbox: [s.decimalLongitude, s.decimalLatitude, s.decimalLongitude, s.decimalLatitude],
      geometry: {
        type: "Point",
        coordinates: [s.decimalLongitude, s.decimalLatitude]
      }
    }), h(this, n, v).call(this, "featureslisted", { features: this.listFeatures }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== x(this, n, K)?.id && (this.selectedItemIndex = -1), s && this.input.focus());
  } catch (r) {
    if (r && typeof r == "object" && "name" in r && r.name === "AbortError")
      return;
    throw r;
  } finally {
    o === this.abortController && (this.abortController = void 0);
  }
};
ze = function(t) {
  this.reverseActive = this.enableReverse === "always", h(this, n, I).call(this), this.picked = void 0, h(this, n, ye).call(this, `${t[1].toFixed(6)}, ${bt(t[0], [-180, 180], !0).toFixed(6)}`), h(this, n, 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));
};
je = function(t) {
  h(this, n, ge).call(this, t.target.value);
};
Re = function(t) {
  (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name);
};
Ae = function(t) {
  this.selectedItemIndex = t;
};
De = function() {
  (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1);
};
Ve = function() {
  this.searchValue = "", h(this, n, v).call(this, "queryclear"), this.picked = void 0, this.input.focus();
};
l.styles = M`
    ${he(It)}
  `;
c([
  d({ attribute: !1 })
], l.prototype, "adjustUrl", 2);
c([
  d({ type: String })
], l.prototype, "apiKey", 2);
c([
  d({ type: String })
], l.prototype, "apiUrl", 2);
c([
  d({ type: Array })
], l.prototype, "bbox", 2);
c([
  d({ type: String })
], l.prototype, "clearButtonTitle", 2);
c([
  d({ type: Boolean })
], l.prototype, "clearListOnPick", 2);
c([
  d({ type: Boolean })
], l.prototype, "clearOnBlur", 2);
c([
  d({ type: Boolean })
], l.prototype, "collapsed", 2);
c([
  d({ attribute: !1 })
], l.prototype, "country", 2);
c([
  d({ type: Number })
], l.prototype, "debounceSearch", 2);
c([
  d({ type: String })
], l.prototype, "enableReverse", 2);
c([
  d({ type: String })
], l.prototype, "errorMessage", 2);
c([
  d({ type: Boolean })
], l.prototype, "excludeTypes", 2);
c([
  d({ type: Boolean })
], l.prototype, "exhaustiveReverseGeocoding", 2);
c([
  d({ type: Boolean })
], l.prototype, "fetchFullGeometryOnPick", 2);
c([
  d({ type: Object })
], l.prototype, "fetchParameters", 2);
c([
  d({ attribute: !1 })
], l.prototype, "filter", 2);
c([
  d({ type: Object })
], l.prototype, "fuzzyMatch", 2);
c([
  d({ type: String })
], l.prototype, "iconsBaseUrl", 2);
c([
  d({ type: Boolean })
], l.prototype, "keepListOpen", 2);
c([
  d({ attribute: !1 })
], l.prototype, "language", 2);
c([
  d({ type: Number })
], l.prototype, "limit", 2);
c([
  d({ type: Number })
], l.prototype, "minLength", 2);
c([
  d({ type: String })
], l.prototype, "noResultsMessage", 2);
c([
  d({ type: Boolean })
], l.prototype, "openListOnTop", 2);
c([
  d({ type: String })
], l.prototype, "placeholder", 2);
c([
  d({ type: Array })
], l.prototype, "proximity", 2);
c([
  d({ type: Boolean })
], l.prototype, "reverseActive", 2);
c([
  d({ type: String })
], l.prototype, "reverseButtonTitle", 2);
c([
  d({ type: Object })
], l.prototype, "reverseGeocodingExcludeTypes", 2);
c([
  d({ type: Number })
], l.prototype, "reverseGeocodingLimit", 2);
c([
  d({ type: Array })
], l.prototype, "reverseGeocodingTypes", 2);
c([
  d({ type: Object })
], l.prototype, "selectFirst", 2);
c([
  d({ type: String })
], l.prototype, "showPlaceType", 2);
c([
  d({ type: Object })
], l.prototype, "showResultsWhileTyping", 2);
c([
  d({ type: Array })
], l.prototype, "types", 2);
c([
  d({ type: String })
], l.prototype, "worldview", 2);
c([
  qe("input")
], l.prototype, "input", 2);
c([
  b()
], l.prototype, "searchValue", 2);
c([
  b()
], l.prototype, "listFeatures", 2);
c([
  b()
], l.prototype, "selectedItemIndex", 2);
c([
  b()
], l.prototype, "picked", 2);
c([
  b()
], l.prototype, "cachedFeatures", 2);
c([
  b()
], l.prototype, "lastSearchUrl", 2);
c([
  b()
], l.prototype, "error", 2);
c([
  b()
], l.prototype, "abortController", 2);
c([
  b()
], l.prototype, "focused", 2);
c([
  b()
], l.prototype, "focusedDelayed", 2);
l = c([
  F("maptiler-geocoder")
], l);
const Ft = [
  "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"
], Ot = "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 Ct = Object.getOwnPropertyDescriptor, Tt = (t, e, i, o) => {
  for (var r = o > 1 ? void 0 : o ? Ct(e, i) : e, s = t.length - 1, a; s >= 0; s--)
    (a = t[s]) && (r = a(r) || r);
  return r;
};
let ce = class extends S {
  render() {
    return A`
      <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>
    `;
  }
};
ce.styles = M`
    ${he(Ot)}
  `;
ce = Tt([
  F("maptiler-geocode-marker")
], ce);
function Pt(t) {
  const e = st(
    Le([
      ot([
        [
          [180, 90],
          [-180, 90],
          [-180, -90],
          [180, -90],
          [180, 90]
        ]
      ]),
      t
    ])
  );
  if (!e)
    return;
  e.properties = { isMask: !0 };
  const i = Z($e(t)), o = (i[2] - i[0]) / 360 / 1e3, r = i[0] < -180, s = i[2] > 180, a = rt(t);
  if (a.features.length > 1 && (r || s))
    for (const f of a.features) {
      const L = Z($e(f));
      if (s && L[0] < -180 + o)
        for (const k of f.geometry.coordinates)
          for (const T of k)
            T[0] += 360 - o;
      if (r && L[2] > 180 - o)
        for (const k of f.geometry.coordinates)
          for (const T of k)
            T[0] -= 360 - o;
    }
  return Le([a.features.length < 2 ? t : at(a) ?? t, e]);
}
const Et = {
  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
}, Ut = (t) => (e) => {
  const i = t.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0-rc.4/icons/", o = e.getProperties(), r = e.getGeometry()?.getType(), s = o.isMask ? 0 : r === "LineString" || r === "MultiLineString" ? 3 : 2;
  return new lt({
    stroke: o.isMask ? void 0 : new Me({
      color: "#3170fe",
      lineDash: [s, s],
      width: s,
      lineCap: "butt"
    }),
    fill: o.isMask ? new Ie({
      color: "#00000020"
    }) : void 0,
    image: new nt({
      src: `${i}marker_${o.isReverse ? "reverse" : o.isSelected ? "selected" : "unselected"}.svg`,
      anchor: [0.5, 1]
    }),
    zIndex: o.isSelected ? 2 : o.isReverse ? 0 : 1,
    text: (o.isSelected || o.isMouseOver) && o.tooltip ? new ct({
      backgroundFill: new Ie({ color: "white" }),
      text: o.tooltip,
      offsetY: -40,
      backgroundStroke: new Me({
        color: "white",
        lineJoin: "round",
        width: 3
      }),
      padding: [2, 0, 0, 2]
    }) : void 0
  });
}, O = "EPSG:4326";
class oi extends Ke {
  #t;
  #e;
  #r;
  constructor(e = {}) {
    const i = document.createElement("div");
    super({
      element: i,
      ...e
    }), this.#t = e, this.#r = document.createElement("maptiler-geocoder"), this.#r.classList.add("openlayers-geocoder"), this.#b(), i.classList.add("openlayers-ctrl-geocoder"), i.style.zIndex = "3", i.appendChild(this.#r);
  }
  /** @internal Not to be called directly */
  setMap(e) {
    super.setMap(e), this.#e && this.#e !== e && (this.#I(), this.#P(), this.#e = void 0), e && (this.#e = e, this.#L(), this.#T());
  }
  getOptions() {
    return { ...this.#t };
  }
  setOptions(e) {
    Object.assign(this.#t, e), this.#b();
  }
  setQuery(e) {
    this.#r.setQuery(e);
  }
  submitQuery(e) {
    this.#r.submitQuery(e);
  }
  clearMap() {
    this.#a = [], this.#u(void 0, void 0);
  }
  clearList() {
    this.#r.clearList();
  }
  setReverseMode(e) {
    this.setOptions({ reverseActive: e });
  }
  focus(e) {
    this.#r.focus(e);
  }
  blur() {
    this.#r.blur();
  }
  /** Markers currently displayed on the map */
  #c = /* @__PURE__ */ new Map();
  /** Marker representing the selected feature */
  #h;
  /** Marker representing the picked feature */
  #o;
  /** Features currently marked on the map */
  #a;
  /** Remember last feature that the map flew to as to not do it again */
  #g;
  /** Layer used for showing results */
  #l;
  /** Source connected to layer used for showing results */
  #s;
  /** Last marker the mouse was over, used to detech mouseover and mouseleave events on markers */
  #d;
  /** Flag whether to show reverse geocoding cursor */
  #y = !1;
  #v = {
    reversetoggle: (e) => {
      this.#y = e.detail.reverse, this.#i("reversetoggle", e.detail);
    },
    querychange: (e) => {
      const i = e.detail.reverseCoords;
      this.#_(i ? [i.decimalLongitude, i.decimalLatitude] : void 0), this.#i("querychange", e.detail);
    },
    queryclear: () => {
      this.#_(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.#m && this.#t.flyToSelected && this.#w(i.center, this.#p(i)), this.#a && i && this.#C(i), this.#i("select", e.detail);
    },
    pick: (e) => {
      const i = e.detail.feature;
      i && i.id !== this.#g && this.#m && (this.#M(i), this.#u(this.#a, i)), this.#g = i?.id, this.#i("pick", e.detail);
    },
    featuresshow: () => {
      this.#i("featuresshow");
    },
    featureshide: () => {
      this.#i("featureshide");
    },
    featureslisted: (e) => {
      const i = e.detail.features;
      this.#a = i, this.#u(this.#a, void 0), this.#S(i), this.#i("featureslisted", e.detail);
    },
    featuresclear: () => {
      this.#a = void 0, this.#u(void 0, void 0), this.#i("featuresclear");
    },
    focusin: () => {
      this.#i("focusin");
    },
    focusout: () => {
      this.#i("focusout");
    }
  };
  #x = {
    postrender: () => {
      const e = this.#e?.getView().getZoom(), i = this.#e?.getView().getCenter();
      this.#r.handleMapChange(e && i ? [e, ...this.#$(i)] : void 0);
    },
    click: (e) => {
      this.#r.handleMapClick(this.#$(e.coordinate)), this.#e?.forEachFeatureAtPixel(e.pixel, (i) => {
        const o = i.getId(), r = this.#a?.find((s) => s.id === o);
        if (!(!o || !r))
          return e.stopPropagation(), this.#i("markerclick", { feature: r, marker: i }), !0;
      });
    },
    pointermove: (e) => {
      if (!this.#e) return;
      const i = this.#e.forEachFeatureAtPixel(e.pixel, (r) => r.getId() ? r : void 0);
      this.#e.getTargetElement().style.cursor = i ? "pointer" : this.#y ? "crosshair" : "";
      const o = i?.getId();
      if (this.#d !== o) {
        if (this.#d) {
          const r = this.#a?.find((a) => a.id === this.#d), s = this.#c.get(r);
          s?.set("isMouseOver", !1), r && s && this.#i("markermouseleave", { feature: r, marker: s });
        }
        if (i) {
          const r = this.#a?.find((s) => s.id === o);
          this.#i("markermouseenter", { feature: r, marker: i }), i.set("isMouseOver", !0);
        }
        this.#d = o;
      }
    }
  };
  #b() {
    this.#r.setOptions(this.#t), this.#r.fetchFullGeometryOnPick = this.#t.pickedResultStyle !== "marker-only";
  }
  #L() {
    if (this.#e) {
      for (const [e, i] of Object.entries(this.#v))
        this.#r.addEventListener(e, i);
      for (const [e, i] of Object.entries(this.#x))
        this.#e.on([e], i);
    }
  }
  #I() {
    if (this.#e) {
      for (const [e, i] of Object.entries(this.#v))
        this.#r.removeEventListener(e, i);
      for (const [e, i] of Object.entries(this.#x))
        this.#e.un([e], i);
    }
  }
  #i(e, i) {
    this.dispatchEvent({ type: e, ...i ?? {} });
  }
  #M(e) {
    e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#w(e.center, this.#p(e)) : this.#k(Z(e.bbox), 50, this.#p(e));
  }
  #S(e) {
    if (!e || e.length === 0 || !this.#m) return;
    const i = e.every((s) => s.matching_text), o = e.reduce(
      (s, a) => i || !a.matching_text ? [Math.min(s[0], a.bbox[0]), Math.min(s[1], a.bbox[1]), Math.max(s[2], a.bbox[2]), Math.max(s[3], a.bbox[3])] : s,
      [180, 90, -180, -90]
    ), r = e.map((s) => this.#p(s)).filter((s) => s !== void 0).reduce((s, a) => s === void 0 ? a : Math.max(s, a), void 0);
    this.#k(Z(o), 50, r);
  }
  #p(e) {
    if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3])
      return;
    const i = e.id.replace(/\..*/, ""), o = this.#t.zoom ?? Et;
    return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((r, s) => {
      const a = o[i + "." + s];
      return r === void 0 ? a : a === void 0 ? r : Math.max(r, a);
    }, void 0) : void 0) ?? o[i];
  }
  get #m() {
    return !!this.#t.flyTo || this.#t.flyTo === void 0;
  }
  get #F() {
    return typeof this.#t.flyTo == "boolean" ? {} : this.#t.flyTo;
  }
  get #O() {
    return typeof this.#t.flyTo == "boolean" ? {} : this.#t.flyTo;
  }
  #w(e, i) {
    this.#e?.getView().animate({
      center: this.#f(e),
      ...i ? { zoom: i } : {},
      duration: 2e3,
      ...this.#F
    });
  }
  #k(e, i, o) {
    this.#e?.getView().fit(Je(e, O, this.#n()), {
      padding: [i, i, i, i],
      ...o ? { maxZoom: o } : {},
      duration: 2e3,
      ...this.#O
    });
  }
  #_(e) {
    if (this.#t.marker === !1 || !this.#e || !this.#s)
      return;
    if (!e) {
      this.#o && (this.#s.removeFeature(this.#o), this.#o.dispose(), this.#o = void 0);
      return;
    }
    const i = this.#f(e);
    if (!this.#o) {
      this.#o = new $(new X(i)), this.#o.set("isReverse", !0), this.#s.addFeature(this.#o);
      return;
    }
    this.#o.getGeometry().setCoordinates(i);
  }
  #u(e, i) {
    if (!this.#e || !this.#s)
      return;
    this.#s.removeFeatures([...this.#c.values()]), this.#c = /* @__PURE__ */ new Map();
    const o = () => {
      if (!i || !this.#e || this.#t.marker === !1) return;
      const r = new $(new X(this.#f(i.center)));
      r.setId(i.id), this.#c.set(i, r), this.#s?.addFeature(r);
    };
    if (i?.geometry.type === "GeometryCollection") {
      const r = i.geometry.geometries.map((s) => s.type === "Polygon" ? new be(s.coordinates) : s.type === "MultiPolygon" ? new we(s.coordinates) : null).filter((s) => !!s);
      if (r.length > 0)
        this.#s.addFeature(new $(new Ye(r).transform(O, this.#n())));
      else
        for (const s of i.geometry.geometries)
          s.type === "LineString" ? this.#s.addFeature(new $(new ke(s.coordinates).transform(O, this.#n()))) : s.type === "MultiLineString" && this.#s.addFeature(new $(new _e(s.coordinates).transform(O, this.#n())));
    } else if (i?.geometry.type.endsWith("Polygon")) {
      const r = Pt(i);
      if (r)
        for (const s of r.features) {
          const a = s.geometry.type === "Polygon" ? new be(s.geometry.coordinates) : new we(s.geometry.coordinates);
          this.#s.addFeature(
            new $({
              isMask: !!s.properties?.isMask,
              geometry: a.transform(O, this.#n())
            })
          );
        }
      this.#t.pickedResultStyle === "full-geometry-including-polygon-center-marker" && o();
    } else i?.geometry.type === "LineString" ? this.#s.addFeature(new $(new ke(i.geometry.coordinates).transform(O, this.#n()))) : i?.geometry.type === "MultiLineString" ? this.#s.addFeature(new $(new _e(i.geometry.coordinates).transform(O, this.#n()))) : i?.geometry.type.endsWith("Point") && o();
    if (this.#t.showResultMarkers !== !1)
      for (const r of e ?? []) {
        if (r.id === i?.id || r.place_type.includes("reverse"))
          continue;
        const s = new $(new X(this.#f(r.center)));
        s.setId(r.id), s.setProperties({
          fuzzy: !!r.matching_text,
          tooltip: r.place_type[0] === "reverse" ? r.place_name : r.place_name.replace(/,.*/, "")
        }), this.#s.addFeature(s), this.#c.set(r, s);
      }
  }
  #C(e) {
    this.#h?.set("isSelected", !1), this.#h = void 0, this.#t.markerOnSelected !== !1 && (this.#h = this.#c.get(e), this.#h?.setProperties({ isSelected: !0 }));
  }
  #T() {
    this.#e && (this.#s = new it({}), this.#l = new He({
      updateWhileAnimating: !0
    }), this.#l.setSource(this.#s), this.#l.setStyle(this.#E()), this.#e.addLayer(this.#l));
  }
  #P() {
    !this.#e || !this.#l || (this.#e.removeLayer(this.#l), this.#l = void 0);
  }
  #n() {
    return Xe() ?? this.#e?.getView().getProjection();
  }
  #f(e) {
    return et(e, this.#n());
  }
  #$(e) {
    return tt(e, this.#n());
  }
  #E() {
    const { fullGeometryStyle: e } = this.#t;
    if (e === !0 || e === void 0) return Ut(this.#t);
    if (!(e === !1 || e === null))
      return e;
  }
}
export {
  Ut as DEFAULT_GEOMETRY_STYLE,
  oi as GeocodingControl,
  te as MaptilerGeocodeClearIconElement,
  ie as MaptilerGeocodeFailIconElement,
  se as MaptilerGeocodeLoadingIconElement,
  ce as MaptilerGeocodeMarkerElement,
  re as MaptilerGeocodeReverseGeocodingIconElement,
  oe as MaptilerGeocodeSearchIconElement,
  l as MaptilerGeocoderElement,
  oi as OpenLayersGeocodingControl,
  Et as ZOOM_DEFAULTS
};
//# sourceMappingURL=openlayers.public.js.map
