import { DashboardVisualisationType } from '../dashboard-visualisation/types.js';
import ScorecardsUtils from '../scorecard/utils.js';
import { ScorecardVisualisation } from '../scorecard/Scorecard.js';
import { ScorecardGroupVisualisation } from '../scorecard-group/ScorecardGroup.js';
import DashboardListUtils from '../dashboard-list/utils.js';
import ChartUtils from '../../_charts/utils.js';
import { getFeatureFlagVisTypeMap } from '../dashboard-visualisation/utils.js';

const createDashboardSections = (dashboardDefinition, dashboardData, query, dashboardFeatureFlags, partialDate) => {
    return dashboardDefinition.sections.map((section) => {
        const { id, display: title, description } = section;
        const featureFlagVisTypeMap = getFeatureFlagVisTypeMap(dashboardFeatureFlags);
        let hasScorecard = false;
        const visualisations = section.visualisations.map((visDefinition) => {
            const { type, display, description: visDescription, id: visId } = visDefinition;
            const isEnabled = featureFlagVisTypeMap[type];
            let data;
            switch (type) {
                case DashboardVisualisationType.LIST:
                    data = DashboardListUtils.createList(visDefinition, dashboardData);
                    break;
                case DashboardVisualisationType.SCORECARD:
                    hasScorecard = true;
                    data = new ScorecardVisualisation().withDefinition(visDefinition).withData(dashboardData).build();
                    break;
                case DashboardVisualisationType.SCORECARD_GROUP:
                    data = new ScorecardGroupVisualisation().withDefinition(visDefinition).withData(dashboardData).build();
                    break;
                case DashboardVisualisationType.BAR:
                case DashboardVisualisationType.LINE:
                case DashboardVisualisationType.DONUT: {
                    data = ChartUtils.createChart(visDefinition, dashboardData, type);
                    break;
                }
                case DashboardVisualisationType.MATRIX_TIMESERIES:
                case DashboardVisualisationType.BAR_TIMESERIES:
                case DashboardVisualisationType.LINE_TIMESERIES: {
                    data = ChartUtils.createTimeseriesCharts(visDefinition, dashboardData, type, query, partialDate);
                    break;
                }
            }
            return {
                id: visId,
                title: display || '',
                description: visDescription || '',
                type,
                data,
                isEnabled: isEnabled ?? true,
            };
        });
        if (hasScorecard)
            ScorecardsUtils.mergeScorecardsIntoGroup(visualisations, featureFlagVisTypeMap[DashboardVisualisationType.SCORECARD_GROUP]);
        return { id, title: title || '', description: description || '', visualisations };
    });
};

export { createDashboardSections };
//# sourceMappingURL=utils.js.map
