import { FormControl, FormControlLabel, Radio, RadioGroup, styled, } from '@mui/material'; import KeyboardArrowDownOutlined from '@mui/icons-material/KeyboardArrowDownOutlined'; import GeneralSelect from '../../common/GeneralSelect/GeneralSelect'; import { useTheme } from '@mui/material/styles'; interface IEnvironmentChangeRequestProps { onChange: (approvals: number | null) => void; value: number | null; } const StyledRadioGroup = styled(RadioGroup)({ flexDirection: 'row', }); const StyledRadioButtonGroup = styled('div')({ display: 'flex', flexDirection: 'column', }); const StyledRequiredApprovals = styled('p')(({ theme }) => ({ marginTop: theme.spacing(1), marginBottom: theme.spacing(0.5), })); const useApprovalOptions = () => { const theme = useTheme(); const approvalOptions = Array.from(Array(10).keys()) .map((key) => String(key + 1)) .map((key) => { const labelText = key === '1' ? 'approval' : 'approvals'; return { key, label: `${key} ${labelText}`, sx: { fontSize: theme.fontSizes.smallBody }, }; }); return approvalOptions; }; export const ChangeRequestSelector = ({ onChange, value, }: IEnvironmentChangeRequestProps) => { const approvalOptions = useApprovalOptions(); return ( { if (event.target.value === 'yes') { onChange(1); } else { onChange(null); } }} > } /> } /> {value ? ( <> Required approvals onChange(Number(approvals))} IconComponent={KeyboardArrowDownOutlined} fullWidth /> ) : null} ); };