import {PaginationProps, Table, TableProps} from "ant-design-vue";
import {TableRowSelection} from "ant-design-vue/lib/table/interface";
import {Ref, UnwrapRef} from "vue";
import {ColumnType} from "ant-design-vue/es/table/interface";
import {ComponentSlots} from "vue-component-type-helpers";
import {FormProMaxItemOptions, FormProMaxProps} from "@/types/components/form";
import {PageParams, PageResult} from "@/types/hooks/useTableProMax.ts";


export type TableProMaxColumnType<T extends BaseTableRowRecord> = Omit<ColumnType<T>, 'dataIndex'> & {
    dataIndex: keyof T | string | string[] | number | number[];
}


export type TableProMaxProps<
    T extends BaseTableRowRecord = {},
    P extends { [key: string]: any } = {}
> = Partial<Omit<TableProps<T>, "dataSource" | 'pagination' | 'loading' | 'rowKey' | 'columns'>> & {
    rowKey?: keyof T,
    columns?: TableProMaxColumnType<T>[],
    searchFormProps?: Omit<FormProMaxProps<P>, 'formItems'>
    searchFormOptions?: FormProMaxItemOptions<P> | Ref<FormProMaxItemOptions<P>> | UnwrapRef<FormProMaxItemOptions<P>>,
    defaultSearchParams?: { [key in keyof P | string]: any };
    requestAuto?: boolean,
    requestApi: RequestApiType<T, P>,
    requestError?: (errorMsg: any) => void,
    dataCallback?: (data: T[]) => T[],
    isPagination?: boolean,
    paginationProps?: TableProMaxPaginationProps,
    isSelection?: boolean,
    selectionProps?: TableProMaxRowSelect<T>,
    isPrinter?: boolean,
    needIndex?: boolean
}

export type TableProMaxSlots<T> = ComponentSlots<typeof Table> & {
    tableHeader: (scope: { selectKeys: string[], selectRows: T[] }) => any,
    tableHeaderRight: (scope: { selectKeys: string[], selectRows: T[] }) => any,
}

export type RequestApiType<T extends BaseTableRowRecord, P extends {
    [key: string]: any
} = {}> = (params: P | PageParams<P>) => Promise<JsonResult<T[] | PageResult<T>>>;

export type TableProMaxPaginationProps = Partial<Omit<PaginationProps, "current" | "pageSize" | "total">>;

export type TableProMaxRowSelect<T extends BaseTableRowRecord> = TableRowSelection<T>;

export interface BaseTableRowRecord {
    snowFlakeId?: string;
    createUserName?: string;
    createTime?: Date | string;
    updateUserName?: string;
    updateTime?: Date | string
}
