import variables from 'config/variables'; import { memo, useState, useCallback } from 'react'; import { useTranslation } from 'contexts/TranslationContext'; import { Radio as RadioUI, RadioGroup, FormControlLabel, FormControl, FormLabel, } from '@mui/material'; import EventBus from 'utils/eventbus'; const Radio = memo((props) => { const { changeLanguage } = useTranslation(); const [value, setValue] = useState(localStorage.getItem(props.name)); const handleChange = useCallback(async (e) => { const newValue = e.target.value; if (newValue === 'loading') { return; } if (props.name === 'language') { // Use context to change language directly - no EventBus needed changeLanguage(newValue); setValue(newValue); variables.stats.postEvent('setting', `${props.name} from ${value} to ${newValue}`); if (props.onChange) { props.onChange(newValue); } EventBus.emit('refresh', props.category); return; } localStorage.setItem(props.name, newValue); setValue(newValue); if (props.onChange) { props.onChange(newValue); } variables.stats.postEvent('setting', `${props.name} from ${value} to ${newValue}`); if (props.element) { if (!document.querySelector(props.element)) { document.querySelector('.reminder-info').style.display = 'flex'; return localStorage.setItem('showReminder', true); } } EventBus.emit('refresh', props.category); }, [value, props, changeLanguage]); return ( {props.title} {props.options.map((option) => ( } label={option.name} key={option.value} /> ))} ); }); Radio.displayName = 'Radio'; export { Radio as default, Radio };