'use strict';

var types = require('../dashboard-visualisation/types.js');
var utils$3 = require('../scorecard/utils.js');
var Scorecard = require('../scorecard/Scorecard.js');
var ScorecardGroup = require('../scorecard-group/ScorecardGroup.js');
var utils$2 = require('../dashboard-list/utils.js');
var utils$1 = require('../../_charts/utils.js');
var utils = require('../dashboard-visualisation/utils.js');

const createDashboardSections = (dashboardDefinition, dashboardData, query, dashboardFeatureFlags, partialDate) => {
    return dashboardDefinition.sections.map((section) => {
        const { id, display: title, description } = section;
        const featureFlagVisTypeMap = utils.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 types.DashboardVisualisationType.LIST:
                    data = utils$2.default.createList(visDefinition, dashboardData);
                    break;
                case types.DashboardVisualisationType.SCORECARD:
                    hasScorecard = true;
                    data = new Scorecard.ScorecardVisualisation().withDefinition(visDefinition).withData(dashboardData).build();
                    break;
                case types.DashboardVisualisationType.SCORECARD_GROUP:
                    data = new ScorecardGroup.ScorecardGroupVisualisation().withDefinition(visDefinition).withData(dashboardData).build();
                    break;
                case types.DashboardVisualisationType.BAR:
                case types.DashboardVisualisationType.LINE:
                case types.DashboardVisualisationType.DONUT: {
                    data = utils$1.default.createChart(visDefinition, dashboardData, type);
                    break;
                }
                case types.DashboardVisualisationType.MATRIX_TIMESERIES:
                case types.DashboardVisualisationType.BAR_TIMESERIES:
                case types.DashboardVisualisationType.LINE_TIMESERIES: {
                    data = utils$1.default.createTimeseriesCharts(visDefinition, dashboardData, type, query, partialDate);
                    break;
                }
            }
            return {
                id: visId,
                title: display || '',
                description: visDescription || '',
                type,
                data,
                isEnabled: isEnabled ?? true,
            };
        });
        if (hasScorecard)
            utils$3.default.mergeScorecardsIntoGroup(visualisations, featureFlagVisTypeMap[types.DashboardVisualisationType.SCORECARD_GROUP]);
        return { id, title: title || '', description: description || '', visualisations };
    });
};

exports.createDashboardSections = createDashboardSections;
//# sourceMappingURL=utils.js.map
