'use client'; import { useState } from 'react'; import { Box, FormControl, RadioGroup, FormControlLabel, Radio, Button, CircularProgress, Alert, Typography, } from '@mui/material'; import { Save, Schedule } from '@mui/icons-material'; import { useAuth } from '@/lib/auth/AuthContext'; import { usersApi } from '@/lib/api/users'; import { useTranslation } from '@/hooks/useTranslation'; export function TimeFormatSelector() { const { user, refreshUser } = useAuth(); const { t } = useTranslation('settings'); const [timeFormat, setTimeFormat] = useState<'12h' | '24h'>( user?.preferences?.timeFormat || '12h' ); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [successMessage, setSuccessMessage] = useState(null); const handleSave = async () => { setIsLoading(true); setError(null); setSuccessMessage(null); try { await usersApi.updateProfile({ preferences: { ...user?.preferences, timeFormat, }, }); await refreshUser(); setSuccessMessage('Time format updated successfully'); } catch (err: any) { console.error('Failed to update time format:', err); setError(err.response?.data?.message || 'Failed to update time format'); } finally { setIsLoading(false); } }; const currentTime = new Date(); const preview12h = currentTime.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true, }); const preview24h = currentTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false, }); return ( Time Format {error && ( setError(null)}> {error} )} {successMessage && ( setSuccessMessage(null)}> {successMessage} )} setTimeFormat(e.target.value as '12h' | '24h')} > } label={ 12-hour format Example: {preview12h} } /> } label={ 24-hour format Example: {preview24h} } /> ); }