import {TableProps as ElTableProps} from 'element-plus'

export interface TableColumn {
    field: string
    label?: string
    type?: string
    /**
     * 是否隐藏
     */
    hidden?: boolean
    children?: TableColumn[]
    slots?: {
        default?: (...args: any[]) => JSX.Element | JSX.Element[] | null
        header?: (...args: any[]) => JSX.Element | null
    }
    index?: number | ((index: number) => number)
    columnKey?: string
    width?: string | number
    minWidth?: string | number
    fixed?: boolean | 'left' | 'right'
    renderHeader?: (...args: any[]) => JSX.Element | null
    // sortable?: boolean
    sortMethod?: (...args: any[]) => number
    sortBy?: string | string[] | ((...args: any[]) => string | string[])
    sortOrders?: (string | null)[]
    resizable?: boolean
    formatter?: (...args: any[]) => any
    showOverflowTooltip?: boolean
    align?: 'left' | 'center' | 'right'
    headerAlign?: 'left' | 'center' | 'right'
    className?: string
    labelClassName?: string
    selectable?: (...args: any[]) => boolean
    reserveSelection?: boolean
    filters?: Array<{ text: string; value: string }>
    filterPlacement?: string
    filterMultiple?: boolean
    filterMethod?: (...args: any[]) => boolean
    filteredValue?: string[]

    [key: string]: any
}

export interface TableSlotDefault {
    row: Recordable
    column: TableColumn
    $index: number

    [key: string]: any
}

export interface Pagination {
    small?: boolean
    background?: boolean
    pageSize?: number
    defaultPageSize?: number
    total?: number | string
    pageCount?: number
    pagerCount?: number
    currentPage?: number
    defaultCurrentPage?: number
    layout?: string
    pageSizes?: number[]
    popperClass?: string
    prevText?: string
    nextText?: string
    disabled?: boolean
    hideOnSinglePage?: boolean
}

export interface TableSetProps {
    field: string
    path: string
    value: any
}

export interface TableProps extends Omit<Partial<ElTableProps<any[]>>, 'data'> {
    pageSize?: number
    currentPage?: number
    showAction?: boolean
    // 是否所有的超出隐藏，优先级低于schema中的showOverflowTooltip,
    showOverflowTooltip?: boolean
    // 表头
    columns?: TableColumn[]
    // 是否展示分页
    pagination?: Pagination | undefined
    // 仅对 type=selection 的列有效，类型为 Boolean，为 true 则会在数据更新之后保留之前选中的数据（需指定 row-key）
    reserveSelection?: boolean
    // 加载状态
    loading?: boolean
    // 是否叠加索引
    reserveIndex?: boolean
    // 对齐方式
    align?: 'left' | 'center' | 'right'
    // 表头对齐方式
    headerAlign?: 'left' | 'center' | 'right'
    imagePreview?: string[]
    videoPreview?: string[]
    sortable?: boolean
    data?: Recordable
}
