import {resolveEasing} from "../vfx-utils.mjs";

const vfxScaleAnimation = {
  setup: (state, params) => {
    state.lastPathIndex = 0;
    params.ease = resolveEasing(params.easing ?? "linear", params.easingParams);
  },
  animate: (t, state, params) => {
    const target = params.target || state.projectile?.container;
    if (!target) return;
    const uniformStart = params.startScale ?? 1;
    const uniformEnd = params.endScale ?? 1;
    const startScaleX = params.startScaleX ?? 1;
    const endScaleX = params.endScaleX ?? startScaleX;
    const startScaleY = params.startScaleY ?? 1;
    const endScaleY = params.endScaleY ?? startScaleY;
    const w = params.ease(t);
    const scale = Math.mix(uniformStart, uniformEnd, w);
    const scaleX = Math.mix(startScaleX, endScaleX, w) * scale;
    const scaleY = Math.mix(startScaleY, endScaleY, w) * scale;
    target.scale.set(scaleX, scaleY);
  }
};

export default vfxScaleAnimation;
