import { AdaptableColumn } from '../PredefinedConfig/Common/AdaptableColumn';
import { FilterActionOnDataChange } from '../PredefinedConfig/Common/FilterActionOnDataChange';
import { BaseContext, SystemAlertPredicateId, SystemFilterPredicateId, SystemFilterPredicateIds } from '../../types';
import { StrictExtract } from '../Utilities/Extensions/TypeExtensions';
import { IRowNode } from '@ag-grid-community/core';
import { TypeHint } from '../PredefinedConfig/Common/Types';
/**
 * Options for managing Column Filtering in AdapTable
 */
export interface ColumnFilterOptions<TData = any> {
    /**
     * Options for managing the Quick (i.e. Floating) Filter
     */
    quickFilterOptions?: QuickFilterOptions;
    /**
     * Options for managing the Filter Form
     */
    filterFormOptions?: FilterFormOptions;
    /**
     * Options for managing the Values (IN) Filter
     */
    valuesFilterOptions?: ValuesFilterOptions;
    /**
     * Make Column header distinctive for filtered columns, helps users see currently filtered columns
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    indicateFilteredColumns?: boolean;
    /**
     * Uses Adaptable's Column Filtering (and Quick Filter Bar & Filter Form) in preference to AG Grid's filtering
     *
     * @defaultValue true
     * @noCodeItem
     */
    useAdaptableColumnFiltering?: boolean;
    /**
     * When to re-filter grid after user edits data: 'Always', 'Never' or 'Throttle' (which requires a 'ThrottleDelay')
     *
     * @defaultValue 'Always'
     */
    filterActionOnUserDataChange?: FilterActionOnDataChange;
    /**
     * When to re-filter grid after data ticks: 'Always', 'Never' or 'Throttle' (which requires a 'ThrottleDelay')
     *
     * @defaultValue 'Never'
     */
    filterActionOnExternalDataChange?: FilterActionOnDataChange;
    /**
     * Apply selected filters as soon as they are clicked; if false an Apply Filter button is displayed
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    autoApplyFilter?: boolean;
    /**
     * Clears saved Column Filters when AdapTable loads
     *
     * @defaultValue false
     * @gridInfoItem
     */
    clearColumnFiltersOnStartUp?: boolean;
    /**
     * Default filter type for numeric Columns
     *
     * @defaultValue Equals
     * @gridInfoItem
     */
    defaultNumericColumnFilter?: StrictExtract<SystemFilterPredicateId, 'GreaterThan' | 'LessThan' | 'Equals' | 'NotEquals' | 'Values'> | ((column: AdaptableColumn) => StrictExtract<SystemFilterPredicateId, 'GreaterThan' | 'LessThan' | 'Equals' | 'NotEquals' | 'Values'>);
    /**
     * Default filter type for string Columns
     *
     * @defaultValue Contains
     * @gridInfoItem
     */
    defaultStringColumnFilter?: StrictExtract<SystemFilterPredicateId, 'Is' | 'IsNot' | 'Contains' | 'NotContains' | 'StartsWith' | 'EndsWith' | 'Regex' | 'Values'> | ((column: AdaptableColumn) => StrictExtract<SystemFilterPredicateId, 'Is' | 'IsNot' | 'Contains' | 'NotContains' | 'StartsWith' | 'EndsWith' | 'Regex' | 'Values'>);
    /**
     * Default filter type for date Columns
     *
     * @defaultValue On
     * @gridInfoItem
     */
    defaultDateColumnFilter?: StrictExtract<SystemFilterPredicateId, 'After' | 'Before' | 'On' | 'NotOn' | 'Values'> | ((column: AdaptableColumn) => StrictExtract<SystemFilterPredicateId, 'After' | 'Before' | 'On' | 'NotOn' | 'Values'>);
    /**
     * Allows filtering on Calculated & FreeText columns
     *
     * @defaultValue true
     * @gridInfoItem
     */
    enableFilterOnSpecialColumns?: boolean;
    /**
     * Display Clear Filter button in Toolbar and Tool Panel
     * @defaultValue  false
     * @gridInfoItem
     * @noCodeItem
     */
    showClearFilterButton?: boolean;
    /**
     * Display Suspend / Unsuspend Button in Toolbar and Tool Panel
     * @defaultValue  false
     * @gridInfoItem
     * @noCodeItem
     */
    showSuspendFilterButton?: boolean;
    /**
     * Show Date Picker (or Date Input) in Filter controls
     * @gridInfoItem
     * @noCodeItem
     * @defaultValue true
     */
    showDatePicker?: boolean;
    /**
     * Configure whether some Rows will not be evaluated when Column Filtering
     *
     * @param context
     * @returns boolean
     */
    isRowFilterable?: (context: IsRowFilterableContext) => boolean;
}
/**
 * Options for managing the Filter Bar (aka Quick Filter)
 */
export interface QuickFilterOptions<TData = any> {
    /**
     * Hides Dropdown in Quick Filter Bar for a given Column
     *
     * @defaultValue undefined
     */
    hideQuickFilterDropdown?: (columFilterContext: ColumnFilterContext<TData>) => boolean;
    /**
     * Hides Input in Quick Filter Bar for a given Column
     *
     * @defaultValue undefined
     */
    hideQuickFilterInput?: (columFilterContext: ColumnFilterContext<TData>) => boolean;
    /**
     * Open Quick Filter dropdown with mouse hover or click
     *
     * @defaultValue 'mouseenter'
     * @gridInfoItem
     * @noCodeItem
     */
    quickFilterTrigger?: FilterTrigger;
    /**
     * Sets a height for Quick Filter Bar (if not provided AG Grid's default is used)
     *
     * @defaultValue null
     * @gridInfoItem
     */
    quickFilterHeight?: number;
    /**
     * Whether to display Quick Filter Bar between Column Header and the 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;
    /**
     * Width of Values popup in Filter Bar - can be set width or same size as Column
     * @defaultValue '180'
     */
    quickFilterValuesWidth?: 'auto' | number;
}
/**
 * Options for managing the Column Filter Form
 */
export interface FilterFormOptions<TData = any> {
    /**
     * Styles Adaptable Filter Form to match AG Grid's styling (if using Balham theme)
     *
     * @defaultValue true
     * @gridInfoItem
     * @noCodeItem
     */
    useAgGridFilterFormStyle?: boolean;
    /**
     * Whether to open the Filter Form on the Values or Predicates tab
     *
     * @defaultValue 'Values'
     * @gridInfoItem
     */
    defaultFilterFormTab?: 'Values' | 'Predicates';
}
/**
 * Options for managing the Values (IN) Filter in Filter Bar and Filter Form
 */
export interface ValuesFilterOptions<TData = any> {
    /**
     * Distinct column items to display in Values Filter; useful with large datasource (though AdapTable offers virtualisation)
     *
     * @defaultValue undefined
     * @gridInfoItem
     * @noCodeItem
     */
    maxFilterValuesToDisplay?: ((columFilterContext: ColumnFilterContext<TData>) => number) | number;
    /**
     * If Values filter should filter on datetime rather than date
     * @defaultValue  true
     * @noCodeItem
     */
    filterValuesUsingTime?: boolean;
    /**
     * Display only currently filtered values in Filter controls
     *
     * @defaultValue false
     * @gridInfoItem
     * @noCodeItem
     */
    showCurrentlyFilteredValuesOnly?: boolean;
    /**
     * Show the count of each distinct item for given column in the Values (IN) Filter
     * @defaultValue  false
     * @gridInfoItem
     * @noCodeItem
     */
    showValuesCount?: boolean | ((columFilterContext: ColumnFilterContext<TData>) => boolean);
    /**
     * If showing a Values Count, only count currently filtered columns
     * @defaultValue  false
     * @gridInfoItem
     * @noCodeItem
     */
    showCurrentlyFilteredValuesCount?: boolean;
    /**
     * Whether column values in filter dropdown should apply column's current Sort Order for the column
     *
     * @defaultValue false
     * @gridInfoItem
     */
    sortValuesFilter?: boolean;
    /**
     * Open Values dropdown with mouse hover or click
     *
     * @defaultValue 'mouseenter'
     * @gridInfoItem
     * @noCodeItem
     */
    valuesFilterTrigger?: 'mouseenter' | 'click';
    /**
     * Options for including (Non Input) Predicates in Values Filter
     */
    valuesFilterPredicateOptions?: ValuesFilterPredicateOptions;
}
/**
 * Context provided when Column Filtering
 */
export interface ColumnFilterContext<TData = any> extends BaseContext {
    /**
     * Column being filtered
     */
    column: AdaptableColumn<TData>;
}
/**
 * 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;
}
/**
 * Options for including Predicates in Values Filter
 */
export interface ValuesFilterPredicateOptions<TData = any> {
    /**
     * Predicates to add to Values Filter: should NOT take inputs (ie. use 'BLANK', 'NOT_BLANK', 'TODAY')
     */
    predicates: ColumnValuesFilterPredicate[] | ((context: ColumnFilterContext) => ColumnValuesFilterPredicate[]);
    /**
     * Where Predicates are displayed in Values Filter
     * @defaultValue 'Start'
     */
    predicatesPosition?: 'Start' | 'End';
}
/**
 * Context provided when Column Filtering
 */
export interface ValuesFilterPredicateContext<TData = any> extends BaseContext {
    /**
     * Column being filtered
     */
    column: AdaptableColumn<TData>;
    /**
     * Predicate being evaluated
     */
    predicate: ColumnValuesFilterPredicate;
}
/**
 * Predicate used in Column Values Filter
 */
export type ColumnValuesFilterPredicate = TypeHint<string, SystemFilterPredicateIds>;
/**
 * What triggers the dropdown
 */
export type FilterTrigger = 'mouseenter' | 'click';
