import React from 'react';
import { Input, InputNumber } from 'antd';
import './index.less';

export interface GInputProps {
  [propsName: string]: any

  onChange: (value: any) => void
}

const GInput: React.FC<GInputProps> = (props) => {
  const { DISPLAYTYPE, DATATYPE, value, onChange, disabled } = props
  const type = DISPLAYTYPE.toUpperCase()
  let result = null
  switch (type) {
    case 'TEXT':
    case 'REFTEXT':
      if (DATATYPE === 'integer' || DATATYPE === 'double') {
        result = (
          <InputNumber
            value={value}
            onChange={onChange}
            disabled={disabled}
          />
        )
      } else {
        result = (
          <Input
            type="text"
            value={value}
            onChange={onChange}
            disabled={disabled}
          />
        )
      }
      break
    case 'PASSWORD':
      result = (
        <Input.Password
          value={value}
          onChange={onChange}
          disabled={disabled}
        />
      )
      break
    case 'TEXTAREA':
      result = (
        <Input.TextArea
          value={value}
          onChange={onChange}
          disabled={disabled}
        />
      )
      break
  }
  return result
}

export default GInput;