import { isNumber } from "remeda";
import { intl } from "../../../../../i18n/index.js";
import { createFormatterByMeasure, findMeasureById } from "../../../../utils/index.js";
const pivotIndicators = (spec, context)=>{
    const { advancedVSeed } = context;
    const { measureTree, datasetReshapeInfo } = advancedVSeed;
    const { foldInfo } = datasetReshapeInfo[0];
    const hasRow = spec?.rows?.length > 0;
    const foldMapValues = Object.values(foldInfo.foldMap);
    return {
        ...spec,
        indicatorTitle: intl.i18n`指标名称`,
        indicatorsAsCol: hasRow,
        hideIndicatorName: hasRow,
        indicators: [
            {
                cellType: 'text',
                indicatorKey: foldInfo.measureValue,
                title: foldMapValues.length > 1 ? '' : foldMapValues[0],
                width: 'auto',
                format: fieldFormat(measureTree, foldInfo)
            }
        ]
    };
};
const fieldFormat = (measureTree, foldInfo)=>(value, col, row, table)=>{
        if (!isNumber(col) || !isNumber(row) || !table) return value;
        const datum = table.getCellOriginRecord(col, row);
        if (!datum[0]) return value;
        const { measureId: foldMeasureId } = foldInfo;
        const measureId = datum[0][foldMeasureId];
        const measure = findMeasureById(measureTree, measureId);
        const formatter = createFormatterByMeasure(measure);
        return formatter(value);
    };
export { pivotIndicators };

//# sourceMappingURL=pivotIndicators.js.map