import { mapAdaptablePredicateDefToQlPredicateDef, mapColumnFilterToQlPredicate, qlPredicateToString, } from '../../..//View/Components/ColumnFilter/utils';
import { mapColumnDataTypeToExpressionFunctionType } from '../../../Utilities/adaptableQlUtils';
export const getFilterPreview = (columnFilter, api) => {
    const column = api.columnApi.getColumnWithColumnId(columnFilter.ColumnId);
    const columnFilterOptions = api.optionsApi.getFilterOptions().columnFilterOptions;
    const predicateDefs = api.filterApi.columnFilterApi.getFilterPredicateDefsForColumn(column);
    const columnType = api.columnApi.getColumnDataTypeForColumnId(columnFilter.ColumnId);
    const qlDataType = mapColumnDataTypeToExpressionFunctionType(columnType);
    const qlPredicateDefs = predicateDefs.map((pd) => mapAdaptablePredicateDefToQlPredicateDef(pd, qlDataType));
    const qlPredicate = mapColumnFilterToQlPredicate(columnFilter, column, qlPredicateDefs, columnFilterOptions, 'FilterForm', api);
    return `[${qlPredicateToString(qlPredicate, qlPredicateDefs)}]`;
};
export const getLayoutFilterViewItems = (layout, api) => {
    return {
        name: 'Column Filters',
        values: (layout.ColumnFilters ?? []).map((columnFilter) => getFilterPreview(columnFilter, api)),
    };
};
