import { css as F, LitElement as M, svg as A, html as m, unsafeCSS as he, nothing as ee } from "lit";
import { customElement as S, property as d, state as w, query as Ze } from "lit/decorators.js";
import { convert as Ne } from "geo-coordinates-parser";
import { classMap as V } from "lit/directives/class-map.js";
import { repeat as Qe } from "lit/directives/repeat.js";
import "@turf/clone";
import { styleMap as Ke } from "lit/directives/style-map.js";
import { Feature as L } from "ol";
import { Control as Ye } from "ol/control";
import He from "ol/events/Event";
import { Point as X, Polygon as we, MultiPolygon as ke, GeometryCollection as Je, LineString as _e, MultiLineString as $e } from "ol/geom";
import Xe from "ol/layer/Vector";
import { transformExtent as et, getUserProjection as tt, fromLonLat as it, toLonLat as st } from "ol/proj";
import rt from "ol/source/Vector";
import Le from "@turf/bbox";
import ot from "@turf/difference";
import at from "@turf/flatten";
import { featureCollection as Ie, polygon as nt } from "@turf/helpers";
import lt from "@turf/union";
import Fe from "ol/style/Fill";
import ct from "ol/style/Icon";
import Me from "ol/style/Stroke";
import ht from "ol/style/Style";
import dt from "ol/style/Text";
var pt = Object.getOwnPropertyDescriptor, ut = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? pt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let te = class extends M {
  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 = F`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
te = ut([
  S("maptiler-geocode-clear-icon")
], te);
var ft = Object.getOwnPropertyDescriptor, mt = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? ft(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let ie = class extends M {
  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 = F`
    svg {
      display: block;
      fill: #e15042;
    }
  `;
ie = mt([
  S("maptiler-geocode-fail-icon")
], ie);
var gt = Object.getOwnPropertyDescriptor, yt = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? gt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let se = 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>
    `;
  }
};
se.styles = F`
    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 = yt([
  S("maptiler-geocode-loading-icon")
], se);
var vt = Object.getOwnPropertyDescriptor, xt = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? vt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let re = class extends M {
  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 = F`
    svg {
      display: block;
      fill: var(--color-icon-button);
    }
  `;
re = xt([
  S("maptiler-geocode-reverse-geocoding-icon")
], re);
var bt = Object.getOwnPropertyDescriptor, wt = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? bt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let oe = class extends M {
  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 = F`
    circle {
      stroke-width: 1.875;
      fill: none;
    }

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

    svg {
      display: block;
      stroke: var(--color-icon-button);
    }
  `;
oe = wt([
  S("maptiler-geocode-search-icon")
], oe);
function kt(t, e, i) {
  const o = e[1], s = e[0], r = o - s;
  return t === o && i ? t : ((t - s) % r + r) % r + s;
}
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 _t(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 s;
          try {
            return s = await new Promise((r, a) => {
              i.signal.addEventListener("abort", () => {
                a(Error("aborted"));
              }), navigator.geolocation.getCurrentPosition(
                (u) => {
                  r([u.coords.longitude, u.coords.latitude].map((y) => y.toFixed(6)).join(","));
                },
                (u) => {
                  a(u);
                },
                o
              );
            }), s;
          } catch {
          } finally {
            o.cachedLocationExpiry && (G = {
              time: Date.now(),
              coords: s
            });
          }
          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 $t = ".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 Lt = Object.defineProperty, It = Object.getOwnPropertyDescriptor, Se = (t) => {
  throw TypeError(t);
}, $ = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? It(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = (o ? a(e, i, s) : a(s)) || s);
  return o && s && Lt(e, i, s), s;
}, Oe = (t, e, i) => e.has(t) || Se("Cannot " + i), f = (t, e, i) => (Oe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), Ft = (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) => (Oe(t, e, "access private method"), i), p, N, z, g, Te, Ce, de, ae;
const Pe = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Ee = Pe ? "@2x" : "", P = Pe ? 2 : 1;
let C, Ue, k = class extends M {
  constructor() {
    super(...arguments), Ft(this, p), this.itemStyle = "default", this.showPlaceType = "if-needed", this.missingIconsCache = /* @__PURE__ */ new Set(), this.iconsBaseUrl = "", this.index = 0;
  }
  willUpdate(t) {
    t.has("feature") && f(this, p, N) && (this.index = f(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=${Ke({
      width: `${this.spriteIcon.width / P}px`,
      height: `${this.spriteIcon.height / P}px`,
      backgroundImage: `url(${this.iconsBaseUrl}sprite${Ee}.png)`,
      backgroundPosition: `-${this.spriteIcon.x / P}px -${this.spriteIcon.y / P}px`,
      backgroundSize: `${C.width / P}px ${C.height / P}px`
    })}
                title=${f(this, p, g)}
              />
            ` : this.imageUrl ? m` <img src=${this.imageUrl} alt=${this.category} title=${f(this, p, g)} @error=${U(this, p, Ce)} />` : this.feature?.address ? m` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("road.") ? m` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("address.") ? m` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("postal_code.") ? m` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("poi.") ? m` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : f(this, p, z) ? m` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : m` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> `}

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

          <span class="line2"> ${f(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];
};
Te = function() {
  Ue ??= fetch(`${this.iconsBaseUrl}sprite${Ee}.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, Te).call(this), Ue?.then(() => {
    U(this, p, ae).call(this);
  }));
};
ae = function() {
  do {
    if (this.index--, this.category = f(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)));
};
k.styles = F`
    ${he($t)}
  `;
$([
  d({ type: Object })
], k.prototype, "feature", 2);
$([
  d({ type: String })
], k.prototype, "itemStyle", 2);
$([
  d({ type: String })
], k.prototype, "showPlaceType", 2);
$([
  d({ attribute: !1 })
], k.prototype, "missingIconsCache", 2);
$([
  d({ type: String })
], k.prototype, "iconsBaseUrl", 2);
$([
  w()
], k.prototype, "category", 2);
$([
  w()
], k.prototype, "imageUrl", 2);
$([
  w()
], k.prototype, "spriteIcon", 2);
$([
  w()
], k.prototype, "index", 2);
k = $([
  S("maptiler-geocoder-feature-item")
], k);
const Mt = "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 St = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Be = (t) => {
  throw TypeError(t);
}, c = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? Ot(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = (o ? a(e, i, s) : a(s)) || s);
  return o && s && St(e, i, s), s;
}, pe = (t, e, i) => e.has(t) || Be("Cannot " + i), b = (t, e, i) => (pe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), E = (t, e, i) => e.has(t) ? Be("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, Ge, ze, ue, x, fe, Y, me, ge, I, ye, H, je, le, Re, Ae, De, Ve, We;
let l = class extends M {
  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))
      Tt.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, { external: !0 }), 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, je).call(this, t);
  }
  willUpdate(t) {
    t.has("error") && this.error && console.error("[MapTilerGeocodingControl] Error:", this.error), t.has("enableReverse") && (this.reverseActive = this.enableReverse === "always"), ["picked"].some((e) => t.has(e)) && this.picked && (this.clearListOnPick && h(this, n, I).call(this), this.selectedItemIndex = -1), ["searchValue", "minLength"].some((e) => t.has(e)) && b(this, n, 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, x).call(this, "select", { feature: b(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, x).call(this, "pick", { feature: this.picked });
      },
      (e) => {
        e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, n, x).call(this, "pick", { feature: this.picked }));
      }
    ), ["listFeatures", "focusedDelayed"].some((e) => t.has(e)) && (b(this, n, Ge) ? (h(this, n, x).call(this, "featuresshow"), W(this, q, !0)) : b(this, q) && h(this, n, x).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, n, x).call(this, "reversetoggle", { reverse: this.reverseActive });
  }
  render() {
    return 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, Re)}
            @change=${() => this.picked = void 0}
            placeholder=${this.placeholder ?? "Search"}
            aria-label=${this.placeholder ?? "Search"}
          />

          <div class="clear-button-container ${V({ displayable: this.searchValue !== "" })}">
            ${b(this, n, ze) ? m`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : m`
                  <button type="button" @click=${h(this, n, We)} 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, Ve)} @keydown=${h(this, n, 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, n, De).call(this, e);
      }}
                          @select=${() => {
        h(this, n, Ae).call(this, t);
      }}
                          .missingIconsCache=${b(this, ne)}
                          .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();
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];
};
Ge = function() {
  return !!this.listFeatures?.length && (this.focusedDelayed || this.keepListOpen);
};
ze = 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, 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, external: t === void 0 }).then(() => {
    this.picked = void 0;
  }).catch((e) => this.error = e);
};
Y = function(t) {
  try {
    return Ne(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, n, x).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(b(this, j)), b(this, n, ue))
      return;
    const i = this.searchValue;
    W(this, j, window.setTimeout(() => {
      h(this, n, H).call(this, i, { external: e }).catch((o) => this.error = o);
    }, this.debounceSearch ?? 200));
  } else
    h(this, n, I).call(this);
};
I = function() {
  this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, n, x).call(this, "featuresclear"));
};
ye = function(t) {
  this.searchValue = t, h(this, n, x).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, external: o = !1 } = {}) {
  this.error = void 0, this.abortController?.abort();
  const s = new AbortController();
  this.abortController = s;
  try {
    const r = this.apiUrl ?? "https://api.maptiler.com/geocoding", a = h(this, n, Y).call(this, t), u = new URL(r + "/" + encodeURIComponent(a ? `${a.decimalLongitude},${a.decimalLatitude}` : t) + ".json"), y = u.searchParams;
    this.language !== void 0 && y.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? "");
    const [O] = b(this, R) ?? [void 0];
    let _ = (!a || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map(
      (v) => typeof v == "string" ? v : O === void 0 || (v[0] ?? 0) <= O && O < (v[1] ?? 1 / 0) ? v[2] : void 0
    ).filter((v) => v !== void 0);
    _ && (_ = [...new Set(_)], y.set("types", _.join(",")));
    const ve = !a || 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 && !a) {
      const v = this.proximity ?? [{ type: "server-geolocation" }], be = await _t(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."), a ? (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 qe = u.searchParams.get("types") === "" && u.searchParams.get("excludeTypes") !== "true", D = u.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, x).call(this, "featureslisted", { features: this.listFeatures, external: o }), this.listFeatures[this.selectedItemIndex]?.id !== b(this, n, K)?.id && (this.selectedItemIndex = -1));
      return;
    }
    h(this, n, x).call(this, "request", { urlObj: u }), this.lastSearchUrl = D;
    let B;
    if (qe)
      B = { type: "FeatureCollection", features: [] };
    else {
      const v = await fetch(D, {
        signal: s.signal,
        ...this.fetchParameters
      });
      if (!v.ok)
        throw new Error(await v.text());
      B = await v.json();
    }
    h(this, n, x).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)), a && this.listFeatures.unshift({
      type: "Feature",
      properties: {},
      /* eslint-disable @typescript-eslint/restrict-template-expressions */
      id: `reverse_${a.decimalLongitude}_${a.decimalLatitude}`,
      text: `${a.decimalLatitude}, ${a.decimalLongitude}`,
      place_name: a.toCoordinateFormat("DMS"),
      /* eslint-enable @typescript-eslint/restrict-template-expressions */
      place_type: ["reverse"],
      place_type_name: ["reverse"],
      center: [a.decimalLongitude, a.decimalLatitude],
      bbox: [a.decimalLongitude, a.decimalLatitude, a.decimalLongitude, a.decimalLatitude],
      geometry: {
        type: "Point",
        coordinates: [a.decimalLongitude, a.decimalLatitude]
      }
    }), h(this, n, x).call(this, "featureslisted", { features: this.listFeatures, external: o }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== b(this, n, K)?.id && (this.selectedItemIndex = -1), a && this.input.focus());
  } catch (r) {
    if (r && typeof r == "object" && "name" in r && r.name === "AbortError")
      return;
    throw r;
  } finally {
    s === this.abortController && (this.abortController = void 0);
  }
};
je = 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)}, ${kt(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));
};
Re = function(t) {
  h(this, n, ge).call(this, t.target.value);
};
Ae = function(t) {
  (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name);
};
De = function(t) {
  this.selectedItemIndex = t;
};
Ve = function() {
  (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1);
};
We = function() {
  this.searchValue = "", h(this, n, x).call(this, "queryclear"), this.picked = void 0, this.input.focus();
};
l.styles = F`
    ${he(Mt)}
  `;
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([
  Ze("input")
], l.prototype, "input", 2);
c([
  w()
], l.prototype, "searchValue", 2);
c([
  w()
], l.prototype, "listFeatures", 2);
c([
  w()
], l.prototype, "selectedItemIndex", 2);
c([
  w()
], l.prototype, "picked", 2);
c([
  w()
], l.prototype, "cachedFeatures", 2);
c([
  w()
], l.prototype, "lastSearchUrl", 2);
c([
  w()
], l.prototype, "error", 2);
c([
  w()
], l.prototype, "abortController", 2);
c([
  w()
], l.prototype, "focused", 2);
c([
  w()
], l.prototype, "focusedDelayed", 2);
l = c([
  S("maptiler-geocoder")
], l);
const Tt = [
  "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"
], Ct = "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 Pt = Object.getOwnPropertyDescriptor, Et = (t, e, i, o) => {
  for (var s = o > 1 ? void 0 : o ? Pt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
    (a = t[r]) && (s = a(s) || s);
  return s;
};
let ce = class extends M {
  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 = F`
    ${he(Ct)}
  `;
ce = Et([
  S("maptiler-geocode-marker")
], ce);
function Ut(t) {
  const e = ot(
    Ie([
      nt([
        [
          [180, 90],
          [-180, 90],
          [-180, -90],
          [180, -90],
          [180, 90]
        ]
      ]),
      t
    ])
  );
  if (!e)
    return;
  e.properties = { isMask: !0 };
  const i = Z(Le(t)), o = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, r = i[2] > 180, a = at(t);
  if (a.features.length > 1 && (s || r))
    for (const u of a.features) {
      const y = Z(Le(u));
      if (r && y[0] < -180 + o)
        for (const O of u.geometry.coordinates)
          for (const _ of O)
            _[0] += 360 - o;
      if (s && y[2] > 180 - o)
        for (const O of u.geometry.coordinates)
          for (const _ of O)
            _[0] -= 360 - o;
    }
  return Ie([a.features.length < 2 ? t : lt(a) ?? 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
}, Gt = (t) => (e) => {
  const i = t.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0-rc.6/icons/", o = e.getProperties(), s = e.getGeometry()?.getType(), r = o.isMask ? 0 : s === "LineString" || s === "MultiLineString" ? 3 : 2;
  return new ht({
    stroke: o.isMask ? void 0 : new Me({
      color: "#3170fe",
      lineDash: [r, r],
      width: r,
      lineCap: "butt"
    }),
    fill: o.isMask ? new Fe({
      color: "#00000020"
    }) : void 0,
    image: new ct({
      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 dt({
      backgroundFill: new Fe({ color: "white" }),
      text: o.tooltip,
      offsetY: -40,
      backgroundStroke: new Me({
        color: "white",
        lineJoin: "round",
        width: 3
      }),
      padding: [2, 0, 0, 2]
    }) : void 0
  });
}, T = "EPSG:4326";
class li extends Ye {
  #e;
  #t;
  #r;
  constructor(e = {}) {
    const i = document.createElement("div");
    super({
      element: i,
      ...e
    }), this.#e = 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.#t && this.#t !== e && (this.#I(), this.#P(), this.#t = void 0), e && (this.#t = e, this.#L(), this.#C());
  }
  getOptions() {
    return { ...this.#e };
  }
  setOptions(e) {
    Object.assign(this.#e, 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.#e.flyToSelected && this.#w(i.center, this.#p(i)), this.#a && i && this.#T(i), this.#i("select", e.detail);
    },
    pick: (e) => {
      const i = e.detail.feature;
      i && i.id !== this.#g && this.#m && (this.#F(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.#M(e), 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.#t?.getView().getZoom(), i = this.#t?.getView().getCenter();
      this.#r.handleMapChange(e && i ? [e, ...this.#$(i)] : void 0);
    },
    click: (e) => {
      this.#r.handleMapClick(this.#$(e.coordinate)), this.#t?.forEachFeatureAtPixel(e.pixel, (i) => {
        const o = i.getId(), s = this.#a?.find((r) => r.id === o);
        if (!(!o || !s))
          return e.stopPropagation(), this.#i("markerclick", { feature: s, marker: i }), !0;
      });
    },
    pointermove: (e) => {
      if (!this.#t) return;
      const i = this.#t.forEachFeatureAtPixel(e.pixel, (s) => s.getId() ? s : void 0);
      this.#t.getTargetElement().style.cursor = i ? "pointer" : this.#y ? "crosshair" : "";
      const o = i?.getId();
      if (this.#d !== o) {
        if (this.#d) {
          const s = this.#a?.find((a) => a.id === this.#d), r = this.#c.get(s);
          r?.set("isMouseOver", !1), s && r && this.#i("markermouseleave", { feature: s, marker: r });
        }
        if (i) {
          const s = this.#a?.find((r) => r.id === o);
          this.#i("markermouseenter", { feature: s, marker: i }), i.set("isMouseOver", !0);
        }
        this.#d = o;
      }
    }
  };
  #b() {
    this.#r.setOptions(this.#e), this.#r.fetchFullGeometryOnPick = this.#e.pickedResultStyle !== "marker-only";
  }
  #L() {
    if (this.#t) {
      for (const [e, i] of Object.entries(this.#v))
        this.#r.addEventListener(e, i);
      for (const [e, i] of Object.entries(this.#x))
        this.#t.on([e], i);
    }
  }
  #I() {
    if (this.#t) {
      for (const [e, i] of Object.entries(this.#v))
        this.#r.removeEventListener(e, i);
      for (const [e, i] of Object.entries(this.#x))
        this.#t.un([e], i);
    }
  }
  #i(e, i) {
    this.dispatchEvent(Object.assign(new He(e), i));
  }
  #F(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));
  }
  #M({ detail: { features: e, external: i } }) {
    if (!e || e.length === 0 || !this.#m || this.#e.flyToFeatures === !1 || this.#e.flyToFeatures === "never" || !i && (this.#e.flyToFeatures === void 0 || this.#e.flyToFeatures === "external"))
      return;
    const o = e.every((a) => a.matching_text), s = e.reduce(
      (a, u) => o || !u.matching_text ? [Math.min(a[0], u.bbox[0]), Math.min(a[1], u.bbox[1]), Math.max(a[2], u.bbox[2]), Math.max(a[3], u.bbox[3])] : a,
      [180, 90, -180, -90]
    ), r = e.map((a) => this.#p(a)).filter((a) => a !== void 0).reduce((a, u) => a === void 0 ? u : Math.max(a, u), void 0);
    this.#k(Z(s), 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.#e.zoom ?? Bt;
    return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, r) => {
      const a = o[i + "." + r];
      return s === void 0 ? a : a === void 0 ? s : Math.max(s, a);
    }, void 0) : void 0) ?? o[i];
  }
  get #m() {
    return !!this.#e.flyTo || this.#e.flyTo === void 0;
  }
  get #S() {
    return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
  }
  get #O() {
    return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
  }
  #w(e, i) {
    this.#t?.getView().animate({
      center: this.#f(e),
      ...i ? { zoom: i } : {},
      duration: 2e3,
      ...this.#S
    });
  }
  #k(e, i, o) {
    this.#t?.getView().fit(et(e, T, this.#n()), {
      padding: [i, i, i, i],
      ...o ? { maxZoom: o } : {},
      duration: 2e3,
      ...this.#O
    });
  }
  #_(e) {
    if (this.#e.marker === !1 || !this.#t || !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 L(new X(i)), this.#o.set("isReverse", !0), this.#s.addFeature(this.#o);
      return;
    }
    this.#o.getGeometry().setCoordinates(i);
  }
  #u(e, i) {
    if (!this.#t || !this.#s)
      return;
    this.#s.removeFeatures([...this.#c.values()]), this.#c = /* @__PURE__ */ new Map();
    const o = () => {
      if (!i || !this.#t || this.#e.marker === !1) return;
      const s = new L(new X(this.#f(i.center)));
      s.setId(i.id), this.#c.set(i, s), this.#s?.addFeature(s);
    };
    if (i?.geometry.type === "GeometryCollection") {
      const s = i.geometry.geometries.map((r) => r.type === "Polygon" ? new we(r.coordinates) : r.type === "MultiPolygon" ? new ke(r.coordinates) : null).filter((r) => !!r);
      if (s.length > 0)
        this.#s.addFeature(new L(new Je(s).transform(T, this.#n())));
      else
        for (const r of i.geometry.geometries)
          r.type === "LineString" ? this.#s.addFeature(new L(new _e(r.coordinates).transform(T, this.#n()))) : r.type === "MultiLineString" && this.#s.addFeature(new L(new $e(r.coordinates).transform(T, this.#n())));
    } else if (i?.geometry.type.endsWith("Polygon")) {
      const s = Ut(i);
      if (s)
        for (const r of s.features) {
          const a = r.geometry.type === "Polygon" ? new we(r.geometry.coordinates) : new ke(r.geometry.coordinates);
          this.#s.addFeature(
            new L({
              isMask: !!r.properties?.isMask,
              geometry: a.transform(T, this.#n())
            })
          );
        }
      this.#e.pickedResultStyle === "full-geometry-including-polygon-center-marker" && o();
    } else i?.geometry.type === "LineString" ? this.#s.addFeature(new L(new _e(i.geometry.coordinates).transform(T, this.#n()))) : i?.geometry.type === "MultiLineString" ? this.#s.addFeature(new L(new $e(i.geometry.coordinates).transform(T, this.#n()))) : i?.geometry.type.endsWith("Point") && o();
    if (this.#e.showResultMarkers !== !1)
      for (const s of e ?? []) {
        if (s.id === i?.id || s.place_type.includes("reverse"))
          continue;
        const r = new L(new X(this.#f(s.center)));
        r.setId(s.id), r.setProperties({
          fuzzy: !!s.matching_text,
          tooltip: s.place_type[0] === "reverse" ? s.place_name : s.place_name.replace(/,.*/, "")
        }), this.#s.addFeature(r), this.#c.set(s, r);
      }
  }
  #T(e) {
    this.#h?.set("isSelected", !1), this.#h = void 0, this.#e.markerOnSelected !== !1 && (this.#h = this.#c.get(e), this.#h?.setProperties({ isSelected: !0 }));
  }
  #C() {
    this.#t && (this.#s = new rt({}), this.#l = new Xe({
      updateWhileAnimating: !0
    }), this.#l.setSource(this.#s), this.#l.setStyle(this.#E()), this.#t.addLayer(this.#l));
  }
  #P() {
    !this.#t || !this.#l || (this.#t.removeLayer(this.#l), this.#l = void 0);
  }
  #n() {
    return tt() ?? this.#t?.getView().getProjection();
  }
  #f(e) {
    return it(e, this.#n());
  }
  #$(e) {
    return st(e, this.#n());
  }
  #E() {
    const { fullGeometryStyle: e } = this.#e;
    if (e === !0 || e === void 0) return Gt(this.#e);
    if (!(e === !1 || e === null))
      return e;
  }
}
export {
  Gt as DEFAULT_GEOMETRY_STYLE,
  li as GeocodingControl,
  te as MaptilerGeocodeClearIconElement,
  ie as MaptilerGeocodeFailIconElement,
  se as MaptilerGeocodeLoadingIconElement,
  ce as MaptilerGeocodeMarkerElement,
  re as MaptilerGeocodeReverseGeocodingIconElement,
  oe as MaptilerGeocodeSearchIconElement,
  l as MaptilerGeocoderElement,
  li as OpenLayersGeocodingControl,
  Bt as ZOOM_DEFAULTS
};
//# sourceMappingURL=openlayers.public.js.map
