import { DynamicProps } from "@/types/utils";
import { ElTable } from "element-plus";

// 表格行内容设置
export interface TableColumns {
    prop: string
    label: string
    slot?: boolean
    slotName?: string
    slotHeader?: boolean
    width?: number
    minWidth?: number | string
    // 居中
    align?: "left" | "center"
    // 当内容过长被隐藏时显示 tooltip
    showOverflowTooltip?: boolean
    // 
    resizable?: boolean
    // 固定列
    fixed?: string | boolean
}

// 表格参数
export interface BaseTableProps {
    // 列表
    columns: TableColumns[]
    // 数据
    dataSource: Recordable[]
    // 边框
    border?: boolean
    // loading加载
    loading?: boolean;
    // 最大高度
    maxHeight?: number
    // 高度
    height?: number
    // 复选框多选
    rowSelection?: boolean
    // 行数据的 Key，用来优化 Table 的渲染
    rowKey?: string
    // 总是显示滚动条
    scrollbarAlwaysOn?: boolean
}

// 用于useTable的可选参数
export type TableProps = Partial<DynamicProps<BaseTableProps>>;

// table事件类型
export interface TableActionType {
    setProps: (props: Partial<BaseTableProps>) => void
    setColumns: (columns: TableColumns[]) => void
    setDataSource: (dataSource: Recordable[]) => void
    getDataSource: <T = Recordable>() => T[]
    setLoading: (loading: boolean) => void
    getSelectRows: <T = Recordable>() => Promise<T[]> | T[];
    clearSelectedRow: () => void;
    tableElRef?: any
}

// useTable注册的类型
export type RegisterFn = (formInstance: TableActionType) => void;

// 定义useTable返回的参数类型
export type UseTableReturnType = [RegisterFn, TableActionType];

// 表格的ref节点
export type TableRef = InstanceType<typeof ElTable>
