'use client' import React from 'react' import { scoreToCssVar, red as redHex, green as greenHex } from '../colors' import { ArrowUpIcon } from 'lucide-react' export type ProgressCircleProps = { value: number size?: number thickness?: number className?: string showLabel?: boolean label?: string // Optional highlight segment (e.g., to preview gain from an action) highlightFrom?: number highlightTo?: number highlightPulse?: boolean // Optional center indicator arrow: 'up' (green) or 'down' (red) centerIndicator?: 'up' | 'down' | null indicatorPulse?: boolean } export function ProgressCircle(props: ProgressCircleProps) { const { value, size = 72, thickness = 6, className, showLabel = true, label, highlightFrom, highlightTo, highlightPulse, centerIndicator, indicatorPulse } = props const rawId = React.useId() const gradientId = React.useMemo(() => `kyd-pc-${String(rawId).replace(/:/g, '')}` , [rawId]) const clamped = Math.max(0, Math.min(100, Number.isFinite(value) ? value : 0)) const radius = (size - thickness) / 2 const circumference = 2 * Math.PI * radius const dashOffset = circumference * (1 - clamped / 100) const hasHighlight = Number.isFinite(highlightFrom as number) && Number.isFinite(highlightTo as number) && (typeof highlightFrom === 'number') && (typeof highlightTo === 'number') && highlightTo! > (highlightFrom as number) const fromClamped = hasHighlight ? Math.max(0, Math.min(100, highlightFrom as number)) : 0 const toClamped = hasHighlight ? Math.max(0, Math.min(100, highlightTo as number)) : 0 const highlightLength = hasHighlight ? circumference * ((toClamped - fromClamped) / 100) : 0 const highlightOffset = hasHighlight ? circumference * (1 - toClamped / 100) : 0 const strokeColor = React.useMemo(() => scoreToCssVar(clamped), [clamped]) const indicatorColor = React.useMemo(() => { if (!centerIndicator) return undefined return centerIndicator === 'up' ? `var(--status-positive, ${greenHex})` : `var(--status-negative, ${redHex})` }, [centerIndicator]) return (
{hasHighlight ? ( ) : null} {/* subtle pulsing halo */} {centerIndicator ? (
) : null}
) } export default ProgressCircle