'use strict';

var SummaryDataTableBuilder = require('../../SummaryDataTableBuilder/SummaryDataTableBuilder.js');

class CollatedSummaryBuilder {
    summaries;
    specification;
    constructor(specification, summaries) {
        this.specification = specification;
        this.summaries = summaries;
    }
    pageSummaryTemplates = ['page-header', 'page-footer'];
    dataTableSummaryTemplates = [
        'section-footer',
        'section-header',
        'table-footer',
        'table-header',
    ];
    collatePageSummaries() {
        return this.collateAndMapToDataTable(this.pageSummaryTemplates);
    }
    collateDataTableSummaries() {
        return this.collate(this.dataTableSummaryTemplates);
    }
    collateAndMapToDataTable(summaryTemplates = []) {
        const collatedSummaries = this.collate(summaryTemplates);
        return this.mapToDataTables(collatedSummaries);
    }
    collate(summaryTemplates = this.pageSummaryTemplates) {
        const collatedSummaries = {};
        if (this.summaries) {
            this.summaries.forEach((summary) => {
                const { template } = summary;
                if (summaryTemplates.includes(template)) {
                    if (!collatedSummaries[template]) {
                        collatedSummaries[template] = [];
                    }
                    collatedSummaries[template].push(summary);
                }
            });
        }
        return collatedSummaries;
    }
    mapToDataTables(summaries) {
        const dataTables = {};
        Object.keys(summaries).forEach((summaryType) => {
            if (summaries[summaryType]) {
                dataTables[summaryType] = summaries[summaryType].map((summary) => {
                    return new SummaryDataTableBuilder.SummaryDataTableBuilder(summary, this.specification.sections).buildSummaryTable();
                });
            }
        });
        return dataTables;
    }
}

exports.CollatedSummaryBuilder = CollatedSummaryBuilder;
//# sourceMappingURL=SummaryDataHelper.js.map
