import { BaseState } from './BaseState';
import { AdaptableObject } from './Common/AdaptableObject';
import { ColumnSort } from './Common/ColumnSort';
import { ColumnFilter, GridFilter } from '../types';
import { TableAggregationColumns, PivotAggregationColumns } from './Common/AggregationColumns';
import { RowSummary } from './Common/RowSummary';
import { NonEmptyArray } from '../Utilities/Extensions/ArrayExtensions';
import { XOR } from '../Utilities/Extensions/TypeExtensions';
/**
 * 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;
}
/**
 * Base object for both Table and Pivot Layouts
 */
export interface LayoutBase extends AdaptableObject {
    /**
     * Name of Layout as will appear in 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;
    /**
     * Position of the Grand Total Row in the Layout
     */
    GrandTotalRow?: 'top' | 'bottom' | 'pinnedTop' | 'pinnedBottom' | boolean;
    /**
     * Display Row Grouped Columns as 'single' or 'multi' column
     */
    RowGroupDisplayType?: 'single' | 'multi';
}
/**
 * Defines a Table-based Layout
 */
export interface TableLayout extends LayoutBase {
    /**
     * Names of Columns to include in the Table Layout
     */
    TableColumns: string[];
    /**
     * Map of Table Column Visibility
     */
    ColumnVisibility?: ColumnBooleanFalseMap;
    /**
     * Row Summaries - 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;
}
/**
 * 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;
};
/**
 * 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[];
}
