import { useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; /** * QDRing * Animated SVG arc representing the Qualification Desire score (0–100). * Color: green (≥70), amber (40–69), red (<40). * Animates from 0 to score on mount; smooth spring on value change. */ interface QDRingProps { score: number; size?: number; // diameter in px (default 64) strokeWidth?: number; color?: string; // overrides semantic color if provided showLabel?: boolean; } export function QDRing({ score, size = 64, strokeWidth = 4, color, showLabel = false, }: QDRingProps) { const clampedScore = Math.max(0, Math.min(100, score)); const r = (size - strokeWidth) / 2; const cx = size / 2; const cy = size / 2; const circumference = 2 * Math.PI * r; // Arc: 0% = full stroke-dashoffset (hidden), 100% = 0 offset (full) const offset = circumference * (1 - clampedScore / 100); // Semantic color const arcColor = color ?? ( clampedScore >= 70 ? 'var(--color-green)' : clampedScore >= 40 ? 'var(--color-amber)' : 'var(--color-red)' ); return ( {/* Track */} {/* Animated arc */} {/* Optional center label (shown rotated back) */} {showLabel && ( {clampedScore} )} ); }