'use strict';

const klevuFetch = require('./klevuFetch-cb6905ea.js');
require('./KlevuDomEvents-f5b92150.js');

/**
 * This modifier should be used in the case when user hits enter (or presses button) to see
 * all results from search.
 *
 * @category Modifier
 * @returns
 */
function sendSearchEvent(override) {
    return {
        klevuModifierId: "sendSearchEvent",
        onResult: (res, f) => {
            var _a, _b, _c, _d;
            if (!f.params) {
                return res;
            }
            const { id, term } = f.params;
            if (!id || !term) {
                return res;
            }
            const meta = (_a = res.queriesById(id)) === null || _a === void 0 ? void 0 : _a.meta;
            if (!meta) {
                return res;
            }
            klevuFetch.KlevuEvents.search({
                term: ((_b = meta.klevuImageData) === null || _b === void 0 ? void 0 : _b.processed) &&
                    ((_d = (_c = meta.klevuImageData) === null || _c === void 0 ? void 0 : _c.processed) === null || _d === void 0 ? void 0 : _d.length) > 0
                    ? "KLEVU_IMAGE_SEARCH"
                    : term,
                totalResults: meta.totalResultsFound,
                typeOfSearch: meta.typeOfSearch,
                override,
            });
            if (!f.params) {
                f.params = {};
            }
            f.params.searchSendEventSent = true;
            return res;
        },
    };
}

exports.sendSearchEvent = sendSearchEvent;

//# sourceMappingURL=sendSearchEvent-09b80a2e.js.map