import { DashboardVisualisationType } from '../../../_dashboards/dashboard-visualisation/types.js';
import { Chart } from '../Chart.js';
import DoughnutChartSchemas from './validate.js';

/* eslint-disable prefer-destructuring */
class DoughnutChart extends Chart {
    definition;
    measures;
    keys;
    init = () => {
        this.measures = this.definition.columns.measures;
        this.keys = this.definition.columns.keys || [];
        this.initUnit(this.measures);
    };
    withDefinition = (definition) => {
        this.definition = DoughnutChartSchemas.DoughnutSchema.parse(definition);
        this.init();
        return this;
    };
    build = () => {
        this.createDatasets(this.measures, this.keys);
        this.augmentDataset();
        this.setBespokeOptions();
        return {
            type: DashboardVisualisationType.DONUT,
            options: {
                unit: this.unit,
            },
            data: {
                labels: this.labels,
                datasets: this.datasets,
                config: this.config,
            },
        };
    };
    augmentDataset = () => {
        const hexColours = this.chartColoursHelper.getHexPallette();
        this.datasets = this.datasets.map((set) => {
            return {
                ...set,
                backgroundColor: [...hexColours, ...hexColours],
                borderColor: '#FFFFFF',
                hoverOffset: 4,
                datalabels: {
                    anchor: 'center',
                    borderWidth: 0,
                },
            };
        });
    };
    setBespokeOptions = () => {
        const cutout = this.datasets.length === 1 ? '50%' : '20%';
        this.config = {
            ...this.config,
            cutout,
        };
    };
}

export { DoughnutChart, DoughnutChart as default };
//# sourceMappingURL=DoughnutChart.js.map
