import { forwardRef as zt, useRef as Ke, useEffect as Ne, useImperativeHandle as Ct, createElement as Bt } from "react";
function C() {
}
function Lt(t, e) {
  for (const n in e)
    t[n] = e[n];
  return t;
}
function ct(t) {
  return t();
}
function Qe() {
  return /* @__PURE__ */ Object.create(null);
}
function Y(t) {
  t.forEach(ct);
}
function it(t) {
  return typeof t == "function";
}
function ye(t, e) {
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
}
function St(t) {
  return Object.keys(t).length === 0;
}
function At(t, e, n, r) {
  if (t) {
    const i = ut(t, e, n, r);
    return t[0](i);
  }
}
function ut(t, e, n, r) {
  return t[1] && r ? Lt(n.ctx.slice(), t[1](r(e))) : n.ctx;
}
function Pt(t, e, n, r) {
  if (t[2] && r) {
    const i = t[2](r(n));
    if (e.dirty === void 0)
      return i;
    if (typeof i == "object") {
      const u = [], c = Math.max(e.dirty.length, i.length);
      for (let d = 0; d < c; d += 1)
        u[d] = e.dirty[d] | i[d];
      return u;
    }
    return e.dirty | i;
  }
  return e.dirty;
}
function Nt(t, e, n, r, i, u) {
  if (i) {
    const c = ut(e, n, r, u);
    t.p(c, i);
  }
}
function xt(t) {
  if (t.ctx.length > 32) {
    const e = [], n = t.ctx.length / 32;
    for (let r = 0; r < n; r++)
      e[r] = -1;
    return e;
  }
  return -1;
}
function qe(t) {
  return t ?? "";
}
function b(t, e) {
  t.appendChild(e);
}
function O(t, e, n) {
  t.insertBefore(e, n || null);
}
function I(t) {
  t.parentNode && t.parentNode.removeChild(t);
}
function jt(t, e) {
  for (let n = 0; n < t.length; n += 1)
    t[n] && t[n].d(e);
}
function z(t) {
  return document.createElement(t);
}
function fe(t) {
  return document.createElementNS("http://www.w3.org/2000/svg", t);
}
function ne(t) {
  return document.createTextNode(t);
}
function q() {
  return ne(" ");
}
function j(t, e, n, r) {
  return t.addEventListener(e, n, r), () => t.removeEventListener(e, n, r);
}
function It(t) {
  return function(e) {
    return e.preventDefault(), t.call(this, e);
  };
}
function s(t, e, n) {
  n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n);
}
function Gt(t) {
  return Array.from(t.childNodes);
}
function he(t, e) {
  e = "" + e, t.data !== e && (t.data = e);
}
function Ue(t, e) {
  t.value = e ?? "";
}
function X(t, e, n) {
  t.classList[n ? "add" : "remove"](e);
}
function Ot(t, e, { bubbles: n = !1, cancelable: r = !1 } = {}) {
  const i = document.createEvent("CustomEvent");
  return i.initCustomEvent(t, n, r, e), i;
}
let me;
function de(t) {
  me = t;
}
function ot() {
  if (!me)
    throw new Error("Function called outside component initialization");
  return me;
}
function Dt(t) {
  ot().$$.on_destroy.push(t);
}
function Ft() {
  const t = ot();
  return (e, n, { cancelable: r = !1 } = {}) => {
    const i = t.$$.callbacks[e];
    if (i) {
      const u = Ot(e, n, { cancelable: r });
      return i.slice().forEach((c) => {
        c.call(t, u);
      }), !u.defaultPrevented;
    }
    return !0;
  };
}
const ue = [], je = [];
let oe = [];
const We = [], Vt = /* @__PURE__ */ Promise.resolve();
let Ie = !1;
function Ht() {
  Ie || (Ie = !0, Vt.then(ft));
}
function Ge(t) {
  oe.push(t);
}
const xe = /* @__PURE__ */ new Set();
let ie = 0;
function ft() {
  if (ie !== 0)
    return;
  const t = me;
  do {
    try {
      for (; ie < ue.length; ) {
        const e = ue[ie];
        ie++, de(e), Kt(e.$$);
      }
    } catch (e) {
      throw ue.length = 0, ie = 0, e;
    }
    for (de(null), ue.length = 0, ie = 0; je.length; )
      je.pop()();
    for (let e = 0; e < oe.length; e += 1) {
      const n = oe[e];
      xe.has(n) || (xe.add(n), n());
    }
    oe.length = 0;
  } while (ue.length);
  for (; We.length; )
    We.pop()();
  Ie = !1, xe.clear(), de(t);
}
function Kt(t) {
  if (t.fragment !== null) {
    t.update(), Y(t.before_update);
    const e = t.dirty;
    t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(Ge);
  }
}
function Qt(t) {
  const e = [], n = [];
  oe.forEach((r) => t.indexOf(r) === -1 ? e.push(r) : n.push(r)), n.forEach((r) => r()), oe = e;
}
const Ee = /* @__PURE__ */ new Set();
let te;
function Ze() {
  te = {
    r: 0,
    c: [],
    p: te
    // parent group
  };
}
function Je() {
  te.r || Y(te.c), te = te.p;
}
function G(t, e) {
  t && t.i && (Ee.delete(t), t.i(e));
}
function Q(t, e, n, r) {
  if (t && t.o) {
    if (Ee.has(t))
      return;
    Ee.add(t), te.c.push(() => {
      Ee.delete(t), r && (n && t.d(1), r());
    }), t.o(e);
  } else
    r && r();
}
function ze(t) {
  t && t.c();
}
function _e(t, e, n, r) {
  const { fragment: i, after_update: u } = t.$$;
  i && i.m(e, n), r || Ge(() => {
    const c = t.$$.on_mount.map(ct).filter(it);
    t.$$.on_destroy ? t.$$.on_destroy.push(...c) : Y(c), t.$$.on_mount = [];
  }), u.forEach(Ge);
}
function ge(t, e) {
  const n = t.$$;
  n.fragment !== null && (Qt(n.after_update), Y(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []);
}
function qt(t, e) {
  t.$$.dirty[0] === -1 && (ue.push(t), Ht(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31;
}
function be(t, e, n, r, i, u, c, d = [-1]) {
  const o = me;
  de(t);
  const a = t.$$ = {
    fragment: null,
    ctx: [],
    // state
    props: u,
    update: C,
    not_equal: i,
    bound: Qe(),
    // lifecycle
    on_mount: [],
    on_destroy: [],
    on_disconnect: [],
    before_update: [],
    after_update: [],
    context: new Map(e.context || (o ? o.$$.context : [])),
    // everything else
    callbacks: Qe(),
    dirty: d,
    skip_bound: !1,
    root: e.target || o.$$.root
  };
  c && c(a.root);
  let R = !1;
  if (a.ctx = n ? n(t, e.props || {}, (E, B, ...L) => {
    const N = L.length ? L[0] : B;
    return a.ctx && i(a.ctx[E], a.ctx[E] = N) && (!a.skip_bound && a.bound[E] && a.bound[E](N), R && qt(t, E)), B;
  }) : [], a.update(), R = !0, Y(a.before_update), a.fragment = r ? r(a.ctx) : !1, e.target) {
    if (e.hydrate) {
      const E = Gt(e.target);
      a.fragment && a.fragment.l(E), E.forEach(I);
    } else
      a.fragment && a.fragment.c();
    e.intro && G(t.$$.fragment), _e(t, e.target, e.anchor, e.customElement), ft();
  }
  de(o);
}
class we {
  $destroy() {
    ge(this, 1), this.$destroy = C;
  }
  $on(e, n) {
    if (!it(n))
      return C;
    const r = this.$$.callbacks[e] || (this.$$.callbacks[e] = []);
    return r.push(n), () => {
      const i = r.indexOf(n);
      i !== -1 && r.splice(i, 1);
    };
  }
  $set(e) {
    this.$$set && !St(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
  }
}
function Ut(t) {
  let e, n;
  return {
    c() {
      e = fe("svg"), n = fe("path"), s(n, "d", "M3.8 2.5c-.6 0-1.3.7-1.3 1.3 0 .3.2.7.5.8L7.2 9 3 13.2c-.3.3-.5.7-.5 1 0 .6.7 1.3 1.3 1.3.3 0 .7-.2 1-.5L9 10.8l4.2 4.2c.2.3.7.3 1 .3.6 0 1.3-.7 1.3-1.3 0-.3-.2-.7-.3-1l-4.4-4L15 4.6c.3-.2.5-.5.5-.8 0-.7-.7-1.3-1.3-1.3-.3 0-.7.2-1 .3L9 7.1 4.8 2.8c-.3-.1-.7-.3-1-.3z"), s(e, "viewBox", "0 0 18 18"), s(e, "width", "16"), s(e, "height", "16"), s(e, "class", "svelte-en2qvf");
    },
    m(r, i) {
      O(r, e, i), b(e, n);
    },
    p: C,
    i: C,
    o: C,
    d(r) {
      r && I(e);
    }
  };
}
class Wt extends we {
  constructor(e) {
    super(), be(this, e, null, Ut, ye, {});
  }
}
function Zt(t) {
  let e;
  return {
    c() {
      e = z("div"), e.innerHTML = '<svg viewBox="0 0 18 18" width="24" height="24" class="svelte-7cmwmc"><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><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"></path></svg>', s(e, "class", "svelte-7cmwmc");
    },
    m(n, r) {
      O(n, e, r);
    },
    p: C,
    i: C,
    o: C,
    d(n) {
      n && I(e);
    }
  };
}
class Jt extends we {
  constructor(e) {
    super(), be(this, e, null, Zt, ye, {});
  }
}
function Xt(t) {
  let e, n;
  return {
    c() {
      e = fe("svg"), n = fe("path"), s(n, "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"), s(e, "viewBox", "0 0 60.006 21.412"), s(e, "width", "14"), s(e, "height", "20"), s(e, "class", "svelte-en2qvf");
    },
    m(r, i) {
      O(r, e, i), b(e, n);
    },
    p: C,
    i: C,
    o: C,
    d(r) {
      r && I(e);
    }
  };
}
class Yt extends we {
  constructor(e) {
    super(), be(this, e, null, Xt, ye, {});
  }
}
function $t(t) {
  let e, n;
  return {
    c() {
      e = fe("svg"), n = fe("path"), s(n, "d", "M7.4 2.5c-2.7 0-4.9 2.2-4.9 4.9s2.2 4.9 4.9 4.9c1 0 1.8-.2 2.5-.8l3.7 3.7c.2.2.4.3.8.3.7 0 1.1-.4 1.1-1.1 0-.3-.1-.5-.3-.8L11.4 10c.4-.8.8-1.6.8-2.5.1-2.8-2.1-5-4.8-5zm0 1.6c1.8 0 3.2 1.4 3.2 3.2s-1.4 3.2-3.2 3.2-3.3-1.3-3.3-3.1 1.4-3.3 3.3-3.3z"), s(e, "viewBox", "0 0 18 18"), s(e, "xml:space", "preserve"), s(e, "width", "20"), s(e, "class", "svelte-en2qvf");
    },
    m(r, i) {
      O(r, e, i), b(e, n);
    },
    p: C,
    i: C,
    o: C,
    d(r) {
      r && I(e);
    }
  };
}
class en extends we {
  constructor(e) {
    super(), be(this, e, null, $t, ye, {});
  }
}
function Xe(t, e, n) {
  const r = t.slice();
  return r[69] = e[n], r[71] = n, r;
}
function Ye(t) {
  let e, n;
  return e = new Jt({}), {
    c() {
      ze(e.$$.fragment);
    },
    m(r, i) {
      _e(e, r, i), n = !0;
    },
    i(r) {
      n || (G(e.$$.fragment, r), n = !0);
    },
    o(r) {
      Q(e.$$.fragment, r), n = !1;
    },
    d(r) {
      ge(e, r);
    }
  };
}
function $e(t) {
  let e, n, r, i, u;
  return n = new Yt({}), {
    c() {
      e = z("button"), ze(n.$$.fragment), s(e, "type", "button"), s(
        e,
        "title",
        /*reverseButtonTitle*/
        t[9]
      ), s(e, "class", "svelte-p509gh"), X(
        e,
        "active",
        /*reverseActive*/
        t[0]
      );
    },
    m(c, d) {
      O(c, e, d), _e(n, e, null), r = !0, i || (u = j(
        e,
        "click",
        /*click_handler_2*/
        t[56]
      ), i = !0);
    },
    p(c, d) {
      (!r || d[0] & /*reverseButtonTitle*/
      512) && s(
        e,
        "title",
        /*reverseButtonTitle*/
        c[9]
      ), (!r || d[0] & /*reverseActive*/
      1) && X(
        e,
        "active",
        /*reverseActive*/
        c[0]
      );
    },
    i(c) {
      r || (G(n.$$.fragment, c), r = !0);
    },
    o(c) {
      Q(n.$$.fragment, c), r = !1;
    },
    d(c) {
      c && I(e), ge(n), i = !1, u();
    }
  };
}
function tn(t) {
  let e, n, r, i = (
    /*listFeatures*/
    t[12]
  ), u = [];
  for (let c = 0; c < i.length; c += 1)
    u[c] = tt(Xe(t, i, c));
  return {
    c() {
      e = z("ul");
      for (let c = 0; c < u.length; c += 1)
        u[c].c();
      s(e, "class", "svelte-p509gh");
    },
    m(c, d) {
      O(c, e, d);
      for (let o = 0; o < u.length; o += 1)
        u[o] && u[o].m(e, null);
      n || (r = [
        j(
          e,
          "mouseleave",
          /*mouseleave_handler*/
          t[59]
        ),
        j(
          e,
          "blur",
          /*blur_handler_1*/
          t[60]
        )
      ], n = !0);
    },
    p(c, d) {
      if (d[0] & /*selectedItemIndex, pick, listFeatures, showPlaceType*/
      2110464) {
        i = /*listFeatures*/
        c[12];
        let o;
        for (o = 0; o < i.length; o += 1) {
          const a = Xe(c, i, o);
          u[o] ? u[o].p(a, d) : (u[o] = tt(a), u[o].c(), u[o].m(e, null));
        }
        for (; o < u.length; o += 1)
          u[o].d(1);
        u.length = i.length;
      }
    },
    d(c) {
      c && I(e), jt(u, c), n = !1, Y(r);
    }
  };
}
function nn(t) {
  let e, n;
  return {
    c() {
      e = z("div"), n = ne(
        /*noResultsMessage*/
        t[7]
      ), s(e, "class", "no-results svelte-p509gh");
    },
    m(r, i) {
      O(r, e, i), b(e, n);
    },
    p(r, i) {
      i[0] & /*noResultsMessage*/
      128 && he(
        n,
        /*noResultsMessage*/
        r[7]
      );
    },
    d(r) {
      r && I(e);
    }
  };
}
function rn(t) {
  let e = "", n;
  return {
    c() {
      n = ne(e);
    },
    m(r, i) {
      O(r, n, i);
    },
    p: C,
    d(r) {
      r && I(n);
    }
  };
}
function ln(t) {
  let e, n;
  return {
    c() {
      e = z("div"), n = ne(
        /*errorMessage*/
        t[6]
      ), s(e, "class", "error svelte-p509gh");
    },
    m(r, i) {
      O(r, e, i), b(e, n);
    },
    p(r, i) {
      i[0] & /*errorMessage*/
      64 && he(
        n,
        /*errorMessage*/
        r[6]
      );
    },
    d(r) {
      r && I(e);
    }
  };
}
function et(t) {
  var i, u;
  let e, n = (
    /*feature*/
    (((u = (i = t[69].properties) == null ? void 0 : i.place_type_name) == null ? void 0 : u[0]) ?? /*feature*/
    t[69].place_type[0]) + ""
  ), r;
  return {
    c() {
      e = z("span"), r = ne(n), s(e, "class", "line2 svelte-p509gh");
    },
    m(c, d) {
      O(c, e, d), b(e, r);
    },
    p(c, d) {
      var o, a;
      d[0] & /*listFeatures*/
      4096 && n !== (n = /*feature*/
      (((a = (o = c[69].properties) == null ? void 0 : o.place_type_name) == null ? void 0 : a[0]) ?? /*feature*/
      c[69].place_type[0]) + "") && he(r, n);
    },
    d(c) {
      c && I(e);
    }
  };
}
function tt(t) {
  let e, n, r, i, u = (
    /*feature*/
    t[69].place_name.replace(/,.*/, "") + ""
  ), c, d, o, a = (
    /*feature*/
    t[69].place_name.replace(/[^,]*,?\s*/, "") + ""
  ), R, E, B, L, N, D, h = (
    /*showPlaceType*/
    t[10] && et(t)
  );
  function F() {
    return (
      /*mouseenter_handler*/
      t[57](
        /*i*/
        t[71]
      )
    );
  }
  function U() {
    return (
      /*focus_handler_1*/
      t[58](
        /*feature*/
        t[69]
      )
    );
  }
  return {
    c() {
      e = z("li"), n = z("span"), r = z("span"), i = z("span"), c = ne(u), d = q(), o = z("span"), R = ne(a), E = q(), h && h.c(), B = q(), s(i, "class", "primary svelte-p509gh"), s(o, "class", "secondary svelte-p509gh"), s(r, "class", "line1 svelte-p509gh"), s(n, "class", "texts svelte-p509gh"), s(e, "tabindex", "0"), s(e, "data-selected", L = /*selectedItemIndex*/
      t[13] === /*i*/
      t[71]), s(e, "class", "svelte-p509gh"), X(
        e,
        "selected",
        /*selectedItemIndex*/
        t[13] === /*i*/
        t[71]
      );
    },
    m(_, m) {
      O(_, e, m), b(e, n), b(n, r), b(r, i), b(i, c), b(r, d), b(r, o), b(o, R), b(n, E), h && h.m(n, null), b(e, B), N || (D = [
        j(e, "mouseenter", F),
        j(e, "focus", U)
      ], N = !0);
    },
    p(_, m) {
      t = _, m[0] & /*listFeatures*/
      4096 && u !== (u = /*feature*/
      t[69].place_name.replace(/,.*/, "") + "") && he(c, u), m[0] & /*listFeatures*/
      4096 && a !== (a = /*feature*/
      t[69].place_name.replace(/[^,]*,?\s*/, "") + "") && he(R, a), /*showPlaceType*/
      t[10] ? h ? h.p(t, m) : (h = et(t), h.c(), h.m(n, null)) : h && (h.d(1), h = null), m[0] & /*selectedItemIndex*/
      8192 && L !== (L = /*selectedItemIndex*/
      t[13] === /*i*/
      t[71]) && s(e, "data-selected", L), m[0] & /*selectedItemIndex*/
      8192 && X(
        e,
        "selected",
        /*selectedItemIndex*/
        t[13] === /*i*/
        t[71]
      );
    },
    d(_) {
      _ && I(e), h && h.d(), N = !1, Y(D);
    }
  };
}
function cn(t) {
  let e, n, r, i, u, c, d, o, a, R, E, B, L, N, D, h, F, U;
  i = new en({}), R = new Wt({});
  let _ = (
    /*abortController*/
    t[17] && Ye()
  ), m = (
    /*enableReverse*/
    t[5] === !0 && $e(t)
  );
  const g = (
    /*#slots*/
    t[48].default
  ), S = At(
    g,
    t,
    /*$$scope*/
    t[47],
    null
  );
  function se(f, M) {
    var p, re;
    if (
      /*error*/
      f[16]
    )
      return ln;
    if (!/*focusedDelayed*/
    f[14])
      return rn;
    if (
      /*listFeatures*/
      ((p = f[12]) == null ? void 0 : p.length) === 0
    )
      return nn;
    if (
      /*focusedDelayed*/
      f[14] && /*listFeatures*/
      ((re = f[12]) != null && re.length)
    )
      return tn;
  }
  let K = se(t), k = K && K(t);
  return {
    c() {
      e = z("form"), n = z("div"), r = z("button"), ze(i.$$.fragment), u = q(), c = z("input"), d = q(), o = z("div"), a = z("button"), ze(R.$$.fragment), E = q(), _ && _.c(), B = q(), m && m.c(), L = q(), S && S.c(), N = q(), k && k.c(), s(r, "type", "button"), s(r, "class", "svelte-p509gh"), s(
        c,
        "placeholder",
        /*placeholder*/
        t[8]
      ), s(
        c,
        "aria-label",
        /*placeholder*/
        t[8]
      ), s(c, "class", "svelte-p509gh"), s(a, "type", "button"), s(
        a,
        "title",
        /*clearButtonTitle*/
        t[3]
      ), s(a, "class", "svelte-p509gh"), s(o, "class", "clear-button-container svelte-p509gh"), X(
        o,
        "displayable",
        /*searchValue*/
        t[1] !== ""
      ), s(n, "class", "input-group svelte-p509gh"), s(e, "tabindex", "0"), s(e, "class", D = qe(
        /*className*/
        t[2]
      ) + " svelte-p509gh"), X(
        e,
        "can-collapse",
        /*collapsed*/
        t[4] && /*searchValue*/
        t[1] === ""
      );
    },
    m(f, M) {
      O(f, e, M), b(e, n), b(n, r), _e(i, r, null), b(n, u), b(n, c), t[50](c), Ue(
        c,
        /*searchValue*/
        t[1]
      ), b(n, d), b(n, o), b(o, a), _e(R, a, null), b(o, E), _ && _.m(o, null), b(n, B), m && m.m(n, null), b(n, L), S && S.m(n, null), b(e, N), k && k.m(e, null), h = !0, F || (U = [
        j(
          r,
          "click",
          /*click_handler*/
          t[49]
        ),
        j(
          c,
          "input",
          /*input_1_input_handler*/
          t[51]
        ),
        j(
          c,
          "focus",
          /*focus_handler*/
          t[52]
        ),
        j(
          c,
          "blur",
          /*blur_handler*/
          t[53]
        ),
        j(
          c,
          "keydown",
          /*handleKeyDown*/
          t[19]
        ),
        j(
          c,
          "input",
          /*input_handler*/
          t[54]
        ),
        j(
          a,
          "click",
          /*click_handler_1*/
          t[55]
        ),
        j(e, "submit", It(
          /*handleOnSubmit*/
          t[18]
        ))
      ], F = !0);
    },
    p(f, M) {
      (!h || M[0] & /*placeholder*/
      256) && s(
        c,
        "placeholder",
        /*placeholder*/
        f[8]
      ), (!h || M[0] & /*placeholder*/
      256) && s(
        c,
        "aria-label",
        /*placeholder*/
        f[8]
      ), M[0] & /*searchValue*/
      2 && c.value !== /*searchValue*/
      f[1] && Ue(
        c,
        /*searchValue*/
        f[1]
      ), (!h || M[0] & /*clearButtonTitle*/
      8) && s(
        a,
        "title",
        /*clearButtonTitle*/
        f[3]
      ), /*abortController*/
      f[17] ? _ ? M[0] & /*abortController*/
      131072 && G(_, 1) : (_ = Ye(), _.c(), G(_, 1), _.m(o, null)) : _ && (Ze(), Q(_, 1, 1, () => {
        _ = null;
      }), Je()), (!h || M[0] & /*searchValue*/
      2) && X(
        o,
        "displayable",
        /*searchValue*/
        f[1] !== ""
      ), /*enableReverse*/
      f[5] === !0 ? m ? (m.p(f, M), M[0] & /*enableReverse*/
      32 && G(m, 1)) : (m = $e(f), m.c(), G(m, 1), m.m(n, L)) : m && (Ze(), Q(m, 1, 1, () => {
        m = null;
      }), Je()), S && S.p && (!h || M[1] & /*$$scope*/
      65536) && Nt(
        S,
        g,
        f,
        /*$$scope*/
        f[47],
        h ? Pt(
          g,
          /*$$scope*/
          f[47],
          M,
          null
        ) : xt(
          /*$$scope*/
          f[47]
        ),
        null
      ), K === (K = se(f)) && k ? k.p(f, M) : (k && k.d(1), k = K && K(f), k && (k.c(), k.m(e, null))), (!h || M[0] & /*className*/
      4 && D !== (D = qe(
        /*className*/
        f[2]
      ) + " svelte-p509gh")) && s(e, "class", D), (!h || M[0] & /*className, collapsed, searchValue*/
      22) && X(
        e,
        "can-collapse",
        /*collapsed*/
        f[4] && /*searchValue*/
        f[1] === ""
      );
    },
    i(f) {
      h || (G(i.$$.fragment, f), G(R.$$.fragment, f), G(_), G(m), G(S, f), h = !0);
    },
    o(f) {
      Q(i.$$.fragment, f), Q(R.$$.fragment, f), Q(_), Q(m), Q(S, f), h = !1;
    },
    d(f) {
      f && I(e), ge(i), t[50](null), ge(R), _ && _.d(), m && m.d(), S && S.d(f), k && k.d(), F = !1, Y(U);
    }
  };
}
function un(t, e, n) {
  const r = e[1], i = e[0], u = r - i;
  return t === r && n ? t : ((t - i) % u + u) % u + i;
}
function nt(t) {
  let e = [...t];
  return e[2] < e[0] && (e[2] += 360), e;
}
function on(t, e, n) {
  let r, { $$slots: i = {}, $$scope: u } = e, { class: c = void 0 } = e, { apiKey: d } = e, { bbox: o = void 0 } = e, { clearButtonTitle: a = "clear" } = e, { clearOnBlur: R = !1 } = e, { collapsed: E = !1 } = e, { country: B = void 0 } = e, { debounceSearch: L = 200 } = e, { enableReverse: N = !1 } = e, { errorMessage: D = "Searching failed" } = e, { filter: h = () => !0 } = e, { flyTo: F = !0 } = e, { fuzzyMatch: U = !0 } = e, { language: _ = void 0 } = e, { limit: m = void 0 } = e, { mapController: g = void 0 } = e, { minLength: S = 2 } = e, { noResultsMessage: se = "No results found" } = e, { placeholder: K = "Search" } = e, { proximity: k = void 0 } = e, { reverseActive: f = N === "always" } = e, { reverseButtonTitle: M = "toggle reverse geocoding" } = e, { searchValue: p = "" } = e, { showFullGeometry: re = !0 } = e, { showPlaceType: Oe = !1 } = e, { showResultsWhileTyping: ke = !0 } = e, { trackProximity: pe = !0 } = e, { types: ve = void 0 } = e, { zoom: Te = 16 } = e, { fetchParameters: Ce = {} } = e;
  function st() {
    V.focus();
  }
  function at() {
    V.blur();
  }
  function De(l, T = !0) {
    n(1, p = l), T ? (n(13, v = -1), Ve()) : (Le(), setTimeout(() => {
      V.focus(), V.select();
    }));
  }
  let le = !1, y, A, w, Fe = "", V, v = -1, W, Me = [], $, ce, Re;
  const Z = Ft();
  Dt(() => {
    g && (g.setEventHandler(void 0), g.indicateReverse(!1), g.setSelectedMarker(-1), g.setMarkers(void 0, void 0));
  });
  function Ve(l) {
    if (ce && (clearTimeout(ce), ce = void 0), v > -1 && y)
      n(45, w = y[v]), n(1, p = w.place_name.replace(/,.*/, "")), n(16, W = void 0), n(44, A = void 0), n(13, v = -1);
    else if (p) {
      const T = l || !He();
      Be(p, { exact: !0 }).then(() => {
        n(44, A = y), n(45, w = void 0), T && dt();
      }).catch((H) => n(16, W = H));
    }
  }
  function He() {
    return /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/.test(p);
  }
  async function Be(l, { byId: T = !1, exact: H = !1 } = {}) {
    n(16, W = void 0);
    const ae = He(), x = new URLSearchParams();
    _ != null && x.set("language", Array.isArray(_) ? _.join(",") : _), ve && x.set("types", ve.join(",")), ae || (o && x.set("bbox", o.map((J) => J.toFixed(6)).join(",")), B && x.set("country", Array.isArray(B) ? B.join(",") : B)), T || (k && x.set("proximity", k.map((J) => J.toFixed(6)).join(",")), (H || !ke) && x.set("autocomplete", "false"), x.set("fuzzyMatch", String(U))), m !== void 0 && x.set("limit", String(m)), x.set("key", d);
    const ee = "https://api.maptiler.com/geocoding/" + encodeURIComponent(l) + ".json?" + x.toString();
    if (ee === Fe) {
      T ? (n(12, y = void 0), n(45, w = Me[0])) : n(12, y = Me);
      return;
    }
    Fe = ee, $ == null || $.abort();
    const P = new AbortController();
    n(17, $ = P);
    let Ae;
    try {
      Ae = await fetch(ee, { signal: P.signal, ...Ce }).finally(() => {
        P === $ && n(17, $ = void 0);
      });
    } catch (J) {
      if (J && typeof J == "object" && "name" in J && J.name === "AbortError")
        return;
      throw new Error();
    }
    if (!Ae.ok)
      throw new Error();
    const Pe = await Ae.json();
    Z("response", { url: ee, featureCollection: Pe }), T ? (n(12, y = void 0), n(45, w = Pe.features[0]), Me = [w]) : (n(12, y = Pe.features.filter(h)), Me = y, ae && V.focus());
  }
  function dt() {
    var H, ae, x, ee;
    if (!(A != null && A.length) || !F)
      return;
    const l = [180, 90, -180, -90], T = !A.some((P) => !P.matching_text);
    for (const P of A)
      (T || !P.matching_text) && (l[0] = Math.min(l[0], ((H = P.bbox) == null ? void 0 : H[0]) ?? P.center[0]), l[1] = Math.min(l[1], ((ae = P.bbox) == null ? void 0 : ae[1]) ?? P.center[1]), l[2] = Math.max(l[2], ((x = P.bbox) == null ? void 0 : x[2]) ?? P.center[0]), l[3] = Math.max(l[3], ((ee = P.bbox) == null ? void 0 : ee[3]) ?? P.center[1]));
    g && A.length > 0 && (w && l[0] === l[2] && l[1] === l[3] ? g.flyTo(w.center, Te) : g.fitBounds(nt(l), 50));
  }
  function ht(l) {
    n(0, f = N === "always"), De(un(l[0], [-180, 180], !0).toFixed(6) + "," + l[1].toFixed(6));
  }
  function mt(l) {
    if (!y)
      return;
    let T = l.key === "ArrowDown" ? 1 : l.key === "ArrowUp" ? -1 : 0;
    T ? (v === -1 && T === -1 && n(13, v = y.length), n(13, v += T), v >= y.length && n(13, v = -1), l.preventDefault()) : ["ArrowLeft", "ArrowRight", "Home", "End"].includes(l.key) && n(13, v = -1);
  }
  function Le(l = !0) {
    if (ke && p.length > S) {
      ce && clearTimeout(ce);
      const T = p;
      ce = window.setTimeout(
        () => {
          Be(T).catch((H) => n(16, W = H));
        },
        l ? L : 0
      );
    } else
      n(12, y = void 0), n(16, W = void 0);
  }
  function Se(l) {
    n(45, w = l), n(1, p = l.place_name), n(13, v = -1);
  }
  const _t = () => V.focus();
  function gt(l) {
    je[l ? "unshift" : "push"](() => {
      V = l, n(15, V);
    });
  }
  function yt() {
    p = this.value, n(1, p), n(11, le), n(25, R);
  }
  const bt = () => n(11, le = !0), wt = () => n(11, le = !1), kt = () => Le(), pt = () => {
    n(1, p = ""), V.focus();
  }, vt = () => n(0, f = !f), Tt = (l) => n(13, v = l), Mt = (l) => Se(l), Rt = () => n(13, v = -1), Et = () => {
  };
  return t.$$set = (l) => {
    "class" in l && n(2, c = l.class), "apiKey" in l && n(23, d = l.apiKey), "bbox" in l && n(24, o = l.bbox), "clearButtonTitle" in l && n(3, a = l.clearButtonTitle), "clearOnBlur" in l && n(25, R = l.clearOnBlur), "collapsed" in l && n(4, E = l.collapsed), "country" in l && n(26, B = l.country), "debounceSearch" in l && n(27, L = l.debounceSearch), "enableReverse" in l && n(5, N = l.enableReverse), "errorMessage" in l && n(6, D = l.errorMessage), "filter" in l && n(28, h = l.filter), "flyTo" in l && n(29, F = l.flyTo), "fuzzyMatch" in l && n(30, U = l.fuzzyMatch), "language" in l && n(31, _ = l.language), "limit" in l && n(32, m = l.limit), "mapController" in l && n(33, g = l.mapController), "minLength" in l && n(34, S = l.minLength), "noResultsMessage" in l && n(7, se = l.noResultsMessage), "placeholder" in l && n(8, K = l.placeholder), "proximity" in l && n(22, k = l.proximity), "reverseActive" in l && n(0, f = l.reverseActive), "reverseButtonTitle" in l && n(9, M = l.reverseButtonTitle), "searchValue" in l && n(1, p = l.searchValue), "showFullGeometry" in l && n(35, re = l.showFullGeometry), "showPlaceType" in l && n(10, Oe = l.showPlaceType), "showResultsWhileTyping" in l && n(36, ke = l.showResultsWhileTyping), "trackProximity" in l && n(37, pe = l.trackProximity), "types" in l && n(38, ve = l.types), "zoom" in l && n(39, Te = l.zoom), "fetchParameters" in l && n(40, Ce = l.fetchParameters), "$$scope" in l && n(47, u = l.$$scope);
  }, t.$$.update = () => {
    if (t.$$.dirty[1] & /*trackProximity*/
    64 && (pe || n(22, k = void 0)), t.$$.dirty[0] & /*focused, clearOnBlur*/
    33556480 && setTimeout(() => {
      n(14, Re = le), R && !le && n(1, p = "");
    }), t.$$.dirty[0] & /*searchValue, listFeatures*/
    4098 && (p || (n(45, w = void 0), n(12, y = void 0), n(16, W = void 0), n(44, A = y))), t.$$.dirty[1] & /*showFullGeometry, picked*/
    16400 && re && w && !w.address && w.geometry.type === "Point" && Be(w.id, { byId: !0 }).catch((l) => n(16, W = l)), t.$$.dirty[0] & /*flyTo*/
    536870912 | t.$$.dirty[1] & /*mapController, picked, zoom*/
    16644 && g && w && F && (!w.bbox || w.bbox[0] === w.bbox[2] && w.bbox[1] === w.bbox[3] ? g.flyTo(w.center, Te) : g.fitBounds(nt(w.bbox), 50), n(12, y = void 0), n(44, A = void 0), n(13, v = -1)), t.$$.dirty[0] & /*listFeatures*/
    4096 | t.$$.dirty[1] & /*markedFeatures*/
    8192 && A !== y && n(44, A = void 0), t.$$.dirty[1] & /*mapController, markedFeatures, picked*/
    24580 && g && g.setMarkers(A, w), t.$$.dirty[0] & /*searchValue*/
    2 && n(13, v = -1), t.$$.dirty[0] & /*reverseActive, listFeatures, focusedDelayed*/
    20481 | t.$$.dirty[1] & /*mapController, trackProximity*/
    68 && g && g.setEventHandler((l) => {
      switch (l.type) {
        case "mapClick":
          f && ht(l.coordinates);
          break;
        case "proximityChange":
          n(22, k = pe ? l.proximity : void 0);
          break;
        case "markerClick":
          {
            const T = y == null ? void 0 : y.find((H) => H.id === l.id);
            T && Se(T);
          }
          break;
        case "markerMouseEnter":
          n(13, v = Re ? (y == null ? void 0 : y.findIndex((T) => T.id === l.id)) ?? -1 : -1);
          break;
        case "markerMouseLeave":
          n(13, v = -1);
          break;
      }
    }), t.$$.dirty[0] & /*selectedItemIndex*/
    8192 | t.$$.dirty[1] & /*mapController*/
    4 && (g == null || g.setSelectedMarker(v)), t.$$.dirty[0] & /*listFeatures, selectedItemIndex*/
    12288 && n(46, r = y == null ? void 0 : y[v]), t.$$.dirty[0] & /*searchValue*/
    2 | t.$$.dirty[1] & /*mapController*/
    4) {
      const l = /^(-?\d+(?:\.\d*)?),(-?\d+(?:\.\d*)?)$/.exec(p);
      g == null || g.setReverseMarker(l ? [Number(l[1]), Number(l[2])] : void 0);
    }
    t.$$.dirty[1] & /*selected*/
    32768 && Z("select", r), t.$$.dirty[1] & /*picked*/
    16384 && Z("pick", w), t.$$.dirty[0] & /*focusedDelayed, listFeatures*/
    20480 && Z("optionsVisibilityChange", Re && !!y), t.$$.dirty[0] & /*listFeatures*/
    4096 && Z("featuresListed", y), t.$$.dirty[1] & /*markedFeatures*/
    8192 && Z("featuresMarked", A), t.$$.dirty[0] & /*reverseActive*/
    1 && Z("reverseToggle", f), t.$$.dirty[0] & /*searchValue*/
    2 && Z("queryChange", p), t.$$.dirty[0] & /*reverseActive*/
    1 | t.$$.dirty[1] & /*mapController*/
    4 && g && g.indicateReverse(f);
  }, [
    f,
    p,
    c,
    a,
    E,
    N,
    D,
    se,
    K,
    M,
    Oe,
    le,
    y,
    v,
    Re,
    V,
    W,
    $,
    Ve,
    mt,
    Le,
    Se,
    k,
    d,
    o,
    R,
    B,
    L,
    h,
    F,
    U,
    _,
    m,
    g,
    S,
    re,
    ke,
    pe,
    ve,
    Te,
    Ce,
    st,
    at,
    De,
    A,
    w,
    r,
    u,
    i,
    _t,
    gt,
    yt,
    bt,
    wt,
    kt,
    pt,
    vt,
    Tt,
    Mt,
    Rt,
    Et
  ];
}
class fn extends we {
  constructor(e) {
    super(), be(
      this,
      e,
      on,
      cn,
      ye,
      {
        class: 2,
        apiKey: 23,
        bbox: 24,
        clearButtonTitle: 3,
        clearOnBlur: 25,
        collapsed: 4,
        country: 26,
        debounceSearch: 27,
        enableReverse: 5,
        errorMessage: 6,
        filter: 28,
        flyTo: 29,
        fuzzyMatch: 30,
        language: 31,
        limit: 32,
        mapController: 33,
        minLength: 34,
        noResultsMessage: 7,
        placeholder: 8,
        proximity: 22,
        reverseActive: 0,
        reverseButtonTitle: 9,
        searchValue: 1,
        showFullGeometry: 35,
        showPlaceType: 10,
        showResultsWhileTyping: 36,
        trackProximity: 37,
        types: 38,
        zoom: 39,
        fetchParameters: 40,
        focus: 41,
        blur: 42,
        setQuery: 43
      },
      null,
      [-1, -1, -1]
    );
  }
  get focus() {
    return this.$$.ctx[41];
  }
  get blur() {
    return this.$$.ctx[42];
  }
  get setQuery() {
    return this.$$.ctx[43];
  }
}
const rt = [
  "featuresListed",
  "featuresMarked",
  "optionsVisibilityChange",
  "pick",
  "queryChange",
  "response",
  "reverseToggle",
  "select"
], sn = [
  "apiKey",
  "bbox",
  "clearButtonTitle",
  "clearOnBlur",
  "collapsed",
  "country",
  "debounceSearch",
  "enableReverse",
  "errorMessage",
  "filter",
  "fuzzyMatch",
  "language",
  "limit",
  "minLength",
  "noResultsMessage",
  "placeholder",
  "proximity",
  "reverseButtonTitle",
  "showFullGeometry",
  "showPlaceType",
  "showResultsWhileTyping",
  "trackProximity",
  "types",
  "zoom",
  "mapController"
];
function lt(t) {
  return "on" + t[0].toUpperCase() + t.slice(1);
}
const dn = zt(function(e, n) {
  const r = Ke(), i = Ke(), u = { ...e };
  for (const c of rt)
    delete u[lt(c)];
  Ne(() => {
    if (!r.current)
      throw new Error();
    const c = new fn({
      target: r.current,
      props: u
    });
    return i.current = c, () => c.$destroy();
  }, []);
  for (const c of sn)
    Ne(() => {
      i.current && e[c] !== void 0 && i.current.$set({ [c]: e[c] });
    }, [e[c]]);
  for (const c of rt) {
    const d = e[lt(c)];
    Ne(() => {
      var o;
      (o = i.current) == null || o.$on(
        c,
        d ? (a) => {
          d(a.detail);
        } : void 0
      );
    }, [d]);
  }
  return Ct(n, () => ({
    setQuery: (c, d = !0) => {
      var o;
      return (o = i.current) == null ? void 0 : o.setQuery(c, d);
    },
    focus: () => {
      var c;
      return (c = i.current) == null ? void 0 : c.focus();
    },
    blur: () => {
      var c;
      return (c = i.current) == null ? void 0 : c.blur();
    }
  })), Bt("div", { ref: r });
});
export {
  dn as GeocodingControl
};
//# sourceMappingURL=react.js.map
