import { FoldMeasureId } from "../../../../../dataReshape/constant.js";
const reverseStackCornerRadius = (cornerRadius)=>{
    if (!Array.isArray(cornerRadius)) return cornerRadius;
    const [topLeft = 0, topRight = 0, bottomRight = 0, bottomLeft = 0] = cornerRadius;
    return [
        bottomRight,
        bottomLeft,
        topLeft,
        topRight
    ];
};
const mergeStackCornerRadius = (cornerRadius)=>{
    if (!Array.isArray(cornerRadius)) return cornerRadius;
    const [topLeft = 0, topRight = 0, bottomRight = 0, bottomLeft = 0] = cornerRadius;
    return [
        Math.max(topLeft, bottomRight),
        Math.max(topRight, bottomLeft),
        Math.max(bottomRight, topLeft),
        Math.max(bottomLeft, topRight)
    ];
};
const getStackRangeCornerRadius = (cornerRadius, datum)=>{
    const stackStart = datum?.['__VCHART_STACK_START'];
    const stackEnd = datum?.['__VCHART_STACK_END'];
    if ('number' != typeof stackStart || 'number' != typeof stackEnd) return;
    const hasPositivePart = stackStart > 0 || stackEnd > 0;
    const hasNegativePart = stackStart < 0 || stackEnd < 0;
    if (hasPositivePart && hasNegativePart) return mergeStackCornerRadius(cornerRadius);
    if (hasPositivePart) return cornerRadius;
    if (hasNegativePart) return reverseStackCornerRadius(cornerRadius);
    return 0;
};
const stackCornerRadius_stackCornerRadius = (spec, context)=>{
    const { advancedVSeed, vseed } = context;
    const { chartType } = vseed;
    const stackCornerRadius = advancedVSeed.config?.[chartType]?.stackCornerRadius;
    if ('dualAxis' === chartType && 'bar' !== spec.type) return spec;
    return {
        ...spec,
        stackCornerRadius: (_, datum)=>{
            const stackRangeCornerRadius = getStackRangeCornerRadius(stackCornerRadius, datum);
            if (void 0 !== stackRangeCornerRadius) return stackRangeCornerRadius;
            const value = datum?.[datum?.[FoldMeasureId]];
            if (value > 0) return stackCornerRadius;
            if (value < 0) return reverseStackCornerRadius(stackCornerRadius);
            return 0;
        }
    };
};
export { stackCornerRadius_stackCornerRadius as stackCornerRadius };

//# sourceMappingURL=stackCornerRadius.js.map