import { clamp } from '../utils/helpers'

export const animateDashboard = (bars, pieQuarters, progress) => {
  // progress is 0 at scrollProgress = 0.75, and 1 at scrollProgress = 1.0
  // Scale bar charts on their Y axis with a staggered effect
  bars.forEach((barRef, index) => {
    if (barRef.current) {
      const delay = index * 0.08
      const scaleY = clamp((progress - delay) / 0.5, 0, 1)
      
      // Interpolate scale Y
      barRef.current.scale.y = scaleY
    }
  })

  // Rotate pie chart quarters around their local Y axis
  pieQuarters.forEach((quarterRef, index) => {
    if (quarterRef.current) {
      // Rotate based on progress (offset each slice slightly for dynamic feeling)
      const rotationSpeed = 2 + index * 0.5
      quarterRef.current.rotation.y = -0.709 + progress * Math.PI * 2 * rotationSpeed
    }
  })
}
