import { Autocomplete, type AutocompleteProps, type AutocompleteRenderOptionState, Checkbox, styled, TextField, } from '@mui/material'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import CheckBoxIcon from '@mui/icons-material/CheckBox'; import type { IRole } from 'interfaces/role'; import { RoleDescription } from '../RoleDescription/RoleDescription'; import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender'; const StyledRoleOption = styled('div')(({ theme }) => ({ paddingTop: theme.spacing(0.75), display: 'flex', flexDirection: 'column', '& > span:last-of-type': { fontSize: theme.fontSizes.smallerBody, color: theme.palette.text.secondary, }, })); interface IMultipleRoleSelectProps extends Partial> { roles: IRole[]; value: IRole[]; setValue: (role: IRole[]) => void; required?: boolean; } function sortItems(items: T[]): T[] { return items.sort((a, b) => { if (a.type !== b.type) { return a.type === 'project' ? -1 : 1; } if (a.type === 'custom') { return a.name.localeCompare(b.name); } return 0; }); } const StyledListItem = styled('li')(({ theme }) => ({ display: 'flex', gap: theme.spacing(0.5), })); export const MultipleRoleSelect = ({ roles, value, setValue, required, ...rest }: IMultipleRoleSelectProps) => { const renderRoleOption = ( props: React.HTMLAttributes, option: IRole, state: AutocompleteRenderOptionState, ) => ( } checkedIcon={} checked={state.selected} /> {option.name} {option.description} ); const sortedRoles = sortItems(roles); return ( <> theme.spacing(0.5), alignItems: 'flex-start', }, }, }, }, }} multiple disableCloseOnSelect openOnFocus size='small' value={value} groupBy={(option) => { return option.type === 'project' ? 'Predefined project roles' : 'Custom project roles'; }} onChange={(_, roles) => setValue(roles)} options={sortedRoles} renderOption={renderRoleOption} getOptionLabel={(option) => option.name} renderInput={(params) => ( )} {...rest} /> 0} show={() => ( <> {value.map(({ id }) => ( ))} )} /> ); };