import { setUnitOnValue, mapUnitToSymbol } from '../../../utils/Dashboards/VisualisationUnitHelper.js';

class ChartLabelsHelper {
    /**
     * Gets the axis labels
     *
     * @param {ChartMeasure} measures
     * @memberof ChartLabelsHelper
     */
    getLabels = (measures) => {
        return measures.map((col) => {
            const { unit, display } = col;
            return setUnitOnValue(display || '', mapUnitToSymbol(unit));
        });
    };
    /**
     * Gets the dataset label
     * Dataset label = the label seen in the legend
     *
     * @memberof ChartLabels
     */
    getDatasetLabel = (keys, row) => {
        return keys
            .map((key) => {
            // Only set the label if there is more than one key
            const label = key.display && keys.length > 1 ? `${key.display}: ` : '';
            // Use the row/col value as the value
            const value = row[key.id]?.raw ?? '';
            return `${label}${value}`;
        })
            .join(', ');
    };
    /**
     * Gets the axis labels when the column values are used
     *
     * @param {DashboardDataResponse[][]} groups
     * @param {string} axisId
     * @memberof ChartLabelsHelper
     */
    getListLabels = (groups, axisId, unitSymbol) => {
        const allLabels = groups.flatMap((gd) => {
            return gd.map((row) => {
                const field = row[axisId];
                let label = '';
                if (field) {
                    label = setUnitOnValue(field.raw || '', unitSymbol);
                }
                return label;
            });
        });
        return Array.from(new Set(allLabels));
    };
}

export { ChartLabelsHelper as default };
//# sourceMappingURL=ChartLabels.js.map
