import { Form, InputNumber as AntInputNumber } from 'antd';
import { ElementStatus } from 'core/types/statuses';

const InputNumber = ({
  value,
  setCurrentValue,
  status,
  validateStatus,
  message,
  ...props
}) => {
  return (
    <Form.Item validateStatus={validateStatus} help={message}>
      <AntInputNumber
        {...props}
        parser={value => {
          value = value.replace(/[^0-9.,]+/, '');
          if (value === '') {
            return '0';
          }
          return value;
        }}
        disabled={status === ElementStatus.Disabled}
        style={styles}
        onChange={value => setCurrentValue(value)}
        value={value}
      />
    </Form.Item>
  );
};

const styles = {
  width: '100%',
};

export default InputNumber;
