'use client' import { motion } from 'framer-motion' import { useEffect, useState } from 'react' interface RunwayGaugeProps { months: number maxMonths?: number size?: number label?: string } export default function RunwayGauge({ months, maxMonths = 36, size = 140, label = 'Runway' }: RunwayGaugeProps) { const [animatedAngle, setAnimatedAngle] = useState(0) const clampedMonths = Math.min(months, maxMonths) const targetAngle = (clampedMonths / maxMonths) * 270 - 135 // -135 to +135 degrees useEffect(() => { const timer = setTimeout(() => setAnimatedAngle(targetAngle), 100) return () => clearTimeout(timer) }, [targetAngle]) // Color based on runway const getColor = () => { if (months >= 18) return '#22c55e' // green if (months >= 12) return '#eab308' // yellow if (months >= 6) return '#f97316' // orange return '#ef4444' // red } const color = getColor() const cx = size / 2 const cy = size / 2 const radius = (size / 2) - 16 const needleLength = radius - 10 // Arc path for gauge background const startAngle = -135 const endAngle = 135 const polarToCartesian = (cx: number, cy: number, r: number, deg: number) => { const rad = (deg - 90) * Math.PI / 180 return { x: cx + r * Math.cos(rad), y: cy + r * Math.sin(rad) } } const arcStart = polarToCartesian(cx, cy, radius, startAngle) const arcEnd = polarToCartesian(cx, cy, radius, endAngle) const arcPath = `M ${arcStart.x} ${arcStart.y} A ${radius} ${radius} 0 1 1 ${arcEnd.x} ${arcEnd.y}` // Filled arc const filledEnd = polarToCartesian(cx, cy, radius, Math.min(animatedAngle, endAngle)) const largeArc = (animatedAngle - startAngle) > 180 ? 1 : 0 const filledPath = `M ${arcStart.x} ${arcStart.y} A ${radius} ${radius} 0 ${largeArc} 1 ${filledEnd.x} ${filledEnd.y}` // Needle endpoint const needleRad = (animatedAngle - 90) * Math.PI / 180 const needleX = cx + needleLength * Math.cos(needleRad) const needleY = cy + needleLength * Math.sin(needleRad) const shouldPulse = months < 6 return (
{/* Background arc */} {/* Filled arc */} {/* Tick marks */} {[0, 6, 12, 18, 24, 30, 36].map((tick) => { const tickAngle = (tick / maxMonths) * 270 - 135 const inner = polarToCartesian(cx, cy, radius - 12, tickAngle) const outer = polarToCartesian(cx, cy, radius - 6, tickAngle) return ( {tick} ) })} {/* Needle */} {/* Center circle */}

{Math.round(months)}

{label}

) }