"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Suggestions = void 0;
const react_1 = __importDefault(require("react"));
const components_1 = require("../../components");
const hooks_1 = require("../../hooks");
const Suggestions = (props) => {
    var _a;
    const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleSuggestions;
    const reactifySearchContext = (0, hooks_1.useReactifySearchContext)();
    const { searchTerm } = (0, hooks_1.useSearch)();
    const sensorIds = (0, components_1.SENSOR_IDS)(reactifySearchContext.options.mode, reactifySearchContext.config);
    return (react_1.default.createElement(components_1.CustomComponent, { componentId: "SensorSuggestions", defaultQuery: () => {
            return {
                suggest: {
                    suggestions: {
                        text: searchTerm,
                        phrase: {
                            field: props.field,
                            gram_size: 2,
                            confidence: 0,
                            direct_generator: [{
                                    field: props.field,
                                    suggest_mode: "always",
                                    min_word_length: 1,
                                }],
                        },
                    },
                },
            };
        }, react: {
            and: sensorIds,
        }, render: (renderProps) => {
            var _a, _b, _c;
            const props = {
                suggestions: [],
            };
            if ((_b = (_a = renderProps.rawData) === null || _a === void 0 ? void 0 : _a.suggest) === null || _b === void 0 ? void 0 : _b.suggestions.length) {
                const options = (_c = renderProps.rawData.suggest.suggestions[renderProps.rawData.suggest.suggestions.length - 1]) === null || _c === void 0 ? void 0 : _c.options;
                props.suggestions = options
                    .filter((option) => option.text !== searchTerm)
                    .filter((option) => { var _a; return !((_a = reactifySearchContext.config.suggestions.exclude) !== null && _a !== void 0 ? _a : []).includes(option.text); })
                    .map((option) => ({
                    text: option.text,
                }));
            }
            return react_1.default.createElement(RenderComponent, Object.assign({}, props));
        } }));
};
exports.Suggestions = Suggestions;
//# sourceMappingURL=Suggestions.js.map