import { groupBy } from "remeda";
import { datasetScatter } from "../dataset/index.js";
const playerScatter = (spec, context)=>{
    const { advancedVSeed } = context;
    const { datasetReshapeInfo, dimensions = [], chartType, encoding } = advancedVSeed;
    const baseConfig = advancedVSeed.config[chartType];
    const result = datasetScatter(spec, context);
    if (!baseConfig || !baseConfig.player) return result;
    const { player } = baseConfig;
    const fontFamily = player.fontFamily || baseConfig.fontFamily;
    const textSize = player.fontSize ?? 36;
    const id = datasetReshapeInfo[0].id;
    const { unfoldInfo } = datasetReshapeInfo[0];
    const { encodingPlayer } = unfoldInfo;
    const { autoPlay = true, interval = 1000, loop = false, position, railColor, trackColor, sliderHandleColor, sliderHandleBorderColor, startButtonColor, pauseButtonColor, backwardButtonColor, forwardButtonColor } = player;
    const { maxCount } = player;
    const dataGroups = groupBy(advancedVSeed.dataset, (item)=>item[encodingPlayer]);
    if (result.data && 'values' in result.data) result.data.values = [];
    const specs = Object.values(dataGroups).map((items)=>({
            data: {
                id: id,
                values: maxCount ? items.slice(0, maxCount) : items
            }
        }));
    const duration = interval;
    const exchangeDuration = 0.6 * interval;
    const dataKey = dimensions.filter((d)=>!encoding.player?.includes(d.id)).map((d)=>d.id);
    const padding = 12;
    return {
        ...result,
        dataKey,
        stackCornerRadius: void 0,
        animationUpdate: {
            bar: [
                {
                    type: 'update',
                    options: {
                        excludeChannels: [
                            'x'
                        ]
                    },
                    easing: 'linear',
                    duration
                },
                {
                    channel: [
                        'x'
                    ],
                    easing: 'circInOut',
                    duration: exchangeDuration
                }
            ],
            point: [
                {
                    type: 'update',
                    easing: 'linear',
                    duration
                }
            ],
            line: [
                {
                    type: 'update',
                    easing: 'linear',
                    duration
                }
            ],
            axis: {
                duration: exchangeDuration,
                easing: 'circInOut'
            }
        },
        animationEnter: {
            bar: [
                {
                    type: 'moveIn',
                    duration: exchangeDuration,
                    easing: 'circInOut',
                    options: {
                        direction: 'x',
                        orient: 'negative'
                    }
                }
            ]
        },
        animationExit: {
            bar: [
                {
                    type: 'fadeOut',
                    duration: exchangeDuration
                }
            ]
        },
        customMark: [
            {
                type: 'text',
                dataId: 'year',
                style: {
                    textBaseline: 'bottom',
                    fontSize: textSize,
                    textAlign: 'right',
                    fontFamily,
                    fontWeight: 600,
                    text: (datum)=>datum[encodingPlayer],
                    x: (datum, ctx)=>ctx.vchart.getChart().getCanvasRect()?.width - padding,
                    y: (datum, ctx)=>ctx.vchart.getChart().getCanvasRect()?.height - padding - textSize,
                    fill: 'grey',
                    fillOpacity: 0.5
                }
            }
        ],
        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 { playerScatter };

//# sourceMappingURL=playerScatter.js.map