import * as React from 'react';
import { mapColumnDataTypeToExpressionFunctionType } from '../../../Utilities/adaptableQlUtils';
import { useAdaptable } from '../../AdaptableContext';
import { ColumnFilterComponent as ColumnFilterComponent } from './ColumnFilter';
import { mapAdaptablePredicateDefToQlPredicateDef, mapColumnFilterToQlPredicate, mapQlPredicateToAdaptablePredicate, } from './utils';
export const LayoutColumnFilter = (props) => {
    const { api } = useAdaptable();
    const column = api.columnApi.getColumnWithColumnId(props.columnFilter.ColumnId);
    const columnFilterOptions = api.optionsApi.getFilterOptions().columnFilterOptions;
    const predicateDefs = api.filterApi.columnFilterApi.getFilterPredicateDefsForColumn(column);
    const qlDataType = mapColumnDataTypeToExpressionFunctionType(column.dataType);
    const qlPredicateDefs = predicateDefs.map((predDef) => mapAdaptablePredicateDefToQlPredicateDef(predDef, qlDataType));
    const qlPredicate = mapColumnFilterToQlPredicate(props.columnFilter, column, qlPredicateDefs, columnFilterOptions, 'FilterForm', api);
    const handlePredicateChange = (newPredicate) => {
        const newAdaptablePredicates = newPredicate.args.map(mapQlPredicateToAdaptablePredicate);
        const newFilter = {
            ...props.columnFilter,
            ColumnId: props.columnFilter.ColumnId,
            Predicates: newAdaptablePredicates,
            PredicatesOperator: newPredicate.operator,
        };
        props.onColumnFilterChange(newFilter);
    };
    return (React.createElement(ColumnFilterComponent, { columnId: props.columnFilter.ColumnId, predicate: qlPredicate, predicateDefs: qlPredicateDefs, disabled: props.columnFilter?.IsSuspended, onPredicateChange: handlePredicateChange }));
};
