import { useMemo as O, useState as le, useCallback as fe } from "react";
function D(t) {
  return Array.isArray ? Array.isArray(t) : re(t) === "[object Array]";
}
function de(t) {
  if (typeof t == "string")
    return t;
  let e = t + "";
  return e == "0" && 1 / t == -1 / 0 ? "-0" : e;
}
function ge(t) {
  return t == null ? "" : de(t);
}
function M(t) {
  return typeof t == "string";
}
function te(t) {
  return typeof t == "number";
}
function Ae(t) {
  return t === !0 || t === !1 || pe(t) && re(t) == "[object Boolean]";
}
function se(t) {
  return typeof t == "object";
}
function pe(t) {
  return se(t) && t !== null;
}
function E(t) {
  return t != null;
}
function j(t) {
  return !t.trim().length;
}
function re(t) {
  return t == null ? t === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(t);
}
const Ee = "Incorrect 'index' type", Ce = (t) => `Invalid value for key ${t}`, me = (t) => `Pattern length exceeds max of ${t}.`, Fe = (t) => `Missing ${t} property in key`, Me = (t) => `Property 'weight' in key '${t}' must be a positive integer`, U = Object.prototype.hasOwnProperty;
class Be {
  constructor(e) {
    this._keys = [], this._keyMap = {};
    let s = 0;
    e.forEach((r) => {
      let n = ne(r);
      this._keys.push(n), this._keyMap[n.id] = n, s += n.weight;
    }), this._keys.forEach((r) => {
      r.weight /= s;
    });
  }
  get(e) {
    return this._keyMap[e];
  }
  keys() {
    return this._keys;
  }
  toJSON() {
    return JSON.stringify(this._keys);
  }
}
function ne(t) {
  let e = null, s = null, r = null, n = 1, i = null;
  if (M(t) || D(t))
    r = t, e = X(t), s = K(t);
  else {
    if (!U.call(t, "name"))
      throw new Error(Fe("name"));
    const u = t.name;
    if (r = u, U.call(t, "weight") && (n = t.weight, n <= 0))
      throw new Error(Me(u));
    e = X(u), s = K(u), i = t.getFn;
  }
  return { path: e, id: s, weight: n, src: r, getFn: i };
}
function X(t) {
  return D(t) ? t : t.split(".");
}
function K(t) {
  return D(t) ? t.join(".") : t;
}
function De(t, e) {
  let s = [], r = !1;
  const n = (i, u, c) => {
    if (E(i))
      if (!u[c])
        s.push(i);
      else {
        let h = u[c];
        const o = i[h];
        if (!E(o))
          return;
        if (c === u.length - 1 && (M(o) || te(o) || Ae(o)))
          s.push(ge(o));
        else if (D(o)) {
          r = !0;
          for (let a = 0, f = o.length; a < f; a += 1)
            n(o[a], u, c + 1);
        } else u.length && n(o, u, c + 1);
      }
  };
  return n(t, M(e) ? e.split(".") : e, 0), r ? s : s[0];
}
const ye = {
  // Whether the matches should be included in the result set. When `true`, each record in the result
  // set will include the indices of the matched characters.
  // These can consequently be used for highlighting purposes.
  includeMatches: !1,
  // When `true`, the matching function will continue to the end of a search pattern even if
  // a perfect match has already been located in the string.
  findAllMatches: !1,
  // Minimum number of characters that must be matched before a result is considered a match
  minMatchCharLength: 1
}, xe = {
  // When `true`, the algorithm continues searching to the end of the input even if a perfect
  // match is found before the end of the same input.
  isCaseSensitive: !1,
  // When `true`, the algorithm will ignore diacritics (accents) in comparisons
  ignoreDiacritics: !1,
  // When true, the matching function will continue to the end of a search pattern even if
  includeScore: !1,
  // List of properties that will be searched. This also supports nested properties.
  keys: [],
  // Whether to sort the result list, by score
  shouldSort: !0,
  // Default sort function: sort by ascending score, ascending index
  sortFn: (t, e) => t.score === e.score ? t.idx < e.idx ? -1 : 1 : t.score < e.score ? -1 : 1
}, _e = {
  // Approximately where in the text is the pattern expected to be found?
  location: 0,
  // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
  // (of both letters and location), a threshold of '1.0' would match anything.
  threshold: 0.6,
  // Determines how close the match must be to the fuzzy location (specified above).
  // An exact letter match which is 'distance' characters away from the fuzzy location
  // would score as a complete mismatch. A distance of '0' requires the match be at
  // the exact location specified, a threshold of '1000' would require a perfect match
  // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
  distance: 100
}, Ie = {
  // When `true`, it enables the use of unix-like search commands
  useExtendedSearch: !1,
  // The get function to use when fetching an object's properties.
  // The default will search nested paths *ie foo.bar.baz*
  getFn: De,
  // When `true`, search will ignore `location` and `distance`, so it won't matter
  // where in the string the pattern appears.
  // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
  ignoreLocation: !1,
  // When `true`, the calculation for the relevance score (used for sorting) will
  // ignore the field-length norm.
  // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
  ignoreFieldNorm: !1,
  // The weight to determine how much field length norm effects scoring.
  fieldNormWeight: 1
};
var l = {
  ...xe,
  ...ye,
  ..._e,
  ...Ie
};
const Se = /[^ ]+/g;
function we(t = 1, e = 3) {
  const s = /* @__PURE__ */ new Map(), r = Math.pow(10, e);
  return {
    get(n) {
      const i = n.match(Se).length;
      if (s.has(i))
        return s.get(i);
      const u = 1 / Math.pow(i, 0.5 * t), c = parseFloat(Math.round(u * r) / r);
      return s.set(i, c), c;
    },
    clear() {
      s.clear();
    }
  };
}
class V {
  constructor({
    getFn: e = l.getFn,
    fieldNormWeight: s = l.fieldNormWeight
  } = {}) {
    this.norm = we(s, 3), this.getFn = e, this.isCreated = !1, this.setIndexRecords();
  }
  setSources(e = []) {
    this.docs = e;
  }
  setIndexRecords(e = []) {
    this.records = e;
  }
  setKeys(e = []) {
    this.keys = e, this._keysMap = {}, e.forEach((s, r) => {
      this._keysMap[s.id] = r;
    });
  }
  create() {
    this.isCreated || !this.docs.length || (this.isCreated = !0, M(this.docs[0]) ? this.docs.forEach((e, s) => {
      this._addString(e, s);
    }) : this.docs.forEach((e, s) => {
      this._addObject(e, s);
    }), this.norm.clear());
  }
  // Adds a doc to the end of the index
  add(e) {
    const s = this.size();
    M(e) ? this._addString(e, s) : this._addObject(e, s);
  }
  // Removes the doc at the specified index of the index
  removeAt(e) {
    this.records.splice(e, 1);
    for (let s = e, r = this.size(); s < r; s += 1)
      this.records[s].i -= 1;
  }
  getValueForItemAtKeyId(e, s) {
    return e[this._keysMap[s]];
  }
  size() {
    return this.records.length;
  }
  _addString(e, s) {
    if (!E(e) || j(e))
      return;
    let r = {
      v: e,
      i: s,
      n: this.norm.get(e)
    };
    this.records.push(r);
  }
  _addObject(e, s) {
    let r = { i: s, $: {} };
    this.keys.forEach((n, i) => {
      let u = n.getFn ? n.getFn(e) : this.getFn(e, n.path);
      if (E(u)) {
        if (D(u)) {
          let c = [];
          const h = [{ nestedArrIndex: -1, value: u }];
          for (; h.length; ) {
            const { nestedArrIndex: o, value: a } = h.pop();
            if (E(a))
              if (M(a) && !j(a)) {
                let f = {
                  v: a,
                  i: o,
                  n: this.norm.get(a)
                };
                c.push(f);
              } else D(a) && a.forEach((f, d) => {
                h.push({
                  nestedArrIndex: d,
                  value: f
                });
              });
          }
          r.$[i] = c;
        } else if (M(u) && !j(u)) {
          let c = {
            v: u,
            n: this.norm.get(u)
          };
          r.$[i] = c;
        }
      }
    }), this.records.push(r);
  }
  toJSON() {
    return {
      keys: this.keys,
      records: this.records
    };
  }
}
function ie(t, e, { getFn: s = l.getFn, fieldNormWeight: r = l.fieldNormWeight } = {}) {
  const n = new V({ getFn: s, fieldNormWeight: r });
  return n.setKeys(t.map(ne)), n.setSources(e), n.create(), n;
}
function Le(t, { getFn: e = l.getFn, fieldNormWeight: s = l.fieldNormWeight } = {}) {
  const { keys: r, records: n } = t, i = new V({ getFn: e, fieldNormWeight: s });
  return i.setKeys(r), i.setIndexRecords(n), i;
}
function $(t, {
  errors: e = 0,
  currentLocation: s = 0,
  expectedLocation: r = 0,
  distance: n = l.distance,
  ignoreLocation: i = l.ignoreLocation
} = {}) {
  const u = e / t.length;
  if (i)
    return u;
  const c = Math.abs(r - s);
  return n ? u + c / n : c ? 1 : u;
}
function Re(t = [], e = l.minMatchCharLength) {
  let s = [], r = -1, n = -1, i = 0;
  for (let u = t.length; i < u; i += 1) {
    let c = t[i];
    c && r === -1 ? r = i : !c && r !== -1 && (n = i - 1, n - r + 1 >= e && s.push([r, n]), r = -1);
  }
  return t[i - 1] && i - r >= e && s.push([r, i - 1]), s;
}
const w = 32;
function be(t, e, s, {
  location: r = l.location,
  distance: n = l.distance,
  threshold: i = l.threshold,
  findAllMatches: u = l.findAllMatches,
  minMatchCharLength: c = l.minMatchCharLength,
  includeMatches: h = l.includeMatches,
  ignoreLocation: o = l.ignoreLocation
} = {}) {
  if (e.length > w)
    throw new Error(me(w));
  const a = e.length, f = t.length, d = Math.max(0, Math.min(r, f));
  let g = i, A = d;
  const p = c > 1 || h, m = p ? Array(f) : [];
  let y;
  for (; (y = t.indexOf(e, A)) > -1; ) {
    let C = $(e, {
      currentLocation: y,
      expectedLocation: d,
      distance: n,
      ignoreLocation: o
    });
    if (g = Math.min(C, g), A = y + a, p) {
      let x = 0;
      for (; x < a; )
        m[y + x] = 1, x += 1;
    }
  }
  A = -1;
  let B = [], L = 1, S = a + f;
  const ae = 1 << a - 1;
  for (let C = 0; C < a; C += 1) {
    let x = 0, _ = S;
    for (; x < _; )
      $(e, {
        errors: C,
        currentLocation: d + _,
        expectedLocation: d,
        distance: n,
        ignoreLocation: o
      }) <= g ? x = _ : S = _, _ = Math.floor((S - x) / 2 + x);
    S = _;
    let Q = Math.max(1, d - _ + 1), P = u ? f : Math.min(d + _, f) + a, R = Array(P + 2);
    R[P + 1] = (1 << C) - 1;
    for (let F = P; F >= Q; F -= 1) {
      let k = F - 1, J = s[t.charAt(k)];
      if (p && (m[k] = +!!J), R[F] = (R[F + 1] << 1 | 1) & J, C && (R[F] |= (B[F + 1] | B[F]) << 1 | 1 | B[F + 1]), R[F] & ae && (L = $(e, {
        errors: C,
        currentLocation: k,
        expectedLocation: d,
        distance: n,
        ignoreLocation: o
      }), L <= g)) {
        if (g = L, A = k, A <= d)
          break;
        Q = Math.max(1, 2 * d - A);
      }
    }
    if ($(e, {
      errors: C + 1,
      currentLocation: d,
      expectedLocation: d,
      distance: n,
      ignoreLocation: o
    }) > g)
      break;
    B = R;
  }
  const T = {
    isMatch: A >= 0,
    // Count exact matches (those with a score of 0) to be "almost" exact
    score: Math.max(1e-3, L)
  };
  if (p) {
    const C = Re(m, c);
    C.length ? h && (T.indices = C) : T.isMatch = !1;
  }
  return T;
}
function ke(t) {
  let e = {};
  for (let s = 0, r = t.length; s < r; s += 1) {
    const n = t.charAt(s);
    e[n] = (e[n] || 0) | 1 << r - s - 1;
  }
  return e;
}
const N = String.prototype.normalize ? ((t) => t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "")) : ((t) => t);
class ue {
  constructor(e, {
    location: s = l.location,
    threshold: r = l.threshold,
    distance: n = l.distance,
    includeMatches: i = l.includeMatches,
    findAllMatches: u = l.findAllMatches,
    minMatchCharLength: c = l.minMatchCharLength,
    isCaseSensitive: h = l.isCaseSensitive,
    ignoreDiacritics: o = l.ignoreDiacritics,
    ignoreLocation: a = l.ignoreLocation
  } = {}) {
    if (this.options = {
      location: s,
      threshold: r,
      distance: n,
      includeMatches: i,
      findAllMatches: u,
      minMatchCharLength: c,
      isCaseSensitive: h,
      ignoreDiacritics: o,
      ignoreLocation: a
    }, e = h ? e : e.toLowerCase(), e = o ? N(e) : e, this.pattern = e, this.chunks = [], !this.pattern.length)
      return;
    const f = (g, A) => {
      this.chunks.push({
        pattern: g,
        alphabet: ke(g),
        startIndex: A
      });
    }, d = this.pattern.length;
    if (d > w) {
      let g = 0;
      const A = d % w, p = d - A;
      for (; g < p; )
        f(this.pattern.substr(g, w), g), g += w;
      if (A) {
        const m = d - w;
        f(this.pattern.substr(m), m);
      }
    } else
      f(this.pattern, 0);
  }
  searchIn(e) {
    const { isCaseSensitive: s, ignoreDiacritics: r, includeMatches: n } = this.options;
    if (e = s ? e : e.toLowerCase(), e = r ? N(e) : e, this.pattern === e) {
      let p = {
        isMatch: !0,
        score: 0
      };
      return n && (p.indices = [[0, e.length - 1]]), p;
    }
    const {
      location: i,
      distance: u,
      threshold: c,
      findAllMatches: h,
      minMatchCharLength: o,
      ignoreLocation: a
    } = this.options;
    let f = [], d = 0, g = !1;
    this.chunks.forEach(({ pattern: p, alphabet: m, startIndex: y }) => {
      const { isMatch: B, score: L, indices: S } = be(e, p, m, {
        location: i + y,
        distance: u,
        threshold: c,
        findAllMatches: h,
        minMatchCharLength: o,
        includeMatches: n,
        ignoreLocation: a
      });
      B && (g = !0), d += L, B && S && (f = [...f, ...S]);
    });
    let A = {
      isMatch: g,
      score: g ? d / this.chunks.length : 1
    };
    return g && n && (A.indices = f), A;
  }
}
class I {
  constructor(e) {
    this.pattern = e;
  }
  static isMultiMatch(e) {
    return Z(e, this.multiRegex);
  }
  static isSingleMatch(e) {
    return Z(e, this.singleRegex);
  }
  search() {
  }
}
function Z(t, e) {
  const s = t.match(e);
  return s ? s[1] : null;
}
class Oe extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "exact";
  }
  static get multiRegex() {
    return /^="(.*)"$/;
  }
  static get singleRegex() {
    return /^=(.*)$/;
  }
  search(e) {
    const s = e === this.pattern;
    return {
      isMatch: s,
      score: s ? 0 : 1,
      indices: [0, this.pattern.length - 1]
    };
  }
}
class $e extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "inverse-exact";
  }
  static get multiRegex() {
    return /^!"(.*)"$/;
  }
  static get singleRegex() {
    return /^!(.*)$/;
  }
  search(e) {
    const r = e.indexOf(this.pattern) === -1;
    return {
      isMatch: r,
      score: r ? 0 : 1,
      indices: [0, e.length - 1]
    };
  }
}
class Ne extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "prefix-exact";
  }
  static get multiRegex() {
    return /^\^"(.*)"$/;
  }
  static get singleRegex() {
    return /^\^(.*)$/;
  }
  search(e) {
    const s = e.startsWith(this.pattern);
    return {
      isMatch: s,
      score: s ? 0 : 1,
      indices: [0, this.pattern.length - 1]
    };
  }
}
class ve extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "inverse-prefix-exact";
  }
  static get multiRegex() {
    return /^!\^"(.*)"$/;
  }
  static get singleRegex() {
    return /^!\^(.*)$/;
  }
  search(e) {
    const s = !e.startsWith(this.pattern);
    return {
      isMatch: s,
      score: s ? 0 : 1,
      indices: [0, e.length - 1]
    };
  }
}
class Te extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "suffix-exact";
  }
  static get multiRegex() {
    return /^"(.*)"\$$/;
  }
  static get singleRegex() {
    return /^(.*)\$$/;
  }
  search(e) {
    const s = e.endsWith(this.pattern);
    return {
      isMatch: s,
      score: s ? 0 : 1,
      indices: [e.length - this.pattern.length, e.length - 1]
    };
  }
}
class Pe extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "inverse-suffix-exact";
  }
  static get multiRegex() {
    return /^!"(.*)"\$$/;
  }
  static get singleRegex() {
    return /^!(.*)\$$/;
  }
  search(e) {
    const s = !e.endsWith(this.pattern);
    return {
      isMatch: s,
      score: s ? 0 : 1,
      indices: [0, e.length - 1]
    };
  }
}
class ce extends I {
  constructor(e, {
    location: s = l.location,
    threshold: r = l.threshold,
    distance: n = l.distance,
    includeMatches: i = l.includeMatches,
    findAllMatches: u = l.findAllMatches,
    minMatchCharLength: c = l.minMatchCharLength,
    isCaseSensitive: h = l.isCaseSensitive,
    ignoreDiacritics: o = l.ignoreDiacritics,
    ignoreLocation: a = l.ignoreLocation
  } = {}) {
    super(e), this._bitapSearch = new ue(e, {
      location: s,
      threshold: r,
      distance: n,
      includeMatches: i,
      findAllMatches: u,
      minMatchCharLength: c,
      isCaseSensitive: h,
      ignoreDiacritics: o,
      ignoreLocation: a
    });
  }
  static get type() {
    return "fuzzy";
  }
  static get multiRegex() {
    return /^"(.*)"$/;
  }
  static get singleRegex() {
    return /^(.*)$/;
  }
  search(e) {
    return this._bitapSearch.searchIn(e);
  }
}
class oe extends I {
  constructor(e) {
    super(e);
  }
  static get type() {
    return "include";
  }
  static get multiRegex() {
    return /^'"(.*)"$/;
  }
  static get singleRegex() {
    return /^'(.*)$/;
  }
  search(e) {
    let s = 0, r;
    const n = [], i = this.pattern.length;
    for (; (r = e.indexOf(this.pattern, s)) > -1; )
      s = r + i, n.push([r, s - 1]);
    const u = !!n.length;
    return {
      isMatch: u,
      score: u ? 0 : 1,
      indices: n
    };
  }
}
const W = [
  Oe,
  oe,
  Ne,
  ve,
  Pe,
  Te,
  $e,
  ce
], q = W.length, je = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, Ke = "|";
function We(t, e = {}) {
  return t.split(Ke).map((s) => {
    let r = s.trim().split(je).filter((i) => i && !!i.trim()), n = [];
    for (let i = 0, u = r.length; i < u; i += 1) {
      const c = r[i];
      let h = !1, o = -1;
      for (; !h && ++o < q; ) {
        const a = W[o];
        let f = a.isMultiMatch(c);
        f && (n.push(new a(f, e)), h = !0);
      }
      if (!h)
        for (o = -1; ++o < q; ) {
          const a = W[o];
          let f = a.isSingleMatch(c);
          if (f) {
            n.push(new a(f, e));
            break;
          }
        }
    }
    return n;
  });
}
const ze = /* @__PURE__ */ new Set([ce.type, oe.type]);
class Ge {
  constructor(e, {
    isCaseSensitive: s = l.isCaseSensitive,
    ignoreDiacritics: r = l.ignoreDiacritics,
    includeMatches: n = l.includeMatches,
    minMatchCharLength: i = l.minMatchCharLength,
    ignoreLocation: u = l.ignoreLocation,
    findAllMatches: c = l.findAllMatches,
    location: h = l.location,
    threshold: o = l.threshold,
    distance: a = l.distance
  } = {}) {
    this.query = null, this.options = {
      isCaseSensitive: s,
      ignoreDiacritics: r,
      includeMatches: n,
      minMatchCharLength: i,
      findAllMatches: c,
      ignoreLocation: u,
      location: h,
      threshold: o,
      distance: a
    }, e = s ? e : e.toLowerCase(), e = r ? N(e) : e, this.pattern = e, this.query = We(this.pattern, this.options);
  }
  static condition(e, s) {
    return s.useExtendedSearch;
  }
  searchIn(e) {
    const s = this.query;
    if (!s)
      return {
        isMatch: !1,
        score: 1
      };
    const { includeMatches: r, isCaseSensitive: n, ignoreDiacritics: i } = this.options;
    e = n ? e : e.toLowerCase(), e = i ? N(e) : e;
    let u = 0, c = [], h = 0;
    for (let o = 0, a = s.length; o < a; o += 1) {
      const f = s[o];
      c.length = 0, u = 0;
      for (let d = 0, g = f.length; d < g; d += 1) {
        const A = f[d], { isMatch: p, indices: m, score: y } = A.search(e);
        if (p) {
          if (u += 1, h += y, r) {
            const B = A.constructor.type;
            ze.has(B) ? c = [...c, ...m] : c.push(m);
          }
        } else {
          h = 0, u = 0, c.length = 0;
          break;
        }
      }
      if (u) {
        let d = {
          isMatch: !0,
          score: h / u
        };
        return r && (d.indices = c), d;
      }
    }
    return {
      isMatch: !1,
      score: 1
    };
  }
}
const z = [];
function He(...t) {
  z.push(...t);
}
function G(t, e) {
  for (let s = 0, r = z.length; s < r; s += 1) {
    let n = z[s];
    if (n.condition(t, e))
      return new n(t, e);
  }
  return new ue(t, e);
}
const v = {
  AND: "$and",
  OR: "$or"
}, H = {
  PATH: "$path",
  PATTERN: "$val"
}, Y = (t) => !!(t[v.AND] || t[v.OR]), Ye = (t) => !!t[H.PATH], Ve = (t) => !D(t) && se(t) && !Y(t), ee = (t) => ({
  [v.AND]: Object.keys(t).map((e) => ({
    [e]: t[e]
  }))
});
function he(t, e, { auto: s = !0 } = {}) {
  const r = (n) => {
    let i = Object.keys(n);
    const u = Ye(n);
    if (!u && i.length > 1 && !Y(n))
      return r(ee(n));
    if (Ve(n)) {
      const h = u ? n[H.PATH] : i[0], o = u ? n[H.PATTERN] : n[h];
      if (!M(o))
        throw new Error(Ce(h));
      const a = {
        keyId: K(h),
        pattern: o
      };
      return s && (a.searcher = G(o, e)), a;
    }
    let c = {
      children: [],
      operator: i[0]
    };
    return i.forEach((h) => {
      const o = n[h];
      D(o) && o.forEach((a) => {
        c.children.push(r(a));
      });
    }), c;
  };
  return Y(t) || (t = ee(t)), r(t);
}
function Qe(t, { ignoreFieldNorm: e = l.ignoreFieldNorm }) {
  t.forEach((s) => {
    let r = 1;
    s.matches.forEach(({ key: n, norm: i, score: u }) => {
      const c = n ? n.weight : null;
      r *= Math.pow(
        u === 0 && c ? Number.EPSILON : u,
        (c || 1) * (e ? 1 : i)
      );
    }), s.score = r;
  });
}
function Je(t, e) {
  const s = t.matches;
  e.matches = [], E(s) && s.forEach((r) => {
    if (!E(r.indices) || !r.indices.length)
      return;
    const { indices: n, value: i } = r;
    let u = {
      indices: n,
      value: i
    };
    r.key && (u.key = r.key.src), r.idx > -1 && (u.refIndex = r.idx), e.matches.push(u);
  });
}
function Ue(t, e) {
  e.score = t.score;
}
function Xe(t, e, {
  includeMatches: s = l.includeMatches,
  includeScore: r = l.includeScore
} = {}) {
  const n = [];
  return s && n.push(Je), r && n.push(Ue), t.map((i) => {
    const { idx: u } = i, c = {
      item: e[u],
      refIndex: u
    };
    return n.length && n.forEach((h) => {
      h(i, c);
    }), c;
  });
}
class b {
  constructor(e, s = {}, r) {
    this.options = { ...l, ...s }, this.options.useExtendedSearch, this._keyStore = new Be(this.options.keys), this.setCollection(e, r);
  }
  setCollection(e, s) {
    if (this._docs = e, s && !(s instanceof V))
      throw new Error(Ee);
    this._myIndex = s || ie(this.options.keys, this._docs, {
      getFn: this.options.getFn,
      fieldNormWeight: this.options.fieldNormWeight
    });
  }
  add(e) {
    E(e) && (this._docs.push(e), this._myIndex.add(e));
  }
  remove(e = () => !1) {
    const s = [];
    for (let r = 0, n = this._docs.length; r < n; r += 1) {
      const i = this._docs[r];
      e(i, r) && (this.removeAt(r), r -= 1, n -= 1, s.push(i));
    }
    return s;
  }
  removeAt(e) {
    this._docs.splice(e, 1), this._myIndex.removeAt(e);
  }
  getIndex() {
    return this._myIndex;
  }
  search(e, { limit: s = -1 } = {}) {
    const {
      includeMatches: r,
      includeScore: n,
      shouldSort: i,
      sortFn: u,
      ignoreFieldNorm: c
    } = this.options;
    let h = M(e) ? M(this._docs[0]) ? this._searchStringList(e) : this._searchObjectList(e) : this._searchLogical(e);
    return Qe(h, { ignoreFieldNorm: c }), i && h.sort(u), te(s) && s > -1 && (h = h.slice(0, s)), Xe(h, this._docs, {
      includeMatches: r,
      includeScore: n
    });
  }
  _searchStringList(e) {
    const s = G(e, this.options), { records: r } = this._myIndex, n = [];
    return r.forEach(({ v: i, i: u, n: c }) => {
      if (!E(i))
        return;
      const { isMatch: h, score: o, indices: a } = s.searchIn(i);
      h && n.push({
        item: i,
        idx: u,
        matches: [{ score: o, value: i, norm: c, indices: a }]
      });
    }), n;
  }
  _searchLogical(e) {
    const s = he(e, this.options), r = (c, h, o) => {
      if (!c.children) {
        const { keyId: f, searcher: d } = c, g = this._findMatches({
          key: this._keyStore.get(f),
          value: this._myIndex.getValueForItemAtKeyId(h, f),
          searcher: d
        });
        return g && g.length ? [
          {
            idx: o,
            item: h,
            matches: g
          }
        ] : [];
      }
      const a = [];
      for (let f = 0, d = c.children.length; f < d; f += 1) {
        const g = c.children[f], A = r(g, h, o);
        if (A.length)
          a.push(...A);
        else if (c.operator === v.AND)
          return [];
      }
      return a;
    }, n = this._myIndex.records, i = {}, u = [];
    return n.forEach(({ $: c, i: h }) => {
      if (E(c)) {
        let o = r(s, c, h);
        o.length && (i[h] || (i[h] = { idx: h, item: c, matches: [] }, u.push(i[h])), o.forEach(({ matches: a }) => {
          i[h].matches.push(...a);
        }));
      }
    }), u;
  }
  _searchObjectList(e) {
    const s = G(e, this.options), { keys: r, records: n } = this._myIndex, i = [];
    return n.forEach(({ $: u, i: c }) => {
      if (!E(u))
        return;
      let h = [];
      r.forEach((o, a) => {
        h.push(
          ...this._findMatches({
            key: o,
            value: u[a],
            searcher: s
          })
        );
      }), h.length && i.push({
        idx: c,
        item: u,
        matches: h
      });
    }), i;
  }
  _findMatches({ key: e, value: s, searcher: r }) {
    if (!E(s))
      return [];
    let n = [];
    if (D(s))
      s.forEach(({ v: i, i: u, n: c }) => {
        if (!E(i))
          return;
        const { isMatch: h, score: o, indices: a } = r.searchIn(i);
        h && n.push({
          score: o,
          key: e,
          value: i,
          idx: u,
          norm: c,
          indices: a
        });
      });
    else {
      const { v: i, n: u } = s, { isMatch: c, score: h, indices: o } = r.searchIn(i);
      c && n.push({ score: h, key: e, value: i, norm: u, indices: o });
    }
    return n;
  }
}
b.version = "7.1.0";
b.createIndex = ie;
b.parseIndex = Le;
b.config = l;
b.parseQuery = he;
He(Ge);
const et = ({
  data: t,
  filter: e,
  sort: s
}) => {
  const r = O(() => {
    let o = t;
    return e != null && (o = o.filter((a) => e(a, {}))), s != null && (o = [...o].sort(s)), o;
  }, [t, e, s]), n = O(() => r.length === 0 ? null : new b(r, {
    keys: Object.keys(r[0]),
    threshold: 0.3
  }), [r]), [i, u] = le({}), c = fe(
    ((o) => {
      if (Array.isArray(o)) {
        const a = new Set(o);
        return r.filter((f) => a.has(f.key));
      }
      return r.find((a) => a.key === o);
    }),
    [r]
  ), h = O(() => {
    let o = r;
    i.searchTerm != null && i.searchTerm.length > 0 && n != null && (o = n.search(i.searchTerm).map((d) => d.item), s != null && (o = [...o].sort(s)));
    const a = o.map((f) => f.key);
    return { getItem: c, data: a };
  }, [r, i, c, n, s]);
  return O(() => ({ ...h, retrieve: u }), [h, u]);
};
export {
  et as u
};
