import { useState as i, useMemo as b, useCallback as V, useEffect as h } from "react";
import { debounce as v } from "es-toolkit/function";
const y = (r, e) => e.split(".").reduce((t, s) => t ? t[s] : void 0, r), C = (r) => Object.keys(r).filter((e) => {
  const t = r[e];
  return typeof t == "string" || typeof t == "number";
}), w = (r, e = {}) => {
  const [t, s] = i(""), [l, a] = i(""), f = b(() => e.debounceMs ? v((c) => a(c), e.debounceMs) : null, [e.debounceMs]), m = V(
    (u) => {
      if (s(u), !f) {
        a(u);
        return;
      }
      f(u);
    },
    [f]
  );
  h(() => {
    e.debounceMs || a(t);
  }, [e.debounceMs, t]);
  const S = b(() => {
    const u = e.debounceMs ? l : t;
    if (!t)
      return r;
    if (r.length === 0)
      return [];
    const c = e.caseSensitive ?? !1, d = c ? u : u.toLowerCase();
    if (e.customFilter)
      return r.filter((o) => e.customFilter?.(o, u));
    const g = e.fields ?? C(r[0]);
    return r.filter(
      (o) => g.some((M) => {
        const n = y(o, M.toString());
        return typeof n == "string" ? (c ? n : n.toLowerCase()).includes(d) : typeof n == "number" ? n.toString().includes(d) : !1;
      })
    );
  }, [l, r, e, t]);
  return { searchValue: t, setSearchValue: m, filteredList: S };
};
export {
  w as default
};
//# sourceMappingURL=useSearch.js.map
