import { intl } from "../../../../../i18n/index.js";
import { findAllMeasures } from "../../../../utils/index.js";
const dataConfig = (spec, context)=>{
    const { advancedVSeed, vseed } = context;
    const measures = findAllMeasures(advancedVSeed.measureTree);
    const aggregationRules = measures.map((measure)=>({
            field: measure.id,
            aggregationType: 'SUM',
            indicatorKey: measure.id
        }));
    const dataConfigObj = {
        aggregationRules
    };
    const { totals } = vseed;
    if (totals) {
        const grandTotalLabel = intl.i18n`总计`;
        const subTotalLabel = intl.i18n`小计`;
        dataConfigObj.totals = {};
        if (totals.row) {
            const dimensionIds = (advancedVSeed.dimensionTree || []).filter((dim)=>'row' === dim.encoding).map((dim)=>dim.id);
            const rowSubDimensions = totals.row.subTotalsDimensions?.filter((dim)=>dimensionIds.includes(dim));
            const normalizedRowSubDimensions = totals.row.showSubTotals && (!rowSubDimensions || 0 === rowSubDimensions.length) ? dimensionIds.length > 0 ? [
                dimensionIds[0]
            ] : [] : rowSubDimensions;
            dataConfigObj.totals.row = {
                showGrandTotals: totals.row.showGrandTotals ?? false,
                showSubTotals: totals.row.showSubTotals ?? false,
                subTotalsDimensions: normalizedRowSubDimensions,
                grandTotalLabel,
                subTotalLabel
            };
        }
        if (totals.column) {
            const dimensionIds = (advancedVSeed.dimensionTree || []).filter((dim)=>'column' === dim.encoding).map((dim)=>dim.id);
            const columnSubDimensions = totals.column.subTotalsDimensions?.filter((dim)=>dimensionIds.includes(dim));
            const normalizedColumnSubDimensions = totals.column.showSubTotals && (!columnSubDimensions || 0 === columnSubDimensions.length) ? dimensionIds.length > 0 ? [
                dimensionIds[0]
            ] : [] : columnSubDimensions;
            dataConfigObj.totals.column = {
                showGrandTotals: totals.column.showGrandTotals ?? false,
                showSubTotals: totals.column.showSubTotals ?? false,
                subTotalsDimensions: normalizedColumnSubDimensions,
                grandTotalLabel,
                subTotalLabel
            };
        }
    }
    return {
        ...spec,
        dataConfig: dataConfigObj
    };
};
export { dataConfig };

//# sourceMappingURL=pivotDataConfig.js.map