import { datasetXY } from "../dataset/index.js";
const playerLine = (spec, context)=>{
    const { advancedVSeed } = context;
    const { datasetReshapeInfo, chartType } = advancedVSeed;
    const baseConfig = advancedVSeed.config[chartType];
    const result = datasetXY(spec, context);
    if (!baseConfig || !baseConfig.player) return result;
    const { player } = baseConfig;
    const id = datasetReshapeInfo[0].id;
    const { unfoldInfo } = datasetReshapeInfo[0];
    const { encodingX } = unfoldInfo;
    const { maxCount = false, autoPlay = true, interval, loop = false, position, railColor, trackColor, sliderHandleColor, sliderHandleBorderColor, startButtonColor, pauseButtonColor, backwardButtonColor, forwardButtonColor } = player;
    const uniqueXValues = Array.from(new Set(advancedVSeed.dataset.map((d)=>d[encodingX]))).sort((a, b)=>a > b ? 1 : -1);
    const step = 1;
    const specs = [];
    result.data = [
        {
            id: id,
            values: []
        }
    ];
    if (false === maxCount) for(let currentSize = 2; currentSize <= uniqueXValues.length; currentSize += step){
        const currentXValues = uniqueXValues.slice(0, currentSize);
        const frameData = advancedVSeed.dataset.filter((d)=>currentXValues.includes(d[encodingX]));
        specs.push({
            data: {
                id: id,
                values: frameData
            }
        });
    }
    else if (uniqueXValues.length <= maxCount) {
        const limitCount = uniqueXValues.length;
        for(let currentSize = 2; currentSize <= limitCount; currentSize += step){
            const currentXValues = uniqueXValues.slice(0, currentSize);
            const frameData = advancedVSeed.dataset.filter((d)=>currentXValues.includes(d[encodingX]));
            specs.push({
                data: {
                    id: id,
                    values: frameData
                }
            });
        }
    } else {
        const limitCount = maxCount;
        for(let currentSize = 2; currentSize < limitCount; currentSize += step){
            const currentXValues = uniqueXValues.slice(0, currentSize);
            const frameData = advancedVSeed.dataset.filter((d)=>currentXValues.includes(d[encodingX]));
            specs.push({
                data: {
                    id: id,
                    values: frameData
                }
            });
        }
        for(let i = 0; i <= uniqueXValues.length - limitCount; i += step){
            const currentXValues = uniqueXValues.slice(i, i + limitCount);
            const frameData = advancedVSeed.dataset.filter((d)=>currentXValues.includes(d[encodingX]));
            specs.push({
                data: {
                    id: id,
                    values: frameData
                }
            });
        }
    }
    const duration = interval;
    return {
        ...result,
        stackCornerRadius: void 0,
        animationUpdate: {
            duration
        },
        point: {
            visible: false
        },
        player: {
            visible: true,
            auto: autoPlay,
            interval: interval,
            loop: loop,
            alternate: false,
            position: 'middle',
            orient: position,
            type: 'discrete',
            specs,
            controller: {
                visible: true,
                start: {
                    visible: true,
                    order: 0,
                    style: {
                        fill: startButtonColor
                    }
                },
                pause: {
                    visible: true,
                    order: 1,
                    style: {
                        fill: pauseButtonColor
                    }
                },
                backward: {
                    visible: true,
                    order: 2,
                    style: {
                        fill: backwardButtonColor
                    }
                },
                forward: {
                    visible: true,
                    order: 3,
                    position: 'end',
                    style: {
                        fill: forwardButtonColor
                    }
                }
            },
            slider: {
                visible: true,
                railStyle: {
                    visible: true,
                    fill: railColor,
                    ['top' === position || 'bottom' === position ? 'height' : 'width']: 2
                },
                trackStyle: {
                    visible: true,
                    fill: trackColor,
                    ['top' === position || 'bottom' === position ? 'height' : 'width']: 2
                },
                handlerStyle: {
                    visible: true,
                    lineWidth: 2,
                    stroke: sliderHandleBorderColor,
                    fill: sliderHandleColor,
                    size: 9
                }
            }
        }
    };
};
export { playerLine };

//# sourceMappingURL=playerLine.js.map