// 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 RHFTextFieldMoney({ name, ...other }: IProps & TextFieldProps) {
  const { control, watch, setValue } = useFormContext();
  const values = watch();

  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={{
              startAdornment: <InputAdornment position="start">Rp</InputAdornment>,
              inputComponent: MoneyFormat as any,
            }}
          />
        </>
      )}
    />
  );
}
