import { __exports as g } from "./index-impl2.js";
import { __require as X } from "./index-normalizeText.js";
var k;
function V() {
  if (k) return g;
  k = 1, g.__esModule = !0, g.aggressiveFuzzyMatch = E, g.createFuzzySearchImpl = w, g.experimentalSmartFuzzyMatch = L, g.fuzzyMatchImpl = C;
  var _ = q(X());
  function q(e) {
    return e && e.__esModule ? e : { default: e };
  }
  var M = Number.MAX_SAFE_INTEGER, d = function(r, s) {
    return (
      /*: number*/
      r.score - s.score
    );
  }, O = function(r, s) {
    return (
      /*: number*/
      r[0] - s[0]
    );
  }, R = new Set(`  []()-–—'"“”`.split(""));
  function x(e) {
    return R.has(e);
  }
  function T(e, r, s, i, t, v, n) {
    if (e === i)
      return [0, [[0, e.length - 1]]];
    var a = i.length, u = r.length, f = t.length;
    if (r === t)
      return [0.1, [[0, u - 1]]];
    if (r.startsWith(t))
      return [0.5, [[0, f - 1]]];
    var h = e.indexOf(i);
    if (h > -1 && x(e[h - 1]))
      return [0.9, [[h, h + a - 1]]];
    var c = r.indexOf(t);
    if (c > -1 && x(r[c - 1]))
      return [1, [[c, c + a - 1]]];
    var l = v.length;
    if (l > 1 && v.every(function(p) {
      return s.has(p);
    })) {
      var o = 1.5 + l * 0.2;
      return [o, v.map(function(p) {
        var S = r.indexOf(p);
        return [S, S + p.length - 1];
      }).sort(O)];
    }
    return c > -1 ? [2, [[c, c + a - 1]]] : n === "aggressive" ? E(r, t) : n === "smart" ? L(r, t) : null;
  }
  function E(e, r) {
    for (var s = e.length, i = r.length, t = 0, v = r[t], n = [], a = -1, u = -2, f = 0; f < s; f += 1)
      if (e[f] === v) {
        if (f !== u + 1 && (a >= 0 && n.push([a, u]), a = f), u = f, t += 1, t === i)
          return n.push([a, u]), W(n, e);
        v = r[t];
      }
    return null;
  }
  function L(e, r) {
    for (var s = e.length, i = [], t = 0, v = r[t], n = -1, a = -2; ; ) {
      var u = e.indexOf(v, a + 1);
      if (u === -1)
        break;
      if (u === 0 || x(e[u - 1]))
        n = u;
      else {
        var f = r.length - t, h = e.length - u, c = Math.min(3, f, h), l = r.slice(t, t + c);
        if (e.slice(u, u + c) === l)
          n = u;
        else {
          a += 1;
          continue;
        }
      }
      for (a = n; a < s && e[a] === v; a += 1)
        t += 1, v = r[t];
      if (a -= 1, i.push([n, a]), t === r.length)
        return W(i, e);
    }
    return null;
  }
  function W(e, r) {
    var s = 2;
    return e.forEach(function(i) {
      var t = i[0], v = i[1], n = v - t + 1, a = t === 0 || r[t] === " " || r[t - 1] === " ", u = v === r.length - 1 || r[v] === " " || r[v + 1] === " ", f = a && u;
      f ? s += 0.2 : a ? s += 0.4 : n >= 3 ? s += 0.8 : s += 1.6;
    }), [s, e];
  }
  function C(e, r) {
    var s = (0, _.default)(r), i = s.split(" "), t = (0, _.default)(e), v = new Set(t.split(" ")), n = T(e, t, v, r, s, i, "smart");
    return n ? {
      item: e,
      score: n[0],
      matches: [n[1]]
    } : null;
  }
  function w(e, r) {
    var s = r.strategy, i = s === void 0 ? "aggressive" : s, t = r.getText, v = e.map(function(n) {
      var a;
      if (t)
        a = t(n);
      else {
        var u = r.key ? n[r.key] : n;
        a = [u];
      }
      var f = a.map(function(h) {
        var c = h || "", l = (0, _.default)(c), o = new Set(l.split(" "));
        return [c, l, o];
      });
      return [n, f];
    });
    return function(n) {
      var a = [], u = (0, _.default)(n), f = u.split(" ");
      return u.length ? (v.forEach(function(h) {
        for (var c = h[0], l = h[1], o = M, p = [], S = 0, A = l.length; S < A; S += 1) {
          var y = l[S], B = y[0], N = y[1], G = y[2], F = T(B, N, G, n, u, f, i);
          F ? (o = Math.min(o, F[0]), p.push(F[1])) : p.push(null);
        }
        o < M && a.push({
          item: c,
          score: o,
          matches: p
        });
      }), a.sort(d), a) : [];
    };
  }
  return g;
}
export {
  V as __require
};
