import { useFieldArray, useFormContext } from 'react-hook-form';
import { IRole } from '@automatisch/types';
import MuiTextField from '@mui/material/TextField';
import Stack from '@mui/material/Stack';
import DeleteIcon from '@mui/icons-material/Delete';
import IconButton from '@mui/material/IconButton';
import Button from '@mui/material/Button';
import useRoles from 'hooks/useRoles.ee';
import useFormatMessage from 'hooks/useFormatMessage';
import ControlledAutocomplete from 'components/ControlledAutocomplete';
import TextField from 'components/TextField';
import { Divider, Typography } from '@mui/material';
function generateRoleOptions(roles: IRole[]) {
return roles?.map(({ name: label, id: value }) => ({ label, value }));
}
function RoleMappingsFieldArray() {
const formatMessage = useFormatMessage();
const { control } = useFormContext();
const { roles, loading: rolesLoading } = useRoles();
const { fields, append, remove } = useFieldArray({
control,
name: 'roleMappings',
});
const handleAppendMapping = () => append({ roleId: '', remoteRoleName: '' });
const handleRemoveMapping = (index: number) => () => remove(index);
return (
<>
{fields.length === 0 && (