"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LayoutColumnFilter = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const adaptableQlUtils_1 = require("../../../Utilities/adaptableQlUtils");
const AdaptableContext_1 = require("../../AdaptableContext");
const ColumnFilter_1 = require("./ColumnFilter");
const utils_1 = require("./utils");
const LayoutColumnFilter = (props) => {
    const { api } = (0, AdaptableContext_1.useAdaptable)();
    const column = api.columnApi.getColumnWithColumnId(props.columnFilter.ColumnId);
    const columnFilterOptions = api.optionsApi.getFilterOptions().columnFilterOptions;
    const predicateDefs = api.filterApi.columnFilterApi.getFilterPredicateDefsForColumn(column);
    const qlDataType = (0, adaptableQlUtils_1.mapColumnDataTypeToExpressionFunctionType)(column.dataType);
    const qlPredicateDefs = predicateDefs.map((predDef) => (0, utils_1.mapAdaptablePredicateDefToQlPredicateDef)(predDef, qlDataType));
    const qlPredicate = (0, utils_1.mapColumnFilterToQlPredicate)(props.columnFilter, column, qlPredicateDefs, columnFilterOptions, 'FilterForm', api);
    const handlePredicateChange = (newPredicate) => {
        const newAdaptablePredicates = newPredicate.args.map(utils_1.mapQlPredicateToAdaptablePredicate);
        const newFilter = {
            ...props.columnFilter,
            ColumnId: props.columnFilter.ColumnId,
            Predicates: newAdaptablePredicates,
            PredicatesOperator: newPredicate.operator,
        };
        props.onColumnFilterChange(newFilter);
    };
    return (React.createElement(ColumnFilter_1.ColumnFilterComponent, { location: 'filterForm', columnId: props.columnFilter.ColumnId, predicate: qlPredicate, predicateDefs: qlPredicateDefs, disabled: props.columnFilter?.IsSuspended, onPredicateChange: handlePredicateChange, hideActionButtons: true }));
};
exports.LayoutColumnFilter = LayoutColumnFilter;
