import { useTranslation } from 'react-i18next'; import { spoolbuddyApi } from '../../api/client'; interface WeightDisplayProps { weight: number | null; weightStable: boolean; deviceOnline: boolean; deviceId: string | null; } export function WeightDisplay({ weight, weightStable, deviceOnline, deviceId }: WeightDisplayProps) { const { t } = useTranslation(); const handleTare = async () => { if (!deviceId) return; try { await spoolbuddyApi.tare(deviceId); } catch (e) { console.error('Failed to tare:', e); } }; const formatWeight = (w: number | null) => { if (w === null) return '--.-'; return w.toFixed(1); }; return (
{/* Weight readout */}
{formatWeight(weight)} g
{/* Stability indicator */}
{!deviceOnline ? t('spoolbuddy.weight.noReading', 'No reading') : weightStable ? t('spoolbuddy.weight.stable', 'Stable') : t('spoolbuddy.weight.measuring', 'Measuring...')}
{/* Tare button */}
); }