export class AdaptableFilterHandler {
    constructor(adaptableApi, columnSetup) {
        this.adaptableApi = adaptableApi;
        this.colId = columnSetup.colId;
    }
    doesFilterPass(params) {
        try {
            const rowNode = params.node;
            // first assess if the Row is filterable - if not, then return true so it always appears in Grid
            const isRowFilterable = this.adaptableApi.gridApi.internalApi.isRowFilterable(rowNode);
            if (!isRowFilterable) {
                return true;
            }
            const columnFilters = this.adaptableApi.filterApi.columnFilterApi
                .getActiveColumnFilters()
                .filter((columnFilter) => this.adaptableApi.filterApi.columnFilterApi.isColumnFilterActive(columnFilter))
                .filter((columnFilter) => columnFilter.ColumnId === this.colId)
                .filter((columnFilter) => {
                const shouldEvaluateFilterOnClient = this.adaptableApi.expressionApi.internalApi.shouldEvaluatePredicatesInAdaptableQL('ColumnFilter', columnFilter, columnFilter.Predicates);
                return shouldEvaluateFilterOnClient;
            });
            const anyFilterFailed = columnFilters.some((columnFilter) => !this.adaptableApi.filterApi.columnFilterApi.internalApi.evaluateColumnFilter(columnFilter, rowNode));
            return anyFilterFailed ? false : true;
        }
        catch (ex) {
            this.adaptableApi.consoleError(ex);
            return false;
        }
    }
    getFilterDisplayValues(currentSearchValue) {
        if (!this.filterDisplayValues) {
            this.filterDisplayValues =
                this.adaptableApi.gridApi.internalApi.getDistinctFilterDisplayValuesForColumn({
                    columnId: this.colId,
                    currentSearchValue,
                });
        }
        return this.filterDisplayValues;
    }
    onNewRowsLoaded() {
        this.resetFilterDisplayValues();
    }
    onAnyFilterChanged() {
        this.resetFilterDisplayValues();
    }
    resetFilterDisplayValues() {
        // Reset the filter display values manually
        this.filterDisplayValues = null;
    }
    async refreshFilterDisplayValues() {
        this.resetFilterDisplayValues();
        return this.getFilterDisplayValues('');
    }
    refresh(params) {
        // No specific refresh logic needed for this handler
        // The filter display values will be reset on new rows loaded or any filter changed
    }
    destroy() {
        this.filterDisplayValues = null;
    }
}
