import { Checkbox, checkboxClasses, FormControl, FormControlLabel, FormGroup, MenuItem, menuItemClasses, Select, selectClasses, styled, } from '@mui/material'; import { Sync as SyncIcon, SyncDisabled as SyncDisabledIcon, } from '@mui/icons-material'; import { v4 as uuidv4 } from 'uuid'; import { BLUE, GREY, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; import { UPLOAD_FILE_TYPES_ARRAY } from '../../lib/consts/UPLOAD_FILE_TYPES'; import OutlinedInput from '../OutlinedInput'; import OutlinedInputLabel from '../OutlinedInputLabel'; type FileInfoProps = Pick & Partial> & { isReadonly?: boolean; onChange?: FileInfoChangeHandler; }; const FILE_INFO_DEFAULT_PROPS: Partial = { isReadonly: undefined, onChange: undefined, }; const StyledSelect = styled(Select)({ [`& .${selectClasses.icon}`]: { color: GREY, }, }); const StyledMenuItem = styled(MenuItem)({ backgroundColor: TEXT, paddingRight: '3em', [`&.${menuItemClasses.selected}`]: { backgroundColor: GREY, fontWeight: 400, '&:hover': { backgroundColor: GREY, }, }, '&:hover': { backgroundColor: GREY, }, }); const FileLocationActiveCheckbox = styled(Checkbox)({ color: RED, [`&.${checkboxClasses.checked}`]: { color: BLUE, }, }); const FileInfo = ( { fileName, fileType, fileLocations, isReadonly, onChange, }: FileInfoProps = FILE_INFO_DEFAULT_PROPS as FileInfoProps, ): JSX.Element => { const idExtension = uuidv4(); const fileNameElementId = `file-name-${idExtension}`; const fileNameElementLabel = 'File name'; const fileTypeElementId = `file-type-${idExtension}`; const fileTypeElementLabel = 'File type'; return ( :not(:first-child)': { marginTop: '1em' } }}> {fileNameElementLabel} { onChange?.call(null, { fileName: value === fileName ? undefined : value, }); }} /> {fileType && ( {fileTypeElementLabel} } onChange={({ target: { value } }) => { onChange?.call(null, { fileType: value === fileType ? undefined : (value as FileType), }); }} > {UPLOAD_FILE_TYPES_ARRAY.map( ([fileTypeKey, [, fileTypeDisplayString]]) => ( {fileTypeDisplayString} ), )} )} {fileLocations.map( ( { anvilName, anvilDescription, anvilUUID, isFileLocationActive }, fileLocationIndex, ) => ( } defaultChecked={isFileLocationActive} disabled={isReadonly} icon={} onChange={({ target: { checked } }) => { onChange?.call( null, { isFileLocationActive: checked === isFileLocationActive ? undefined : checked, }, { fileLocationIndex }, ); }} /> } key={anvilUUID} label={`${anvilName}: ${anvilDescription}`} sx={{ color: TEXT }} value={`${anvilUUID}-sync`} /> ), )} ); }; FileInfo.defaultProps = FILE_INFO_DEFAULT_PROPS; export default FileInfo;