import type { SortableEvent, SortableOptions } from 'sortablejs';
import type { CreateElement } from 'vue';
import type { AffixProps } from '../affix';
import type { LoadingProps } from '../loading';
import type { PageInfo, PaginationProps } from '../pagination';
import type { TooltipProps } from '../tooltip';
import type { CheckboxGroupProps, CheckboxGroupValue, CheckboxProps } from '../checkbox';
import type { RadioProps } from '../radio';
import type { InputProps } from '../input';
import type { ButtonProps } from '../button';
import type { DialogProps } from '../dialog';
import type { AllValidateResult, FormRule } from '../form';
import type { ClassName, ComponentType, HTMLElementAttributes, LNode, OptionData, SizeType } from '../../common';
export interface TypeBaseTableProps<T extends TableRowData = TableRowData> {
    allowResizeColumnWidth?: boolean;
    bordered?: boolean;
    bottomContent?: string | LNode;
    cellEmptyContent?: string | LNode<BaseTableCellParams<T>>;
    columns?: Array<BaseTableCol<T>>;
    data?: Array<T>;
    disableDataPage?: boolean;
    empty?: string | LNode;
    firstFullRow?: string | LNode;
    fixedRows?: Array<number>;
    footData?: Array<T>;
    footerAffixProps?: Partial<AffixProps>;
    footerAffixedBottom?: boolean | Partial<AffixProps>;
    footerSummary?: string | LNode;
    headerAffixProps?: Partial<AffixProps>;
    headerAffixedTop?: boolean | Partial<AffixProps>;
    height?: string | number;
    horizontalScrollAffixedBottom?: boolean | Partial<AffixProps>;
    hover?: boolean;
    lastFullRow?: string | LNode;
    loading?: boolean | LNode;
    loadingProps?: Partial<LoadingProps>;
    maxHeight?: string | number;
    pagination?: PaginationProps;
    paginationAffixedBottom?: boolean | Partial<AffixProps>;
    resizable?: boolean;
    rowAttributes?: TableRowAttributes<T>;
    rowClassName?: ClassName | ((params: RowClassNameParams<T>) => ClassName);
    rowKey: string;
    rowspanAndColspan?: TableRowspanAndColspanFunc<T>;
    rowspanAndColspanInFooter?: TableRowspanAndColspanFunc<T>;
    scroll?: TableScroll;
    showHeader?: boolean;
    size?: SizeType;
    stripe?: boolean;
    tableContentWidth?: string;
    tableLayout?: 'auto' | 'fixed';
    topContent?: string | LNode;
    verticalAlign?: 'top' | 'middle' | 'bottom';
    onCellClick?: (context: BaseTableCellEventContext<T>) => void;
    onPageChange?: (pageInfo: PageInfo, newDataSource: Array<T>) => void;
    onRowClick?: (context: RowEventContext<T>) => void;
    onRowDblclick?: (context: RowEventContext<T>) => void;
    onRowMousedown?: (context: RowEventContext<T>) => void;
    onRowMouseenter?: (context: RowEventContext<T>) => void;
    onRowMouseleave?: (context: RowEventContext<T>) => void;
    onRowMouseover?: (context: RowEventContext<T>) => void;
    onRowMouseup?: (context: RowEventContext<T>) => void;
    onScroll?: (params: {
        e: WheelEvent;
    }) => void;
    onScrollX?: (params: {
        e: WheelEvent;
    }) => void;
    onScrollY?: (params: {
        e: WheelEvent;
    }) => void;
}
export interface BaseTableCol<T extends TableRowData = TableRowData> {
    align?: 'left' | 'right' | 'center';
    attrs?: BaseTableColumnAttributes<T>;
    cell?: string | LNode<BaseTableCellParams<T>>;
    children?: Array<BaseTableCol<T>>;
    className?: TableColumnClassName<T> | TableColumnClassName<T>[];
    colKey?: string;
    colspan?: number;
    ellipsis?: boolean | LNode<BaseTableCellParams<T>> | TooltipProps | {
        props: TooltipProps;
        content: LNode<BaseTableCellParams<T>>;
    };
    ellipsisTitle?: boolean | LNode<BaseTableColParams<T>> | TooltipProps | {
        props: TooltipProps;
        content: LNode<BaseTableColParams<T>>;
    };
    fixed?: 'left' | 'right';
    foot?: string | LNode<{
        col: BaseTableCol;
        colIndex: number;
    }>;
    minWidth?: string | number;
    render?: LNode<BaseTableRenderParams<T>>;
    resizable?: boolean;
    resize?: TableColumnResizeConfig;
    title?: string | LNode<{
        col: BaseTableCol;
        colIndex: number;
    }>;
    width?: string | number;
}
export interface TypePrimaryTableProps<T extends TableRowData = TableRowData> extends Omit<TypeBaseTableProps<T>, 'columns' | 'onCellClick'> {
    asyncLoading?: 'loading' | 'load-more' | LNode;
    columnController?: TableColumnController;
    columnControllerVisible?: boolean;
    defaultColumnControllerVisible?: boolean;
    columns?: Array<PrimaryTableCol<T>>;
    displayColumns?: CheckboxGroupValue;
    defaultDisplayColumns?: CheckboxGroupValue;
    dragSort?: 'row' | 'row-handler' | 'col' | 'row-handler-col' | 'drag-col';
    dragSortOptions?: SortableOptions;
    editableCellState?: EditableCellType<T>;
    editableRowKeys?: Array<string | number>;
    expandIcon?: boolean | LNode<ExpandArrowRenderParams<T>>;
    expandOnRowClick?: boolean;
    expandedRow?: LNode<TableExpandedRowParams<T>>;
    expandedRowKeys?: Array<string | number>;
    defaultExpandedRowKeys?: Array<string | number>;
    filterIcon?: LNode;
    filterRow?: string | LNode;
    filterValue?: FilterValue;
    defaultFilterValue?: FilterValue;
    hideSortTips?: boolean;
    indeterminateSelectedRowKeys?: Array<string | number>;
    multipleSort?: boolean;
    reserveSelectedRowOnPaginate?: boolean;
    selectedRowKeys?: Array<string | number>;
    defaultSelectedRowKeys?: Array<string | number>;
    showSortColumnBgColor?: boolean;
    sort?: TableSort;
    defaultSort?: TableSort;
    sortIcon?: LNode;
    sortOnRowDraggable?: boolean;
    onAsyncLoadingClick?: (context: {
        status: 'loading' | 'load-more';
    }) => void;
    onCellClick?: (context: PrimaryTableCellEventContext<T>) => void;
    onChange?: (data: TableChangeData, context: TableChangeContext<T>) => void;
    onColumnChange?: (context: PrimaryTableColumnChange<T>) => void;
    onColumnControllerVisibleChange?: (visible: boolean, context: {
        trigger: 'cancel' | 'confirm';
    }) => void;
    onDataChange?: (data: Array<T>, context: TableDataChangeContext) => void;
    onDisplayColumnsChange?: (value: CheckboxGroupValue) => void;
    onDragSort?: (context: DragSortContext<T>) => void;
    onExpandChange?: (expandedRowKeys: Array<string | number>, options: ExpandOptions<T>) => void;
    onFilterChange?: (filterValue: FilterValue, context: {
        col?: PrimaryTableCol<T>;
    }) => void;
    onRowEdit?: (context: PrimaryTableRowEditContext<T>) => void;
    onRowValidate?: (context: PrimaryTableRowValidateContext<T>) => void;
    onSelectChange?: (selectedRowKeys: Array<string | number>, options: SelectOptions<T>) => void;
    onSortChange?: (sort: TableSort, options: SortOptions<T>) => void;
    onValidate?: (context: PrimaryTableValidateContext) => void;
}
export interface PrimaryTableInstanceFunctions<T extends TableRowData = TableRowData> {
    validateRowData: (rowValue: T) => void;
    validateTableData: () => void;
}
export interface PrimaryTableCol<T extends TableRowData = TableRowData> extends Omit<BaseTableCol, 'cell' | 'title' | 'render' | 'children'> {
    cell?: string | LNode<PrimaryTableCellParams<T>>;
    checkProps?: CheckProps<T>;
    children?: Array<PrimaryTableCol<T>>;
    colKey?: string;
    disabled?: (options: {
        row: T;
        rowIndex: number;
    }) => boolean;
    edit?: TableEditableCellConfig<T>;
    filter?: TableColumnFilter;
    render?: LNode<PrimaryTableRenderParams<T>>;
    sortType?: SortType;
    sorter?: boolean | SorterFun<T>;
    title?: string | LNode<{
        col: PrimaryTableCol;
        colIndex: number;
    }>;
    type?: 'single' | 'multiple';
}
export interface TypeEnhancedTableProps<T extends TableRowData = TableRowData> extends TypePrimaryTableProps<T> {
    beforeDragSort?: (context: DragSortContext<T>) => boolean;
    tree?: TableTreeConfig;
    treeExpandAndFoldIcon?: LNode<{
        type: 'expand' | 'fold';
    }>;
    onAbnormalDragSort?: (context: TableAbnormalDragSortContext<T>) => void;
    onTreeExpandChange?: (context: TableTreeExpandChangeContext<T>) => void;
}
export interface EnhancedTableInstanceFunctions<T extends TableRowData = TableRowData> {
    appendTo: (key: TableRowValue, newData: T) => void;
    expandAll: () => void;
    foldAll: () => void;
    getData: (key: TableRowValue) => TableRowState<T>;
    getTreeExpandedRow: (type: 'unique' | 'data' | 'all') => void;
    getTreeNode: () => T[];
    insertAfter: (key: TableRowValue, newData: T) => void;
    insertBefore: (key: TableRowValue, newData: T) => void;
    remove: (key: TableRowValue) => void;
    resetData: (newData: T[]) => void;
    setData: (key: TableRowValue, newRowData: T) => void;
    swapData: (params: SwapParams<T>) => void;
    toggleExpandData: (p: {
        row: T;
        rowIndex: number;
    }) => void;
}
export interface TableRowState<T extends TableRowData = TableRowData> {
    disabled?: boolean;
    expandChildrenLength?: number;
    expanded: boolean;
    id: string | number;
    level?: number;
    parent?: TableRowState<T>;
    path?: TableRowState<T>[];
    row: T;
    rowIndex: number;
}
export interface TableColumnFilter {
    component?: ComponentType;
    confirmEvents?: string[];
    list?: Array<OptionData>;
    props?: FilterProps;
    resetValue?: any;
    showConfirmAndReset?: boolean;
    type?: FilterType;
}
export interface TableScroll {
    bufferSize?: number;
    isFixedRowHeight?: boolean;
    rowHeight?: number;
    threshold?: number;
    type: 'lazy' | 'virtual';
}
export interface TableColumnController {
    buttonProps?: ButtonProps;
    checkboxProps?: CheckboxGroupProps;
    dialogProps?: DialogProps;
    displayType?: 'fixed-width' | 'auto-width';
    fields?: string[];
    hideTriggerButton?: boolean;
    placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
}
export interface TableEditableCellConfig<T extends TableRowData = TableRowData> {
    abortEditOnEvent?: string[];
    component?: ComponentType;
    defaultEditable?: boolean;
    onEdited?: (context: PrimaryTableOnEditedContext<T>) => void;
    props?: TableEditableCellProps<T>;
    rules?: TableEditableCellRules<T>;
    showEditIcon?: boolean;
}
export interface TableTreeConfig {
    checkStrictly?: boolean;
    childrenKey?: string;
    defaultExpandAll?: boolean;
    indent?: number;
    treeNodeColumnIndex?: number;
}
export type TableRowAttributes<T> = HTMLElementAttributes | ((params: {
    row: T;
    rowIndex: number;
    type: 'body' | 'foot';
}) => HTMLElementAttributes) | Array<TableRowAttributes<T>>;
export interface RowClassNameParams<T> {
    row: T;
    rowIndex: number;
    type?: 'body' | 'foot';
}
export type TableRowspanAndColspanFunc<T> = (params: BaseTableCellParams<T>) => RowspanColspan;
export interface RowspanColspan {
    colspan?: number;
    rowspan?: number;
}
export interface BaseTableCellEventContext<T> {
    row: T;
    col: BaseTableCol;
    rowIndex: number;
    colIndex: number;
    e: MouseEvent;
}
export interface RowEventContext<T> {
    row: T;
    index: number;
    e: MouseEvent;
}
export interface TableRowData {
    [key: string]: any;
    children?: TableRowData[];
}
export type BaseTableColumnAttributes<T> = {
    [key: string]: any;
} | ((context: CellData<T>) => {
    [key: string]: any;
});
export interface BaseTableCellParams<T> {
    row: T;
    rowIndex: number;
    col: BaseTableCol<T>;
    colIndex: number;
}
export type TableColumnClassName<T> = ClassName | ((context: CellData<T>) => ClassName);
export interface CellData<T> extends BaseTableCellParams<T> {
    type: 'th' | 'td';
}
export interface BaseTableColParams<T> {
    col: BaseTableCol<T>;
    colIndex: number;
}
export interface BaseTableRenderParams<T> extends BaseTableCellParams<T> {
    type: RenderType;
}
export type RenderType = 'cell' | 'title';
export interface TableColumnResizeConfig {
    minWidth: number;
    maxWidth: number;
}
export type DataType = TableRowData;
export type EditableCellType<T> = (params: PrimaryTableCellParams<T>) => boolean;
export interface ExpandArrowRenderParams<T> {
    row: T;
    index: number;
}
export interface TableExpandedRowParams<T> {
    row: T;
    index: number;
    columns: PrimaryTableCol<T>[] | BaseTableCol<T>[];
}
export interface FilterValue {
    [key: string]: any;
}
export type TableSort = SortInfo | Array<SortInfo>;
export interface SortInfo {
    sortBy: string;
    descending: boolean;
}
export interface PrimaryTableCellEventContext<T> {
    row: T;
    col: PrimaryTableCol;
    rowIndex: number;
    colIndex: number;
    e: MouseEvent;
}
export interface TableChangeData {
    sorter?: TableSort;
    filter?: FilterValue;
    pagination?: PaginationProps;
}
export interface TableChangeContext<T> {
    trigger: TableChangeTrigger;
    currentData?: T[];
}
export type TableChangeTrigger = 'filter' | 'sorter' | 'pagination';
export interface PrimaryTableColumnChange<T> {
    columns?: CheckboxGroupValue;
    currentColumn?: PrimaryTableCol<T>;
    type?: 'check' | 'uncheck';
    e?: Event;
}
export interface TableDataChangeContext {
    trigger: 'sort';
}
export interface DragSortContext<T> {
    currentIndex: number;
    current: T;
    targetIndex: number;
    target: T;
    data: T[];
    newData: T[];
    currentData?: T[];
    e: SortableEvent;
    sort: 'row' | 'col';
}
export interface ExpandOptions<T> {
    expandedRowData: Array<T>;
    currentRowData: T;
}
export type PrimaryTableRowEditContext<T> = PrimaryTableCellParams<T> & {
    value: any;
    editedRow: T;
};
export interface PrimaryTableRowValidateContext<T> {
    result: TableRowValidateResult<T>[];
    trigger: TableValidateTrigger;
}
export type TableValidateTrigger = 'self' | 'parent';
export type TableRowValidateResult<T> = PrimaryTableCellParams<T> & {
    errorList: AllValidateResult[];
    value: any;
};
export interface SelectOptions<T> {
    selectedRowData: Array<T>;
    type: 'uncheck' | 'check';
    currentRowKey?: string;
    currentRowData?: T;
}
export interface SortOptions<T> {
    currentDataSource?: Array<T>;
    col: PrimaryTableCol;
}
export interface PrimaryTableValidateContext {
    result: TableErrorListMap;
}
export interface TableErrorListMap {
    [key: string]: AllValidateResult[];
}
export interface PrimaryTableCellParams<T> {
    row: T;
    rowIndex: number;
    col: PrimaryTableCol<T>;
    colIndex: number;
}
export type CheckProps<T> = CheckboxProps | RadioProps | ((options: {
    row: T;
    rowIndex: number;
}) => CheckboxProps | RadioProps);
export interface PrimaryTableRenderParams<T> extends PrimaryTableCellParams<T> {
    type: RenderType;
}
export type SortType = 'desc' | 'asc' | 'all';
export type SorterFun<T> = (a: T, b: T) => number;
export interface TableAbnormalDragSortContext<T> {
    code: number;
    reason: string;
    t?: T;
}
export interface TableTreeExpandChangeContext<T> {
    row: T;
    rowIndex: number;
    rowState: TableRowState<T>;
    trigger?: 'expand-fold-icon';
}
export type TableRowValue = string | number;
export interface SwapParams<T> {
    current: T;
    target: T;
    currentIndex: number;
    targetIndex: number;
}
export type FilterProps = RadioProps | CheckboxProps | InputProps | {
    [key: string]: any;
};
export type FilterType = 'input' | 'single' | 'multiple';
export type PrimaryTableOnEditedContext<T> = PrimaryTableCellParams<T> & {
    trigger: string;
    newRowData: T;
};
export type TableEditableCellProps<T> = TablePlainObject | ((params: TableEditableCellPropsParams<T>) => TablePlainObject);
export interface TableEditableCellPropsParams<T> extends PrimaryTableCellParams<T> {
    editedRow: T;
}
export interface TablePlainObject {
    [key: string]: any;
}
export type TableEditableCellRules<T> = FormRule[] | ((params: PrimaryTableCellParams<T>) => FormRule[]);
export interface BaseTableProps extends TypeBaseTableProps {
    renderExpandedRow?: (h: CreateElement, params: TableExpandedRowParams<TableRowData>) => JSX.Element;
    onLeafColumnsChange?: (columns: BaseTableColumns) => void;
}
export type PrimaryTableProps = TypePrimaryTableProps;
export type EnhancedTableProps = TypeEnhancedTableProps;
export type TableProps = PrimaryTableProps;
export type ThRowspanAndColspan = Map<any, RowspanColspan>;
export type BaseTableColumns = TypeBaseTableProps['columns'];
export interface ColumnStickyLeftAndRight {
    left: number[];
    right: number[];
    top: number[];
    bottom?: number[];
}
export interface TableColFixedClasses {
    left: string;
    right: string;
    lastLeft: string;
    firstRight: string;
    leftShadow: string;
    rightShadow: string;
}
export interface TableRowFixedClasses {
    top: string;
    bottom: string;
    firstBottom: string;
    withoutBorderBottom: string;
}
export interface FixedColumnInfo {
    left?: number;
    right?: number;
    top?: number;
    bottom?: number;
    parent?: FixedColumnInfo;
    children?: string[];
    width?: number;
    height?: number;
    col?: BaseTableCol;
    index?: number;
    lastLeftFixedCol?: boolean;
    firstRightFixedCol?: boolean;
}
export type RowAndColFixedPosition = Map<string | number, FixedColumnInfo>;
export interface RecalculateColumnWidthFunc {
    (columns: BaseTableCol<TableRowData>[], thWidthList: {
        [colKey: string]: number;
    }, tableLayout: string, tableElmWidth: number): void;
}
