import { useState, useEffect } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { BookOpen, ChevronDown, ChevronRight, Loader2, AlertTriangle, Copy, Check } from 'lucide-react' const API_BASE = '' export default function FormulasPanel() { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [expanded, setExpanded] = useState({}) const [copied, setCopied] = useState(null) useEffect(() => { fetch(`${API_BASE}/formulas`).then(r => r.json()).then(d => setData(d)).catch(() => setData({ error: 'Failed' })).finally(() => setLoading(false)) }, []) const toggle = (key) => setExpanded(prev => ({ ...prev, [key]: !prev[key] })) const copyFormula = (text, id) => { navigator.clipboard?.writeText(text) setCopied(id) setTimeout(() => setCopied(null), 2000) } if (loading) { return (
Loading formulas...
) } if (data?.error) { return (
{data.error}
) } const categories = data.categories || {} return (
Formula Documentation {data.version || 'v2.0'}
{data.description || 'All formulas, algorithms, and scoring models'}
{Object.entries(categories).map(([catKey, cat], catIdx) => ( {expanded[catKey] && (
{cat.formulas?.map((f, i) => { const fid = `${catKey}-${i}` return (
{f.name || '—'} {f.unit && {f.unit}} {f.range && {f.range}}
{f.formula || '—'}
{f.rates &&
{f.rates}
} {f.max_rate &&
Max: {f.max_rate}
}
) })}
)}
))}
) }