import { allowAnimation } from "./utils/index.js";
import { barAppear, barExit, barLoop, barUpdate } from "./bar.js";
import { lineOrAreaAppear, lineOrAreaExit, lineOrAreaLoop, lineOrAreaUpdate } from "./lineOrArea.js";
import { pieAppear, pieEnter, pieExit, pieLoop, pieUpdate } from "./pie.js";
import { radarAppear, radarExit, radarLoop, radarUpdate } from "./radar.js";
import { scatterAppear, scatterExit, scatterLoop, scatterUpdate } from "./scatter.js";
const barFamily = [
    'bar',
    'barPercent',
    'barParallel',
    'column',
    'columnPercent',
    'columnParallel'
];
const pieFamily = [
    'pie',
    'donut',
    'rose',
    'roseParallel'
];
const lineFamily = [
    'line',
    'area',
    'areaPercent'
];
const animation = (spec, context)=>{
    const { chartType, config } = context.advancedVSeed;
    const nextSpec = {
        ...spec
    };
    const animationChartType = chartType;
    const chartConfig = config?.[animationChartType];
    const animationConfig = chartConfig?.animation;
    if (!animationConfig?.enable) {
        nextSpec.animation = false;
        return nextSpec;
    }
    const params = animationConfig.params;
    const appear = params?.appear;
    const ignoreFirstNormal = allowAnimation(appear);
    let animationAppear = false;
    let animationNormal = false;
    let animationEnter = false;
    let animationUpdate = false;
    let animationExit = false;
    if (barFamily.includes(chartType)) {
        const barParams = params;
        animationAppear = barAppear(barParams?.appear, chartType);
        animationNormal = barLoop(barParams?.loop, ignoreFirstNormal, chartType, nextSpec);
        animationEnter = barUpdate(barParams?.update, chartType, nextSpec);
        animationUpdate = animationEnter;
        animationExit = barExit(barParams?.update, chartType);
    } else if (lineFamily.includes(chartType)) {
        const lineParams = params;
        animationAppear = lineOrAreaAppear(lineParams?.appear);
        animationNormal = lineOrAreaLoop(lineParams?.loop, ignoreFirstNormal);
        animationEnter = lineOrAreaUpdate(lineParams?.update);
        animationUpdate = animationEnter;
        animationExit = lineOrAreaExit(lineParams?.update);
    } else if (pieFamily.includes(chartType)) {
        const pieParams = params;
        animationAppear = pieAppear(pieParams?.appear, chartType);
        animationNormal = pieLoop(pieParams?.loop, ignoreFirstNormal);
        animationEnter = pieEnter(pieParams?.update, pieParams?.loop);
        animationUpdate = pieUpdate(pieParams?.update);
        animationExit = pieExit();
    } else if ('scatter' === chartType) {
        const scatterParams = params;
        animationAppear = scatterAppear(scatterParams?.appear);
        animationNormal = scatterLoop(scatterParams?.loop, ignoreFirstNormal);
        animationEnter = scatterUpdate(scatterParams?.update);
        animationUpdate = animationEnter;
        animationExit = scatterExit(scatterParams?.update);
    } else if ('radar' === chartType) {
        const radarParams = params;
        animationAppear = radarAppear(radarParams?.appear);
        animationNormal = radarLoop(radarParams?.loop, ignoreFirstNormal);
        animationEnter = radarUpdate(radarParams?.update);
        animationUpdate = animationEnter;
        animationExit = radarExit(radarParams?.update);
    }
    return {
        ...nextSpec,
        animation: true,
        animationAppear,
        animationNormal,
        animationEnter,
        animationUpdate,
        animationExit
    };
};
export { animation };

//# sourceMappingURL=animation.js.map