"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdaptableFloatingFilter = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const AdaptableContext_1 = require("../../AdaptableContext");
const FloatingFilter_1 = require("./FloatingFilter");
const useAdaptableFilterWrapper_1 = require("./useAdaptableFilterWrapper");
/**
 * This wrapper knows about predicates.
 * It transforms predicates in QlPredicates.
 */
const AdaptableFloatingFilter = (props) => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const { qlPredicate, qlPredicateDefs, columnFilter, column, handlePredicateChange, handleOnChange, handleClear, } = (0, useAdaptableFilterWrapper_1.useAdaptableFilterWrapper)(props.Column.columnId);
    const onClear = React.useCallback(() => {
        handleClear();
        props.onClear?.();
    }, [handleClear, props.onClear]);
    const onPredicateChange = React.useCallback((newPredicate) => {
        handlePredicateChange(newPredicate);
        props.onChange?.();
    }, [handlePredicateChange, props.onChange]);
    if (!column) {
        return null;
    }
    return (React.createElement(FloatingFilter_1.FloatingFilter, { onKeydown: (event) => {
            const key = event.key;
            const predicate = adaptable.api.filterApi.columnFilterApi.internalApi.findPredicateDefByShortcut(key, column);
            if (predicate) {
                event.stopPropagation();
                event.preventDefault();
                handleOnChange([
                    {
                        PredicateId: predicate.id,
                        Inputs: [],
                    },
                ]);
                props.onChange?.();
            }
        }, onClear: onClear, columnId: props.Column.columnId, predicate: qlPredicate, predicateDefs: qlPredicateDefs, disabled: columnFilter?.IsSuspended, onPredicateChange: onPredicateChange, onChange: props.onChange }));
};
exports.AdaptableFloatingFilter = AdaptableFloatingFilter;
