import { StreamLight } from "@visactor/vchart";
import { VScreenAnimationType } from "./types.js";
import { allowAnimation, getPrimaryEffect, toMs } from "./utils/index.js";
import { fadeInBar, getGroupCountFromSpec, getLoopResult, groupHighLightBar, growBar, isHorizontalBar, moveInBar, moveOutBar, transform2VChartColor } from "./utils/bar.js";
const barAppear = (config, chartType)=>{
    if (!allowAnimation(config)) return false;
    const effect = getPrimaryEffect(config);
    const configByType = effect === VScreenAnimationType.growth ? growBar(chartType) : effect === VScreenAnimationType.load ? fadeInBar() : {};
    return {
        bar: {
            ...configByType,
            easing: config?.ease,
            duration: toMs(config?.duration ?? 1)
        }
    };
};
const barUpdate = (config, chartType, spec)=>{
    if (!allowAnimation(config)) return false;
    const effect = getPrimaryEffect(config);
    const configByType = effect === VScreenAnimationType.moveIn ? moveInBar(chartType, spec, true) : {};
    return {
        bar: {
            ...configByType,
            easing: config?.ease,
            duration: toMs(config?.duration ?? 1)
        }
    };
};
const barLoop = (config, ignoreFirstNormal, chartType, spec)=>{
    if (!config?.enable) return false;
    const interval = config.interval ?? 0;
    const startTime = ignoreFirstNormal ? toMs(interval) : 0;
    const loop = config.loop;
    const atmosphere = config.atmosphere;
    const loopEffect = getPrimaryEffect(loop);
    const result = [];
    let loopDuration = loopEffect === VScreenAnimationType.none ? 0 : 1;
    const atmosphereDuration = loopEffect === VScreenAnimationType.none ? 2 : 1;
    if (loopEffect === VScreenAnimationType.highLight && loop) {
        const groupDuration = 0.7;
        const stopDuration = 0.85;
        loopDuration = loop.duration ?? groupDuration * getGroupCountFromSpec(spec).groupCount + stopDuration;
        result.push(...groupHighLightBar(startTime, loop, loopDuration, interval, atmosphereDuration, isHorizontalBar(chartType), spec));
    } else if (loop) result.push({
        ...getLoopResult(loopEffect, chartType, spec),
        startTime,
        easing: loop.ease,
        duration: toMs(loopDuration),
        delayAfter: toMs(interval + atmosphereDuration),
        loop: true,
        controlOptions: {
            immediatelyApply: false
        }
    });
    if (atmosphere?.ease || atmosphere?.color) result.push({
        loop: true,
        startTime,
        delay: toMs(loopDuration),
        delayAfter: toMs(interval),
        duration: toMs(atmosphereDuration),
        easing: atmosphere.ease,
        custom: StreamLight,
        customParameters: {
            isHorizontal: isHorizontalBar(chartType),
            attribute: {
                fill: transform2VChartColor(atmosphere.color),
                blur: 0,
                shadowColor: 'rgba(0,0,0,0)'
            }
        }
    });
    return result.length > 0 ? {
        bar: result
    } : false;
};
const barExit = (config, chartType)=>{
    if (!allowAnimation(config)) return false;
    if (getPrimaryEffect(config) !== VScreenAnimationType.moveIn) return {};
    return {
        bar: {
            ...moveOutBar(chartType),
            duration: 1000
        }
    };
};
export { barAppear, barExit, barLoop, barUpdate };

//# sourceMappingURL=bar.js.map