'use client'; import { useState, useEffect } from 'react'; import { FormControl, InputLabel, Select, MenuItem, SelectChangeEvent, Box, Typography, } from '@mui/material'; import { useLocale, MeasurementSystem } from '@/hooks/useLocale'; import { useTranslation } from '@/hooks/useTranslation'; interface MeasurementUnitSelectorProps { variant?: 'standard' | 'outlined' | 'filled'; fullWidth?: boolean; showDescription?: boolean; value?: MeasurementSystem; onChange?: (value: MeasurementSystem) => void; } /** * Measurement unit selector component for choosing between Metric and Imperial systems */ export function MeasurementUnitSelector({ variant = 'outlined', fullWidth = true, showDescription = true, value, onChange, }: MeasurementUnitSelectorProps) { const { measurementSystem, setMeasurementSystem } = useLocale(); const { t } = useTranslation('settings'); // Use controlled value if provided, otherwise use hook value const selectedSystem = value !== undefined ? value : measurementSystem; const handleSystemChange = (event: SelectChangeEvent) => { const newSystem = event.target.value as MeasurementSystem; // If onChange is provided (controlled), use it if (onChange) { onChange(newSystem); } else { // Otherwise use the hook (uncontrolled) setMeasurementSystem(newSystem); } }; return ( {t('preferences.measurementUnits')} ); }