import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import { Input, InputNumber } from '@whalecloud/fdx';

function CustomInput(props) {
  var onChange = props.onChange,
      _props$value = props.value,
      value = _props$value === void 0 ? '' : _props$value,
      _props$inputProps = props.inputProps,
      inputProps = _props$inputProps === void 0 ? {} : _props$inputProps,
      _props$inputType = props.inputType,
      inputType = _props$inputType === void 0 ? 'input' : _props$inputType;

  var _useState = useState(value.value || value),
      _useState2 = _slicedToArray(_useState, 2),
      inputValue = _useState2[0],
      setInputValue = _useState2[1];

  var handleChange = function handleChange(e) {
    var val = e.target ? e.target.value : e;
    setInputValue(val);
  };

  var handleBlur = function handleBlur() {
    onChange(inputValue);
  };

  var getElement = function getElement(inputType) {
    var el;

    switch (inputType) {
      case 'inputNumber':
        el = /*#__PURE__*/React.createElement(InputNumber, Object.assign({
          value: inputValue,
          onChange: handleChange,
          onBlur: handleBlur
        }, inputProps));
        break;

      case 'textArea':
        el = /*#__PURE__*/React.createElement(Input.TextArea, Object.assign({
          value: inputValue,
          onChange: handleChange,
          onBlur: handleBlur
        }, inputProps));
        break;

      default:
        el = /*#__PURE__*/React.createElement(Input, Object.assign({
          value: inputValue,
          onChange: handleChange,
          onBlur: handleBlur
        }, inputProps));
        break;
    }

    return el;
  };

  return getElement(inputType);
}

export default CustomInput;
//# sourceMappingURL=index.js.map