import { VNode } from 'vue';
import type { TableColumnCtx } from 'element-plus';
interface SummaryMethodProps<T = any> {
    columns: TableColumnCtx<T>[];
    data: T[];
}
export const getSummariesWrapper = <T = any>(selectProps: string[], names: string[] = ['小计']) => {
    return (params: SummaryMethodProps<T>) => {
        const { columns, data } = params;
        const sums: (string | VNode)[] = [];
        columns.forEach((column, index) => {
            if (index === 0) {
                sums[index] = h('div', { style: { textDecoration: 'none' } }, names);
                return;
            }
            if (!selectProps.includes(column.property)) return;
            const values = data.map(item => Number(item[column.property]));
            if (!values.every(value => Number.isNaN(value))) {
                sums[index] = `${values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!Number.isNaN(value)) {
                        return prev + curr;
                    } else {
                        return prev;
                    }
                }, 0)}`;
            } else {
                sums[index] = '';
            }
        });
        return sums;
    };
};
