import { toCurrency } from 'src/filters';

export function getTotal(rows, key, opts = {}) {
    const { currency, cb } = opts;
    const total = rows.reduce((acc, row) => acc + +(cb ? cb(row) : row[key] || 0), 0);

    return currency
        ? toCurrency(total, currency == 'default' ? undefined : currency)
        : total;
}
