'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var SummaryDataHelper = require('../../../../utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js');
var DataTableBuilder = require('../../../../utils/DataTableBuilder/DataTableBuilder.js');
var ReportBuilder = require('../../../../utils/TemplateBuilder/ReportBuilder/ReportBuilder.js');
var ParentChildDataBuilder = require('../../../../utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js');
var definitionUtils = require('../../../../utils/definitionUtils.js');

const buildListTable = (definition, columns, reportData, summariesData, reportQuery) => {
    const { specification } = definitionUtils.validateDefinition(definition);
    const collatedSummarries = new SummaryDataHelper.CollatedSummaryBuilder(specification, summariesData).collateDataTableSummaries();
    return new DataTableBuilder.DataTableBuilder(specification.fields)
        .withSummaries(collatedSummarries)
        .withHeaderOptions({
        columns: columns.value,
        reportQuery,
        interactive: true, // Always show sort actions in header
    })
        .buildTable(reportData);
};
const buildReport = (definition, columns, reportData, summariesData, reportQuery) => {
    return new ReportBuilder.ReportBuilder(definition.variant)
        .withData(reportData)
        .withSummaries(summariesData)
        .withColumns(columns.value)
        .withQuery(reportQuery)
        .build();
};
const buildParentChildReport = (definition, columns, reportData, childData, reportQuery) => {
    return new ParentChildDataBuilder.ParentChildDataBuilder(definition.variant)
        .withData(reportData)
        .withColumns(columns.value)
        .withChildColumns([])
        .withChildData(childData)
        .withQuery(reportQuery)
        .build();
};
const createReportTemplateData = (definition, columns, reportData, childData, summariesData, reportQuery) => {
    const { specification } = definitionUtils.validateDefinition(definition);
    const { template } = specification;
    switch (template) {
        case 'list':
        case 'summary-section':
        case 'summary':
        case 'list-section': {
            return buildReport(definition, columns, reportData, summariesData, reportQuery);
        }
        case 'parent-child':
        case 'parent-child-section': {
            return buildParentChildReport(definition, columns, reportData, childData, reportQuery);
        }
        default: {
            return buildListTable(definition, columns, reportData, summariesData, reportQuery);
        }
    }
};
var ReportTemplateUtils = {
    createReportTemplateData,
};

exports.createReportTemplateData = createReportTemplateData;
exports.default = ReportTemplateUtils;
//# sourceMappingURL=utils.js.map
