import { F as Fuse } from './fuse.esm-80f40788.js';
import { s as state } from './store-cca1abc6.js';

async function searchServices(query, filter, limit) {
  let services = ((state === null || state === void 0 ? void 0 : state.services) || []).filter((service) => filter && typeof filter === "function" ? filter(service) : true);
  if (query === null || query === void 0 ? void 0 : query.length) {
    const fuse = new Fuse(services, {
      keys: ["name", "description"],
    });
    services = fuse.search(query, { limit }).map((result) => result === null || result === void 0 ? void 0 : result.item);
  }
  return services;
}

function cleanAndLowerString(str) {
  if (!str)
    return str;
  return str
    .replace(/\s{2,}/g, " ")
    .trim()
    .toLowerCase();
}

function getServiceTypes({ filterBy, } = {}) {
  const services = filterBy
    ? ((state === null || state === void 0 ? void 0 : state.services) || []).filter(filterBy)
    : (state === null || state === void 0 ? void 0 : state.services) || [];
  return [
    ...new Set(services.map((service) => cleanAndLowerString(service === null || service === void 0 ? void 0 : service.tab))),
  ]
    .sort((a, b) => (a > b ? 1 : -1))
    .filter((value) => value === null || value === void 0 ? void 0 : value.length)
    .map((value) => ({
    label: value,
    value,
  }));
}

export { cleanAndLowerString as c, getServiceTypes as g, searchServices as s };
