"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLayoutFilterViewItems = exports.getFilterPreview = void 0;
const utils_1 = require("../../..//View/Components/ColumnFilter/utils");
const adaptableQlUtils_1 = require("../../../Utilities/adaptableQlUtils");
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 = (0, adaptableQlUtils_1.mapColumnDataTypeToExpressionFunctionType)(columnType);
    const qlPredicateDefs = predicateDefs.map((pd) => (0, utils_1.mapAdaptablePredicateDefToQlPredicateDef)(pd, qlDataType));
    const qlPredicate = (0, utils_1.mapColumnFilterToQlPredicate)(columnFilter, column, qlPredicateDefs, columnFilterOptions, 'FilterForm', api);
    return `[${(0, utils_1.qlPredicateToString)(qlPredicate, qlPredicateDefs)}]`;
};
exports.getFilterPreview = getFilterPreview;
const getLayoutFilterViewItems = (layout, api) => {
    return {
        name: 'Column Filters',
        values: (layout.ColumnFilters ?? []).map((columnFilter) => (0, exports.getFilterPreview)(columnFilter, api)),
    };
};
exports.getLayoutFilterViewItems = getLayoutFilterViewItems;
