import { VScreenAnimationType } from "./types.js";
import { allowLineOrAreaAnimation, atmospherePoint } from "./utils/index.js";
import { transform2VChartColor } from "./utils/bar.js";
import { clipInLine, growthTopLine, growthTopPoint } from "./utils/lineOrArea.js";
import { StreamLight } from "@visactor/vchart";
const lineOrAreaAppear = (config)=>{
    if (!config || !allowLineOrAreaAnimation(config)) return false;
    const { effects, ease, duration } = config;
    const effect = effects?.[0];
    const durationMs = (duration ?? 1) * 1000;
    let lineOrAreaConfigByType = {};
    let pointConfigByType = {};
    if (effect === VScreenAnimationType.growth) {
        lineOrAreaConfigByType = growthTopLine();
        pointConfigByType = growthTopPoint();
    } else if (effect === VScreenAnimationType.load) lineOrAreaConfigByType = clipInLine();
    return {
        line: {
            ...lineOrAreaConfigByType,
            easing: ease,
            duration: durationMs
        },
        area: {
            ...lineOrAreaConfigByType,
            easing: ease,
            duration: durationMs
        },
        point: {
            ...pointConfigByType,
            easing: ease,
            duration: durationMs
        }
    };
};
const lineOrAreaLoop = (config, ignoreFirstNormal)=>{
    if (!config?.enable) return false;
    const { loop, atmosphere, interval = 5 } = config;
    const totalDuration = 2;
    const startTime = ignoreFirstNormal ? 1000 * interval : 0;
    const lineOrAreaResult = [];
    const pointResult = [];
    const { effects: loopEffects = [], ease: loopEase = 'linear' } = loop ?? {};
    const loopEffect = loopEffects[0] ?? VScreenAnimationType.none;
    const loopDuration = loopEffect === VScreenAnimationType.none ? 0 : totalDuration / 2;
    const atmosphereDuration = loopEffect === VScreenAnimationType.none ? totalDuration : totalDuration / 2;
    const timeLineConfig = {
        startTime,
        easing: loopEase,
        duration: 1000 * loopDuration,
        delayAfter: (interval + atmosphereDuration) * 1000,
        loop: true,
        controlOptions: {
            immediatelyApply: false
        }
    };
    if (loopEffect === VScreenAnimationType.growth) lineOrAreaResult.push({
        ...growthTopLine(),
        ...timeLineConfig
    });
    else if (loopEffect === VScreenAnimationType.load) lineOrAreaResult.push({
        ...clipInLine(),
        ...timeLineConfig
    });
    const { ease: atmosphereEase, effect: atmosphereEffect, color: atmosphereColor } = atmosphere ?? {};
    const atmosphereLineOrAreaResult = {
        loop: true,
        startTime,
        delay: 1000 * loopDuration,
        delayAfter: 1000 * interval,
        duration: 1000 * atmosphereDuration,
        easing: atmosphereEase,
        custom: StreamLight,
        customParameters: (...args)=>({
                streamLength: 20,
                attribute: {
                    stroke: transform2VChartColor(atmosphereColor),
                    strokeOpacity: 0.8,
                    lineWidth: args[1].attribute?.lineWidth ?? 1
                }
            })
    };
    lineOrAreaResult.push(atmosphereLineOrAreaResult);
    const atmospherePointResult = {
        loop: true,
        startTime,
        delayAfter: (interval + atmosphereDuration) * 1000,
        duration: 1000 * atmosphereDuration,
        easing: atmosphereEase,
        ...atmospherePoint(atmosphereEffect)
    };
    pointResult.push(atmospherePointResult);
    return {
        line: lineOrAreaResult,
        area: lineOrAreaResult,
        point: pointResult
    };
};
const lineOrAreaUpdate = (config)=>{
    if (!config || !allowLineOrAreaAnimation(config)) return false;
    const { ease, duration } = config;
    const durationMs = (duration ?? 1) * 1000;
    return {
        line: {
            easing: ease,
            duration: durationMs
        },
        area: {
            easing: ease,
            duration: durationMs
        },
        point: {
            easing: ease,
            duration: durationMs
        }
    };
};
const lineOrAreaExit = (config)=>{
    if (!config || !allowLineOrAreaAnimation(config)) return false;
    const { ease, duration } = config;
    const durationMs = (duration ?? 1) * 1000;
    return {
        line: {
            easing: ease,
            duration: durationMs
        },
        point: {
            easing: ease,
            duration: durationMs
        },
        area: {
            easing: ease,
            duration: durationMs
        }
    };
};
export { lineOrAreaAppear, lineOrAreaExit, lineOrAreaLoop, lineOrAreaUpdate };

//# sourceMappingURL=lineOrArea.js.map