// Independent periods keep the logo, geographic tour and lighting from moving in lockstep.
// They still consume the same paused elapsed time so one control can stop them all.
export const HERO_ORBIT_TRAVEL_MS=43000;
export const HERO_ORBIT_RETURN_MS=2000;
export const HERO_ORBIT_LAP_MS=HERO_ORBIT_TRAVEL_MS+HERO_ORBIT_RETURN_MS;
export const HERO_LIGHT_CYCLE_MS=37000;
const FADE_MS=875;
const ease = (value:number) => (1 - Math.cos(Math.PI * value)) / 2;
export type HeroAnimationFrame = {elapsedMs:number;position:number;turn:number;lightMix:number;opacity:number};

export function heroAnimationFrame(elapsedMs:number):HeroAnimationFrame {
 const lap=Math.floor(elapsedMs/HERO_ORBIT_LAP_MS),time=elapsedMs%HERO_ORBIT_LAP_MS;
 const progress=ease(Math.min(1,time/HERO_ORBIT_TRAVEL_MS));
 const position=time<HERO_ORBIT_TRAVEL_MS?progress/2:.5+ease((time-HERO_ORBIT_TRAVEL_MS)/HERO_ORBIT_RETURN_MS)/2;
 const opacity=time<HERO_ORBIT_TRAVEL_MS?ease(Math.min(1,time/FADE_MS))*ease(Math.min(1,(HERO_ORBIT_TRAVEL_MS-time)/FADE_MS)):0;
 const lightMix=(1-Math.cos(2*Math.PI*(elapsedMs%HERO_LIGHT_CYCLE_MS)/HERO_LIGHT_CYCLE_MS))/2;
 return {elapsedMs,position,turn:lap+position,lightMix,opacity};
}
