import { toSearchQuery } from "./toSearchQuery.js";
/**
 * @since 6.0.0
 * @since 6.2.0 Added support for `item.name` and `item.label`.
 * @internal
 */ export const defaultExtractor = (usageName, propName = "extractor")=>(item)=>{
        if (typeof item === "string") {
            return item;
        }
        if (item && typeof item === "object") {
            if ("label" in item && typeof item.label === "string") {
                return item.label;
            }
            if ("name" in item && typeof item.name === "string") {
                return item.name;
            }
        }
        throw new Error(`\`${usageName}\` requires the \`${propName}\` prop for lists that do not contain strings or known object types.`);
    };
/**
 * @internal
 * @since 6.0.0
 */ export function search(options) {
    const { list, type, query, filter, extractor, whitespace = "keep" } = options;
    const fallback = type === "search" ? undefined : list;
    if (!list.length) {
        return fallback;
    }
    const q = toSearchQuery(query, whitespace);
    if (!q) {
        return fallback;
    }
    const fn = type === "search" ? "find" : "filter";
    return list[fn]((item)=>filter(q, toSearchQuery(extractor(item), whitespace)));
}

//# sourceMappingURL=utils.js.map