'use strict';

require('./KlevuApiRawResponse-7801506a.js');
const klevuFetch = require('./klevuFetch-d78ab4d9.js');

/**
 * cleans query term to improve search results
 *
 * @param term search term to be cleaned
 */
function cleanSearchQuery(term) {
    return (term
        // whitespace
        .replace(/\s{2,}/g, " ")
        // extra spaces
        .replace(/\s\s+/g, " ")
        // white space in end
        .trim()
        // to lowercase
        .toLocaleLowerCase());
}

const defaults = {
    id: "search",
    limit: 5,
    typeOfRecords: [klevuFetch.KlevuTypeOfRecord.Product],
};
/**
 * Create a basic search to Klevu backend. Default ID for this query is `search`
 *
 *
 * @category Query
 * @param term Search term from input
 * @param options {@link KlevuSearchOptions}
 * @returns
 */
function search(term, options, ...modifiers) {
    const params = Object.assign(Object.assign({}, defaults), options);
    const cleanedTerm = cleanSearchQuery(term);
    const query = {
        id: params.id,
        typeOfRequest: klevuFetch.KlevuTypeOfRequest.Search,
        settings: Object.assign({ query: {
                term: cleanedTerm,
            } }, params),
    };
    return {
        klevuFunctionId: "search",
        params: Object.assign(Object.assign({}, params), { term }),
        queries: [query],
        modifiers,
    };
}

exports.cleanSearchQuery = cleanSearchQuery;
exports.search = search;

//# sourceMappingURL=search-851c2504.js.map