import { FilterActionOnDataChange } from '../AdaptableState/Common/FilterActionOnDataChange';
import { BaseContext } from '../../types';
import { AdaptableColumn } from '../AdaptableState/Common/AdaptableColumn';
import { SystemAlertPredicateId, SystemFilterPredicateId } from '../../types';
import { StrictExtract } from '../Utilities/Extensions/TypeExtensions';
import { AdaptableColumnContext } from '../AdaptableState/Common/AdaptableColumnContext';
import { IRowNode } from 'ag-grid-enterprise';
/**
 * Options for managing Column & Grid Filters in AdapTable
 */
export interface FilterOptions<TData = any> {
    /**
     * Options for managing Column Filters
     */
    columnFilterOptions?: ColumnFilterOptions;
    /**
     * Options for managing the Grid Filter
     */
    gridFilterOptions?: GridFilterOptions;
    /**
     * Clear Grid and Column Filters when AdapTable loads
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    clearFiltersOnStartUp?: boolean;
    /**
     * Provide custom values (or sorting / count info) when using the `In` Filter
     * @param context
     * @returns
     */
    customInFilterValues?: (context: CustomInFilterValuesContext<TData>) => Promise<InFilterValueInfo[]> | InFilterValueInfo[];
    /**
     * When to re-filter grid after data changes: 'Always', 'Never' or 'Throttle' (with a delay value)
     *
     * @defaultValue 'Always'
     */
    filterActionOnDataChange?: FilterActionOnDataChange;
    /**
     * Allow filtering on Calculated & FreeText columns
     *
     * @defaultValue true
     * @gridInfoItem
     */
    enableFilterOnSpecialColumns?: boolean;
    /**
     * Configures whether Rows will be evaluated when filtering
     *
     * @param context
     * @returns boolean
     */
    isRowFilterable?: (context: IsRowFilterableContext) => boolean;
    /**
     * Show Date Picker (or Date Input) in Filter controls
     * @gridInfoItem
     * @noCodeItem
     * @defaultValue true
     */
    showDatePicker?: boolean;
    /**
     * Use Adaptable's Column & Grid Filters in preference to AG Grid's filtering
     *
     * @defaultValue true
     * @noCodeItem
     */
    useAdaptableFiltering?: boolean;
}
/**
 * Options for managing Column Filtering in AdapTable
 */
export interface ColumnFilterOptions<TData = any> {
    /**
     * Make Column Header distinctive for filtered columns, helps users see currently filtered columns
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    indicateFilteredColumns?: boolean;
    /**
     * Apply Column Filters immediately; if false an Apply Filter button is displayed and Quick Filter is disabled
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    autoApplyColumnFilter?: boolean | ((context: AdaptableColumnContext) => boolean);
    /**
     * Whether to cache the values in the IN Filter component
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    cacheInFilterValues?: boolean | ((context: AdaptableColumnContext) => boolean);
    /**
     * Default filter type for numeric Columns
     *
     * @defaultValue Equals
     * @gridInfoItem
     */
    defaultNumericColumnFilter?: StrictExtract<SystemFilterPredicateId, 'GreaterThan' | 'LessThan' | 'Equals' | 'NotEquals' | 'In'> | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract<SystemFilterPredicateId, 'GreaterThan' | 'LessThan' | 'Equals' | 'NotEquals' | 'In'>);
    /**
     * Default filter type for text Columns
     *
     * @defaultValue Contains
     * @gridInfoItem
     */
    defaultTextColumnFilter?: StrictExtract<SystemFilterPredicateId, 'Is' | 'IsNot' | 'Contains' | 'NotContains' | 'StartsWith' | 'EndsWith' | 'Regex' | 'In'> | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract<SystemFilterPredicateId, 'Is' | 'IsNot' | 'Contains' | 'NotContains' | 'StartsWith' | 'EndsWith' | 'Regex' | 'In'>);
    /**
     * Default filter type for date Columns
     *
     * @defaultValue On
     * @gridInfoItem
     */
    defaultDateColumnFilter?: StrictExtract<SystemFilterPredicateId, 'After' | 'Before' | 'On' | 'NotOn' | 'In'> | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract<SystemFilterPredicateId, 'After' | 'Before' | 'On' | 'NotOn' | 'In'>);
    /**
     * Default filter type for array Columns ('textArray', 'numberArray', etc.)
     *
     * @defaultValue In
     * @gridInfoItem
     */
    defaultArrayColumnFilter?: StrictExtract<SystemFilterPredicateId, 'In' | 'NotIn' | 'Blanks' | 'NonBlanks'> | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract<SystemFilterPredicateId, 'In' | 'NotIn' | 'Blanks' | 'NonBlanks'>);
    /**
     * Hides Dropdown in Quick Filter Bar for a given Column
     *
     * @defaultValue undefined
     */
    hideQuickFilterDropdown?: (adaptableColumnContext: AdaptableColumnContext<TData>) => boolean;
    /**
     * Hides Input in Quick Filter Bar for a given Column
     *
     * @defaultValue undefined
     */
    hideQuickFilterInput?: (adaptableColumnContext: AdaptableColumnContext<TData>) => boolean;
    /**
     * Height of Quick Filter Bar (if not provided, AG Grid default is used)
     *
     * @defaultValue null
     * @gridInfoItem
     */
    quickFilterHeight?: number;
    /**
     * Display Quick Filter Bar between Column Header and Grid (provided its been setup)
     * @defaultValue  true
     * @noCodeItem
     */
    showQuickFilter?: boolean;
    /**
     * Shortcut Keys to activate a Quick Filter Predicate
     */
    quickFilterWildcards?: Partial<Record<SystemAlertPredicateId, string[]>>;
    /**
     * Time to wait (in ms) before Filter Bar reacts to new value
     * @defaultValue 250
     * @gridInfoItem
     */
    quickFilterDebounce?: number;
}
/**
 * Options for managing the Grid Filter in AdapTable
 */
export interface GridFilterOptions<TData = any> {
    /**
     * Which UI Components can be used to edit a Grid Filter: Expression Editor, Query Builder (or both)
     *
     * @defaultValue ['ExpressionEditor', 'QueryBuilder']
     */
    availableFilterEditors?: GridFilterEditors;
}
/**
 * Context used for setting whether a Row can be Column Filtered
 */
export interface IsRowFilterableContext<TData = any> extends BaseContext {
    /**
     * The Row Node about to be evaluated
     */
    rowNode: IRowNode;
    /**
     * The data in the Row Node
     */
    data: TData;
}
export type AdaptableFilterComponentLocation = 'FilterBar' | 'FilterForm';
/**
 * Context used for setting default Predicates for Column Filters
 */
export interface DefaultPredicateFilterContext<TData = any> extends BaseContext {
    /**
     * Filter Component being displayed: FilterBar or FilterForm
     */
    filterComponent: AdaptableFilterComponentLocation;
    /**
     * Current Column
     */
    column: AdaptableColumn<TData>;
}
/**
 * Item in the IN Column Filter
 */
export interface InFilterValue<ValueType = any> {
    /**
     * Item's label
     */
    label: string;
    /**
     * The value of Item being shown
     */
    value: ValueType;
    /**
     * Tooltip for Item (if true, the label is used as tooltip)
     */
    tooltip?: boolean | string;
}
/**
 * Information about items in the IN Column Filter
 */
export interface InFilterValueInfo extends InFilterValue {
    /**
     * Whether Item is currently selected
     */
    isSelected?: boolean;
    /**
     * How many times Item appears in the column
     */
    count?: number;
    /**
     * How many times Item appears in the column in filtered rows
     */
    visibleCount?: number;
    /**
     * Whether Item is currently visible in Grid (i.e. in filtered rows)
     */
    visible?: boolean;
}
/**
 * Context used when providing values for the IN Column Filter
 */
export interface CustomInFilterValuesContext<TData = any> extends AdaptableColumnContext {
    /**
     * Default list of values that will be displayed
     */
    defaultValues: Required<InFilterValueInfo>[];
    /**
     * Default values but Sorted based on Column's sort
     */
    sortedValues: Required<InFilterValueInfo>[];
    /**
     * Default values but in the order in which they are currently listed in the grid - (after all the sorting has been applied, or, if no sorting, in their natural order)
     */
    orderedValues: Required<InFilterValueInfo>[];
    /**
     * Search text in the IN Filter component - used when filtering on server
     */
    currentSearchValue: string;
}
/**
 * List of Editors that can be used when creating the Grid Filter
 */
export type GridFilterEditors = GridFilterEditor[];
/**
 * Editor to use for Grid Filter: 'ExpressionEditor' or 'QueryBuilder'
 */
export type GridFilterEditor = 'ExpressionEditor' | 'QueryBuilder';
