import type {
  VQAvatarAnimation,
  VQAvatarAnimationContext,
  VQIdleAvatarAnimationType,
  VQSpeakingAvatarAnimationType,
} from "./types";

const gentleBobAmplitude = ({focused}: VQAvatarAnimationContext) =>
  focused ? 10 : 3.5;

export const vqIdleAvatarAnimations: Record<
  VQIdleAvatarAnimationType,
  VQAvatarAnimation
> = {
  none: () => 0,
  gentleBob: (context) =>
    Math.sin((context.frame / context.fps) * Math.PI * 2) *
    gentleBobAmplitude(context),
};

export const vqSpeakingAvatarAnimations: Record<
  VQSpeakingAvatarAnimationType,
  VQAvatarAnimation
> = {
  none: () => 0,
  rhubarbLipSync: () => 0,
  gentleBob: vqIdleAvatarAnimations.gentleBob,
  quickHop: ({frame, fps}) => {
    const cycleFrames = Math.max(1, Math.round(fps * 0.25));
    const progress = (frame % cycleFrames) / cycleFrames;

    return -Math.sin(progress * Math.PI) * 7;
  },
};
