import { BaseState } from './BaseState';
import { AdaptableObject } from '../types';
import { ColumnSort } from './Common/ColumnSort';
import { ColumnFilter, GridFilter } from '../types';
import { PivotAggregationColumns, TableAggregationColumns } from './Common/AggregationColumns';
import { RowSummary } from './Common/RowSummary';
import { NonEmptyArray } from '../Utilities/Extensions/ArrayExtensions';
import { XOR } from '../Utilities/Extensions/TypeExtensions';
import { GroupSelectionMode, SelectAllMode } from 'ag-grid-enterprise';
/**
 * Chart to open when a layout is applied
 */
export interface LayoutOpenChart {
    /**
     * Name of a persisted chart in `Charting.ChartDefinitions` (must be unique among all charts)
     */
    ChartName: string;
    /**
     * Optional `chartContainers` name, or omit for the AG Grid chart window
     */
    ContainerName?: string;
}
/**
 * Base Layout Type - Pivot or Table
 */
export type Layout = TableLayout | PivotLayout;
/**
 * Array of Layouts - must contain at least one item
 */
export type LayoutArray = NonEmptyArray<Layout>;
/**
 * Adaptable State Section for Layout Module, containing collection of Layouts and name of Current Layout
 */
export interface LayoutState extends BaseState {
    /**
     * Layout to be loaded when AdapTable starts (using `Name` property in Layout); if not provided the first Layout is used
     */
    CurrentLayout?: string;
    /**
     * Collection of Layouts - can be Table or Pivot
     */
    Layouts: LayoutArray;
}
/**
 * How row groups are displayed in a Layout (maps to AG Grid `groupDisplayType`).
 */
export type RowGroupDisplayType = 'single' | 'multi' | 'groupRows';
/**
 * Base object for both Table and Pivot Layouts
 */
export interface LayoutBase extends AdaptableObject {
    /**
     * Name of the Layout as it appears in the Layout toolbar and tool panel
     */
    Name: string;
    /**
     * Controls size (width or flex & min/max) for Columns
     */
    ColumnSizing?: ColumnSizingMap;
    /**
     * Defines which Row Groups are expanded / collapsed
     */
    RowGroupValues?: RowGroupValues;
    /**
     * Defines which Column Groups are expanded / collapsed
     */
    ColumnGroupValues?: ColumnGroupValues;
    /**
     * Set of custom header names for some (or all) Columns
     */
    ColumnHeaders?: ColumnStringMap;
    /**
     * Hides the aggFunc in Column header: e.g. 'sum(Price)' becomes 'Price'
     */
    SuppressAggFuncInHeader?: boolean;
    /**
     * Sorting to apply in the Layout
     */
    ColumnSorts?: ColumnSort[];
    /**
     * Collection of Column Filters to apply in Layout
     */
    ColumnFilters?: ColumnFilter[];
    /**
     * Grid Filter to apply in Layout
     */
    GridFilter?: GridFilter;
    /**
     * Details of which Columns are pinned
     */
    ColumnPinning?: ColumnDirectionMap;
    /**
     * Whether Columns should autosize when Layout first loads
     */
    AutoSizeColumns?: boolean;
    /**
     * AG Grid charts to open when this layout is selected (by chart UUID or name)
     */
    OpenCharts?: LayoutOpenChart[];
    /**
     * Defines Row Selection behaviour for Layout; if false, Row Selection is disabled; if undefined, GridOptions is used
     */
    RowSelection?: LayoutRowSelection | false;
    /**
     * Position of the Grand Total Row in the Layout
     */
    GrandTotalRow?: 'top' | 'bottom' | 'pinnedTop' | 'pinnedBottom' | boolean;
    /**
     * How Row Groups are displayed: 'single' - one hierarchical group Column; 'multi' - a separate group Column per Row Grouped Column; 'groupRows' - full-width group rows (no group column); defaults to 'single'
     */
    RowGroupDisplayType?: RowGroupDisplayType;
}
/**
 * Defines a Table-based Layout
 */
export interface TableLayout extends LayoutBase {
    /**
     * List of Column Ids to include in Table Layout
     */
    TableColumns: string[];
    /**
     * Map of Table Column Visibility
     */
    ColumnVisibility?: ColumnBooleanFalseMap;
    /**
     * Pinned Rows that display Aggregation Info for a whole Column
     */
    RowSummaries?: RowSummary[];
    /**
     * Columns showing aggregated values in Grouped Rows; a record of ColumnId and aggfunc (e.g. sum) or 'true' (to use default aggfunc)
     */
    TableAggregationColumns?: TableAggregationColumns;
    /**
     * Columns which are row-grouped when the Layout is applied
     */
    RowGroupedColumns?: string[];
    /**
     * Pivot Columns - must NOT be provided
     */
    PivotColumns?: never;
    /**
     * Pivot Group Columns - must NOT be provided
     */
    PivotGroupedColumns?: never;
    /**
     * Pivot Expansions - must NOT be provided
     */
    PivotExpandLevel?: never;
    /**
     * Pivot Aggregation Columns - must NOT be provided
     */
    PivotAggregationColumns?: never;
}
/**
 * Defines a Pivot-based Layout
 */
export interface PivotLayout extends LayoutBase {
    /**
     * Mandatory list of Columns to pivot (provide empty array if just displaying Aggregations)
     */
    PivotColumns: string[];
    /**
     * How deep to expand Pivot Columns (0 for none, 1 for 1st level only etc, -1 to expand all)
     */
    PivotExpandLevel?: number;
    /**
     * Columns showing aggregated values in Group Rows; 1st value in record is Column name, 2nd is either aggfunc (e.g. sum, avg etc.) or 'true' (to use default aggfunc)
     */
    PivotAggregationColumns?: PivotAggregationColumns;
    /**
     * Columns which are row-grouped when the Layout is applied
     */
    PivotGroupedColumns?: string[];
    /**
     * Table Columns - must NOT be provided
     */
    TableColumns?: never;
    /**
     * Table Aggregation Columns - must NOT be provided
     */
    TableAggregationColumns?: never;
    /**
     * Row Grouped Columns Columns - must NOT be provided
     */
    RowGroupedColumns?: never;
    /**
     * Display automatically calculated Totals of all Pivot Columns, in the position specified
     */
    PivotGrandTotal?: PivotTotalPosition;
    /**
     * Display automatically calculated Totals within EACH Pivot Column Group, in the position specified
     */
    PivotColumnTotal?: PivotTotalPosition;
    /**
     * Ordered list of Pivot Result Columns; set to `true` to track current display order, or provide custom list
     */
    PivotResultColumnsOrder?: string[] | boolean;
}
/**
 * Defines the position of Pivot Total position - 'before' or 'after' the Value Column(s)
 */
export type PivotTotalPosition = 'before' | 'after' | boolean;
/**
 * Manages Row Group expand / collapse behaviour, including exceptions
 */
export type RowGroupValues = {
    RowGroupDefaultBehavior: 'always-expanded' | 'always-collapsed';
} | RowGroupValuesWithExceptionKeys;
/**
 * Defines which Row Groups are expanded or collapsed
 */
export type RowGroupValuesWithExceptionKeys = {
    /**
     * Default behaviour for Row Groups: 'expanded' or 'collapsed';
     */
    RowGroupDefaultBehavior: 'expanded' | 'collapsed';
} & XOR<{
    /**
     * @deprecated - use GroupKeys instead which enables listing exceptions on a per Column basis
     */
    ExceptionGroupKeys?: any[][];
}, {
    /**
     * Configures Row Group Expand / Collapse behaviour together with per Column Exceptions
     */
    GroupKeys?: GroupKeys[];
}>;
/**
 * Enables setting Row Group behaviour with exceptions
 */
export interface GroupKeys {
    /**
     * Columns that are Row Grouped
     */
    RowGroupedColumns: string[];
    /**
     * Exceptions to default behaviour, provided as array or arrays
     */
    ExceptionGroupKeys?: any[][];
}
/**
 * Manages Column Group expand / collapse behaviour, including exceptions
 */
export type ColumnGroupValues = {
    ColumnGroupDefaultBehavior: 'always-expanded' | 'always-collapsed';
} | ColumnGroupValuesWithExceptionKeys;
/**
 * Defines which Column Groups are expanded or collapsed
 */
export type ColumnGroupValuesWithExceptionKeys = {
    /**
     * Default behaviour for Column Groups: 'expanded' or 'collapsed';
     */
    ColumnGroupDefaultBehavior: 'expanded' | 'collapsed';
    /**
     * Keys of Column Groups which are exceptions to default ColumnGroupDefaultBehavior; key maps to groupId property in ColGroupDef
     */
    ExceptionGroupKeys?: any[];
};
/**
 * Defines a map of Columns with Sizing information
 */
export type ColumnSizingMap = {
    [columnId: string]: ColumnSizingDefinition;
};
/**
 * Defines a map of Columns with a String value
 */
export type ColumnStringMap = {
    [columnId: string]: string;
};
/**
 * Defines a map of Columns with a Number value
 */
export type ColumnNumberMap = {
    [columnId: string]: number;
};
/**
 * Defines a map of Columns with a Boolean value
 */
export type ColumnBooleanFalseMap = {
    [columnId: string]: false;
};
/**
 * Defines a map of Columns with a Left / Right direction value
 */
export type ColumnDirectionMap = {
    [columnId: string]: 'left' | 'right';
};
/**
 * State & behaviour for column sizing (must set `width` or `flex` but not both); all other props optional
 */
export type ColumnSizingDefinition = ({
    Width?: number;
    Flex?: never;
} | {
    Flex?: number;
    Width?: never;
}) & {
    Resizable?: boolean;
    MinWidth?: number;
    MaxWidth?: number;
};
/**
 * Defines Row Selection behaviour in a Layout
 */
export interface LayoutRowSelection {
    /**
     * Row Selection Mode: 'singleRow' or 'multiRow'
     */
    Mode: 'singleRow' | 'multiRow';
    /**
     * Whether to display checkboxes in Selection Column
     * @defaultValue true
     */
    Checkboxes?: boolean;
    /**
     * Whether to show checkbox in Header of Selection Column Header ('multiRow' only)
     * @defaultValue true
     */
    HeaderCheckbox?: boolean;
    /**
     * Renders selection checkboxes in Auto-Group Column (if `true`) or in dedicated Selection Column (if `false`)
     * @defaultValue false
     */
    CheckboxInGroupColumn?: boolean;
    /**
     * Grouping Select Mode: 'self' | 'descendants' | 'filteredDescendants'
     * @defaultValue 'self'
     */
    GroupSelectMode?: GroupSelectionMode;
    /**
     * Select All Mode: 'all' | 'filtered' | 'currentPage'
     * @defaultValue 'all'
     */
    SelectAllMode?: SelectAllMode;
    /**
     * Selection behaviour when clicking a row: 'enableSelection' | 'enableDeselection' | true | false
     * @defaultValue false
     */
    EnableClickSelection?: boolean | 'enableDeselection' | 'enableSelection';
}
/**
 * The OLD Layout - kept temporarily so we can check what we previously had
 */
export interface LayoutOld extends AdaptableObject {
    Name: string;
    Columns: string[];
    ColumnWidthMap?: {
        [columnId: string]: number;
    };
    ColumnSorts?: ColumnSort[];
    ColumnFilters?: ColumnFilter[];
    GridFilter?: GridFilter;
    RowGroupedColumns?: string[];
    ExpandedRowGroupValues?: any[];
    AggregationColumns?: Record<string, string | true | any>;
    EnablePivot?: boolean;
    PivotColumns?: string[];
    PinnedColumnsMap?: {
        [columnId: string]: 'left' | 'right';
    };
    ColumnHeadersMap?: {
        [columnId: string]: string;
    };
    SuppressAggFuncInHeader?: boolean;
    RowSummaries?: RowSummary[];
}
