import { useEffect, useState } from "react"; export type ScoreRingProps = { score: number; maxScore?: number; size?: number; label?: string; /** 링 색 (브랜드 등). 없으면 점수 구간별 자동 색 */ color?: string; className?: string; scoreClassName?: string; }; function scoreStrokeColor(score: number, maxScore: number): string { const pct = (score / maxScore) * 100; if (pct <= 40) return "#D4889A"; if (pct <= 60) return "#7A84D4"; if (pct <= 80) return "#9B8AD4"; return "#6C5CE7"; } export function ScoreRing({ score, maxScore = 100, size = 120, label, color, className = "", scoreClassName, }: ScoreRingProps) { const strokeWidth = size <= 72 ? 5 : 8; const radius = (size - strokeWidth) / 2; const circumference = 2 * Math.PI * radius; const progress = Math.min(score / maxScore, 1); const targetOffset = circumference * (1 - progress); const resolvedColor = color ?? scoreStrokeColor(score, maxScore); const [dashOffset, setDashOffset] = useState(circumference); const defaultScoreClass = size <= 72 ? "text-sm font-bold text-navy-900" : "text-2xl font-bold text-navy-900"; useEffect(() => { setDashOffset(circumference); const id = requestAnimationFrame(() => setDashOffset(targetOffset)); return () => cancelAnimationFrame(id); }, [circumference, targetOffset]); return (