'use client' import { useState } from 'react' import { Scale } from 'lucide-react' import { Button, showToast } from '@/components/ui' interface WeightQuickLogProps { workspaceId: string onLogged?: () => void } export function WeightQuickLog({ workspaceId, onLogged }: WeightQuickLogProps) { const [weight, setWeight] = useState('') const [unit, setUnit] = useState<'kg' | 'lbs'>('kg') const [notes, setNotes] = useState('') const [saving, setSaving] = useState(false) const handleSubmit = async () => { const weightValue = parseFloat(weight) if (isNaN(weightValue) || weightValue <= 0) { showToast('Enter a valid weight', 'error') return } const weightKg = unit === 'lbs' ? weightValue * 0.453592 : weightValue setSaving(true) try { const response = await fetch(`/api/workspaces/${workspaceId}/weight`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ weightKg, notes: notes.trim() || null }), }) if (!response.ok) throw new Error('Failed to log weight') showToast('Weight logged', 'success') setWeight('') setNotes('') onLogged?.() } catch { showToast('Failed to log weight', 'error') } finally { setSaving(false) } } return (
{/* Weight Input */}
setWeight(e.target.value)} placeholder={unit === 'kg' ? '70.0' : '154.0'} className="w-full px-4 py-4 text-3xl font-bold text-center border border-border rounded-card focus:outline-none focus:ring-2 focus:ring-primary-200 focus:border-primary-500" />
{/* Notes */}