import { DEFAULT_DUAL_CHART_TYPE, execPipeline } from "../../../../utils/index.js";
import { FoldPrimaryMeasureValue } from "../../../../../dataReshape/constant.js";
const series = (pipeByAxis, pipes)=>{
    const result = {
        type: 'common',
        padding: 0,
        region: [
            {
                clip: true
            }
        ]
    };
    return (_, context)=>{
        const { advancedVSeed } = context;
        const { datasetReshapeInfo, reshapeMeasures = [] } = advancedVSeed;
        const { foldInfoList = [], index } = datasetReshapeInfo[0];
        result.series = foldInfoList.map((foldInfo)=>{
            const measureId = Object.keys(foldInfo.foldMap)[0];
            const axisType = foldInfo.measureValue === `${FoldPrimaryMeasureValue}${index}` ? 'primary' : 'secondary';
            const measure = (reshapeMeasures[index] ?? []).find((m)=>m.id === measureId);
            const options = {
                axisType,
                chartType: measure?.chartType ?? ('primary' === axisType ? DEFAULT_DUAL_CHART_TYPE.primary : DEFAULT_DUAL_CHART_TYPE.secondary),
                foldInfo
            };
            const pipeline = [
                ...pipeByAxis.map((p)=>p(options)),
                ...pipes
            ];
            return execPipeline(pipeline, context, {});
        });
        return result;
    };
};
const seriesDualAxis = (pipeByAxis, pipes)=>{
    const result = {
        type: 'common',
        padding: 0,
        labelLayout: 'region',
        region: [
            {
                clip: true
            }
        ]
    };
    return (_, context)=>{
        const { advancedVSeed } = context;
        const { datasetReshapeInfo, dataset, reshapeMeasures = [] } = advancedVSeed;
        result.series = dataset.map((d, index)=>{
            const seriesContext = {
                ...context,
                advancedVSeed: {
                    ...advancedVSeed,
                    dataset: d
                }
            };
            const foldInfo = datasetReshapeInfo[0].foldInfoList[index];
            const measureId = Object.keys(foldInfo.foldMap)[0];
            const axisType = foldInfo.measureValue === FoldPrimaryMeasureValue ? 'primary' : 'secondary';
            const measure = (reshapeMeasures[0] ?? []).find((m)=>m.id === measureId);
            const options = {
                axisType,
                chartType: measure?.chartType ?? ('primary' === axisType ? DEFAULT_DUAL_CHART_TYPE.primary : DEFAULT_DUAL_CHART_TYPE.secondary),
                foldInfo
            };
            const pipeline = [
                ...pipeByAxis.map((p)=>p(options)),
                ...pipes
            ];
            return execPipeline(pipeline, seriesContext, {});
        });
        return result;
    };
};
export { series, seriesDualAxis };

//# sourceMappingURL=series.js.map