// form
import { useFormContext, Controller } from 'react-hook-form';
// @mui
import { InputAdornment, TextField, TextFieldProps, Typography } from '@mui/material';
import MoneyFormat from '../../numeric_format/MoneyFormat';

// ----------------------------------------------------------------------

interface IProps {
  name: string;
}

export default function RHFTextFieldPercentage({ name, ...other }: IProps & TextFieldProps) {
  const { control } = useFormContext();

  return (
    <Controller
      name={name}
      control={control}

      render={({ field, fieldState: { error } }) => (
        <>
          <TextField
            {...field}
            autoComplete="off"
            fullWidth error={!!error}
            helperText={error?.message}
            {...other}
            inputProps={{ min: 0, max: 5, style: { textAlign: 'right' } }}
            InputProps={{
              endAdornment: <InputAdornment position="end">%</InputAdornment>,
              inputComponent: MoneyFormat as any,
            }}
          />
        </>
      )}
    />
  );
}
