'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 (