'use client'; import { motion, useReducedMotion, useMotionValue, useSpring, useTransform } from 'framer-motion'; import { useEffect, useState } from 'react'; export default function RatingFactorsMockup() { const shouldReduceMotion = useReducedMotion(); const [isHovered, setIsHovered] = useState(null); const [isMobile, setIsMobile] = useState(false); useEffect(() => { setIsMobile(window.innerWidth < 768); }, []); const factors = [ { name: 'Position', value: 85, color: 'text-primary-blue', bgColor: 'bg-primary-blue' }, { name: 'Field Strength', value: 72, color: 'text-neon-aqua', bgColor: 'bg-neon-aqua' }, { name: 'Consistency', value: 68, color: 'text-performance-green', bgColor: 'bg-performance-green' }, { name: 'Clean Driving', value: 91, color: 'text-warning-amber', bgColor: 'bg-warning-amber' }, { name: 'Reliability', value: 88, color: 'text-primary-blue', bgColor: 'bg-primary-blue' }, { name: 'Team Points', value: 79, color: 'text-performance-green', bgColor: 'bg-performance-green' }, ]; if (isMobile) { return (
{factors.slice(0, 4).map((factor) => (
{factor.name}
{factor.value}
))}
1342
); } const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: shouldReduceMotion ? 0 : 0.1 } } }; const itemVariants = { hidden: { opacity: 0, y: shouldReduceMotion ? 0 : 20 }, visible: { opacity: 1, y: 0, transition: { type: 'spring' as const, stiffness: 200, damping: 20 } } }; return (
{factors.map((factor, index) => ( !shouldReduceMotion && setIsHovered(index)} onHoverEnd={() => setIsHovered(null)} > ))}
); } function RatingFactor({ value, color, bgColor, name, shouldReduceMotion, isHovered }: { value: number; color: string; bgColor: string; name: string; shouldReduceMotion: boolean; isHovered: boolean; }) { const progress = useMotionValue(0); const smoothProgress = useSpring(progress, { stiffness: 60, damping: 25 }); const width = useTransform(smoothProgress, (v: number) => `${v}%`); useEffect(() => { if (shouldReduceMotion) { progress.set(value); } else { const timeout = setTimeout(() => progress.set(value), 200); return () => clearTimeout(timeout); } }, [value, shouldReduceMotion, progress]); return (
{name}
{value}
); } function AnimatedRating({ shouldReduceMotion }: { shouldReduceMotion: boolean }) { const count = useMotionValue(0); const rounded = useTransform(count, (v: number) => Math.round(v)); const spring = useSpring(count, { stiffness: 50, damping: 25 }); useEffect(() => { if (shouldReduceMotion) { count.set(1342); } else { const timeout = setTimeout(() => count.set(1342), 800); return () => clearTimeout(timeout); } }, [shouldReduceMotion, count]); return ( {shouldReduceMotion ? 1342 : {rounded}} ); }