import { ChartTypeEnum } from "../../../../utils/index.js";
import { VScreenAnimationType } from "./types.js";
import { allowAnimation, getPrimaryEffect } from "./utils/index.js";
import { radialPie, scalePie } from "./utils/pie.js";
const pieAppear = (config, chartType)=>{
    if (!config || !allowAnimation(config)) return false;
    const { effects, ease, duration } = config;
    const effect = effects?.[0];
    const durationMs = (duration ?? 1) * 1000;
    let configByType = {};
    if (effect === VScreenAnimationType.radial) configByType = radialPie();
    else if (effect === VScreenAnimationType.scale) configByType = scalePie();
    const result = {
        pie: {
            ...configByType,
            easing: ease,
            duration: durationMs
        },
        rose: {
            ...configByType,
            easing: ease,
            duration: durationMs
        }
    };
    if (chartType === ChartTypeEnum.Rose && effect === VScreenAnimationType.radial) result.preset = 'growAngle';
    return result;
};
const pieUpdate = (config)=>{
    if (!config || !allowAnimation(config)) return false;
    const { ease, duration } = config;
    const durationMs = (duration ?? 1) * 1000;
    return {
        pie: {
            easing: ease,
            duration: durationMs
        },
        rose: {
            easing: ease,
            duration: durationMs
        }
    };
};
const pieEnter = (config, atmosphereConfig)=>{
    if (!config || !allowAnimation(config)) return false;
    const { ease, duration } = config;
    const durationMs = (duration ?? 1) * 1000;
    let configByType = {};
    if (atmosphereConfig?.enable && getPrimaryEffect(atmosphereConfig.loop) === VScreenAnimationType.enlarge) configByType = {
        type: 'fadeIn'
    };
    return {
        pie: {
            easing: ease,
            duration: durationMs
        },
        rose: {
            ...configByType,
            easing: ease,
            duration: durationMs
        }
    };
};
const pieLoop = (config, ignoreFirstNormal)=>{
    if (!config?.enable) return false;
    const { loop, interval = 0 } = config;
    let loopResult = {};
    const startTime = ignoreFirstNormal ? 1000 * interval : 0;
    const { effects: loopEffects = [], ease: loopEase } = loop ?? {};
    const loopDuration = 1;
    const loopEffect = loopEffects[0];
    if (loopEffect === VScreenAnimationType.enlarge) loopResult = [
        {
            channel: {
                outerRadius: {
                    from: (...p)=>p[1].attribute.outerRadius,
                    to: (...p)=>p[1].attribute.outerRadius + 10
                }
            },
            startTime,
            oneByOne: 1000 * loopDuration,
            duration: loopDuration / 2 * 1000,
            loop: true,
            easing: loopEase,
            delayAfter: loopDuration / 2 * 1000 + 1000 * interval,
            controlOptions: {
                immediatelyApply: false
            }
        },
        {
            channel: {
                outerRadius: {
                    from: (...p)=>p[1].attribute.outerRadius + 10,
                    to: (...p)=>p[1].attribute.outerRadius
                }
            },
            startTime,
            oneByOne: 1000 * loopDuration,
            duration: loopDuration / 2 * 1000,
            easing: loopEase,
            delay: loopDuration / 2 * 1000,
            delayAfter: 1000 * interval,
            loop: true,
            controlOptions: {
                immediatelyApply: false
            }
        }
    ];
    else if (loopEffect === VScreenAnimationType.relocate) {
        const offset = 10;
        loopResult = [
            {
                channel: {
                    x: {
                        from: (...p)=>p[1].attribute.x,
                        to: (...p)=>{
                            const angle = (p[1].attribute.startAngle + p[1].attribute.endAngle) / 2;
                            return p[1].attribute.x + offset * Math.cos(angle);
                        }
                    },
                    y: {
                        from: (...p)=>p[1].attribute.y,
                        to: (...p)=>{
                            const angle = (p[1].attribute.startAngle + p[1].attribute.endAngle) / 2;
                            return p[1].attribute.y + offset * Math.sin(angle);
                        }
                    }
                },
                startTime,
                oneByOne: 1000 * loopDuration,
                duration: loopDuration / 2 * 1000,
                loop: true,
                easing: loopEase,
                delayAfter: loopDuration / 2 * 1000 + 1000 * interval,
                controlOptions: {
                    immediatelyApply: false
                }
            },
            {
                channel: {
                    x: {
                        from: (...p)=>{
                            const angle = (p[1].attribute.startAngle + p[1].attribute.endAngle) / 2;
                            return p[1].attribute.x + offset * Math.cos(angle);
                        },
                        to: (...p)=>p[1].attribute.x
                    },
                    y: {
                        from: (...p)=>{
                            const angle = (p[1].attribute.startAngle + p[1].attribute.endAngle) / 2;
                            return p[1].attribute.y + offset * Math.sin(angle);
                        },
                        to: (...p)=>p[1].attribute.y
                    }
                },
                startTime,
                oneByOne: 1000 * loopDuration,
                duration: loopDuration / 2 * 1000,
                easing: loopEase,
                delay: loopDuration / 2 * 1000,
                delayAfter: 1000 * interval,
                loop: true,
                controlOptions: {
                    immediatelyApply: false
                }
            }
        ];
    }
    return {
        pie: loopResult,
        rose: loopResult
    };
};
const pieExit = ()=>false;
export { pieAppear, pieEnter, pieExit, pieLoop, pieUpdate };

//# sourceMappingURL=pie.js.map