import { CollatedSummaryBuilder } from '../../../../utils/TemplateBuilder/SummaryDataHelper/SummaryDataHelper.js';
import { DataTableBuilder } from '../../../../utils/DataTableBuilder/DataTableBuilder.js';
import { ReportBuilder } from '../../../../utils/TemplateBuilder/ReportBuilder/ReportBuilder.js';
import { ParentChildDataBuilder } from '../../../../utils/TemplateBuilder/ParentChildDataBuilder/ParentChildDataBuilder.js';
import { validateDefinition } from '../../../../utils/definitionUtils.js';

const buildListTable = (definition, columns, reportData, summariesData, reportQuery) => {
    const { specification } = validateDefinition(definition);
    const collatedSummarries = new CollatedSummaryBuilder(specification, summariesData).collateDataTableSummaries();
    return new 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(definition.variant)
        .withData(reportData)
        .withSummaries(summariesData)
        .withColumns(columns.value)
        .withQuery(reportQuery)
        .build();
};
const buildParentChildReport = (definition, columns, reportData, childData, reportQuery) => {
    return new ParentChildDataBuilder(definition.variant)
        .withData(reportData)
        .withColumns(columns.value)
        .withChildColumns([])
        .withChildData(childData)
        .withQuery(reportQuery)
        .build();
};
const createReportTemplateData = (definition, columns, reportData, childData, summariesData, reportQuery) => {
    const { specification } = 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,
};

export { createReportTemplateData, ReportTemplateUtils as default };
//# sourceMappingURL=utils.js.map
