import Fuse from "fuse.js";
import state from "../store";
export default async function searchServices(query, filter) {
  var _a;
  let results;
  if (!((_a = state.services) === null || _a === void 0 ? void 0 : _a.length) || !(query === null || query === void 0 ? void 0 : query.length)) {
    results = (state === null || state === void 0 ? void 0 : state.services) || [];
  }
  else {
    const fuse = new Fuse(state.services, {
      keys: ["name", "description"],
      fieldNormWeight: 1,
    });
    results = fuse.search(query).map((result) => result === null || result === void 0 ? void 0 : result.item);
  }
  return results.filter((service) => filter && typeof filter === "function" ? filter(service) : true);
}
//# sourceMappingURL=searchServices.js.map