text: import _extends from 'babel-runtime/helpers/extends';
  import _defineProperty from 'babel-runtime/helpers/defineProperty';
  import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  import _createClass from 'babel-runtime/helpers/createClass';
  import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  import _inherits from 'babel-runtime/helpers/inherits';
  var __rest = this && this.__rest || function (s, e) {
      var t = {};
      for (var p in s) {
          if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
      }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
          if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
      }return t;
  };
  /* tslint:disable:jsx-no-multiline-js */
  import classnames from 'classnames';
  import PropTypes from 'prop-types';
  import React from 'react';
  import TouchFeedback from 'rmc-feedback';
  import { getComponentLocale } from '../_util/getLocale';
  import CustomInput from './CustomInput';
  import Input from './Input';
  function noop() {}
  function fixControlledValue(value) {
      if (typeof value === 'undefined' || value === null) {
          return '';
      }
      return value;
  }
  
  var InputItem = function (_React$Component) {
      _inherits(InputItem, _React$Component);
  
      function InputItem(props) {
          _classCallCheck(this, InputItem);
  
          var _this = _possibleConstructorReturn(this, (InputItem.__proto__ || Object.getPrototypeOf(InputItem)).call(this, props));
  
          _this.onInputChange = function (e) {
              var value = e.target.value;
              var type = _this.props.type;
  
              switch (type) {
                  case 'text':
                      break;
                  case 'bankCard':
                      value = value.replace(/\D/g, '').replace(/(....)(?=.)/g, '$1 ');
                      break;
                  case 'phone':
                      value = value.replace(/\D/g, '').substring(0, 11);
                      var valueLen = value.length;
                      if (valueLen > 3 && valueLen < 8) {
                          value = value.substr(0, 3) + ' ' + value.substr(3);
                      } else if (valueLen >= 8) {
                          value = value.substr(0, 3) + ' ' + value.substr(3, 4) + ' ' + value.substr(7);
                      }
                      break;
                  case 'number':
                      value = value.replace(/\D/g, '');
                      break;
                  case 'password':
                      break;
                  default:
                      break;
              }
              _this.handleOnChange(value);
          };
          _this.handleOnChange = function (value) {
              var onChange = _this.props.onChange;
  
              if (!('value' in _this.props)) {
                  _this.setState({ value: value });
              } else {
                  _this.setState({ value: _this.props.value });
              }
              if (onChange) {
                  onChange(value);
              }
          };
          _this.onInputFocus = function (value) {
              if (_this.debounceTimeout) {
                  clearTimeout(_this.debounceTimeout);
                  _this.debounceTimeout = null;
              }
              _this.setState({
                  focus: true
              });
              if (_this.props.onFocus) {
                  _this.props.onFocus(value);
              }
          };
          _this.onInputBlur = function (value) {
              if (_this.inputRef) {
                  // this.inputRef may be null if customKeyboard unmount
                  _this.debounceTimeout = setTimeout(function () {
                      if (document.activeElement !== (_this.inputRef && _this.inputRef.inputRef)) {
                          _this.setState({
                              focus: false
                          });
                      }
                  }, 200);
              }
              if (_this.props.onBlur) {
                  _this.props.onBlur(value);
              }
          };
          _this.onExtraClick = function (e) {
              if (_this.props.onExtraClick) {
                  _this.props.onExtraClick(e);
              }
          };
          _this.onErrorClick = function (e) {
              if (_this.props.onErrorClick) {
                  _this.props.onErrorClick(e);
              }
          };
          _this.clearInput = function () {
              if (_this.props.type !== 'password' && _this.props.updatePlaceholder) {
                  _this.setState({
                      placeholder: _this.props.value
                  });
              }
              _this.setState({
                  value: ''
              });
              if (_this.props.onChange) {
                  _this.props.onChange('');
              }
              _this.focus();
          };
          _this.focus = function () {
              if (_this.inputRef) {
                  _this.inputRef.focus();
              }
          };
          _this.state = {
              placeholder: props.placeholder,
              value: props.value || props.defaultValue || ''
          };
          return _this;
      }
  
      _createClass(InputItem, [{
          key: 'componentWillReceiveProps',
          value: function componentWillReceiveProps(nextProps) {
              if ('placeholder' in nextProps && !nextProps.updatePlaceholder) {
                  this.setState({
                      placeholder: nextProps.placeholder
                  });
              }
              if ('value' in nextProps) {
                  this.setState({
                      value: nextProps.value
                  });
              }
          }
      }, {
          key: 'componentWillUnmount',
          value: function componentWillUnmount() {
              if (this.debounceTimeout) {
                  clearTimeout(this.debounceTimeout);
                  this.debounceTimeout = null;
              }
          }
      }, {
          key: 'render',
          value: function render() {
              var _classnames,
                  _classnames2,
                  _this2 = this;
  
              var _a = this.props,
                  prefixCls = _a.prefixCls,
                  prefixListCls = _a.prefixListCls,
                  editable = _a.editable,
                  style = _a.style,
                  clear = _a.clear,
                  children = _a.children,
                  error = _a.error,
                  className = _a.className,
                  extra = _a.extra,
                  labelNumber = _a.labelNumber,
                  onExtraClick = _a.onExtraClick,
                  onErrorClick = _a.onErrorClick,
                  updatePlaceholder = _a.updatePlaceholder,
                  type = _a.type,
                  locale = _a.locale,
                  moneyKeyboardAlign = _a.moneyKeyboardAlign,
                  restProps = __rest(_a, ["prefixCls", "prefixListCls", "editable", "style", "clear", "children", "error", "className", "extra", "labelNumber", "onExtraClick", "onErrorClick", "updatePlaceholder", "type", "locale", "moneyKeyboardAlign"]);var defaultValue = restProps.defaultValue,
                  name = restProps.name,
                  disabled = restProps.disabled,
                  maxLength = restProps.maxLength;
              var value = this.state.value;
              // tslint:disable-next-line:variable-name
  
              var _locale = getComponentLocale(this.props, this.context, 'InputItem', function () {
                  return require('./locale/zh_CN');
              });
              var confirmLabel = _locale.confirmLabel;
              var _state = this.state,
                  placeholder = _state.placeholder,
                  focus = _state.focus;
  
              var wrapCls = classnames(prefixListCls + '-item', prefixCls + '-item', prefixListCls + '-item-middle', className, (_classnames = {}, _defineProperty(_classnames, prefixCls + '-disabled', disabled), _defineProperty(_classnames, prefixCls + '-error', error), _defineProperty(_classnames, prefixCls + '-focus', focus), _defineProperty(_classnames, prefixCls + '-android', focus), _classnames));
              var labelCls = classnames(prefixCls + '-label', (_classnames2 = {}, _defineProperty(_classnames2, prefixCls + '-label-2', labelNumber === 2), _defineProperty(_classnames2, prefixCls + '-label-3', labelNumber === 3), _defineProperty(_classnames2, prefixCls + '-label-4', labelNumber === 4), _defineProperty(_classnames2, prefixCls + '-label-5', labelNumber === 5), _defineProperty(_classnames2, prefixCls + '-label-6', labelNumber === 6), _defineProperty(_classnames2, prefixCls + '-label-7', labelNumber === 7), _classnames2));
              var controlCls = prefixCls + '-control';
              var inputType = 'text';
              if (type === 'bankCard' || type === 'phone') {
                  inputType = 'tel';
              } else if (type === 'password') {
                  inputType = 'password';
              } else if (type === 'digit') {
                  inputType = 'number';
              } else if (type !== 'text' && type !== 'number') {
                  inputType = type;
              }
              var patternProps = void 0;
              if (type === 'number') {
                  patternProps = {
                      pattern: '[0-9]*'
                  };
              }
              var classNameProps = void 0;
              if (type === 'digit') {
                  classNameProps = {
                      className: 'h5numInput'
                  };
              }
              return React.createElement(
                  'div',
                  { className: wrapCls },
                  React.createElement(
                      'div',
                      { className: prefixListCls + '-line' },
                      children ? React.createElement(
                          'div',
                          { className: labelCls },
                          children
                      ) : null,
                      React.createElement(
                          'div',
                          { className: controlCls },
                          type === 'money' ? React.createElement(CustomInput, { value: fixControlledValue(value), defaultValue: defaultValue, type: type, ref: function ref(el) {
                                  return _this2.inputRef = el;
                              }, maxLength: maxLength, placeholder: placeholder, onChange: this.handleOnChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, disabled: disabled, editable: editable, prefixCls: prefixCls, style: style, confirmLabel: confirmLabel, moneyKeyboardAlign: moneyKeyboardAlign }) : React.createElement(Input, _extends({}, patternProps, restProps, classNameProps, { value: fixControlledValue(value), defaultValue: defaultValue, ref: function ref(el) {
                                  return _this2.inputRef = el;
                              }, style: style, type: inputType, maxLength: maxLength, name: name, placeholder: placeholder, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, readOnly: !editable, disabled: disabled }))
                      ),
                      clear && editable && !disabled && value && ('' + value).length > 0 ? React.createElement(
                          TouchFeedback,
                          { activeClassName: prefixCls + '-clear-active' },
                          React.createElement('div', { className: prefixCls + '-clear', onClick: this.clearInput })
                      ) : null,
                      error ? React.createElement('div', { className: prefixCls + '-error-extra', onClick: this.onErrorClick }) : null,
                      extra !== '' ? React.createElement(
                          'div',
                          { className: prefixCls + '-extra', onClick: this.onExtraClick },
                          extra
                      ) : null
                  )
              );
          }
      }]);
  
      return InputItem;
  }(React.Component);
  
  InputItem.defaultProps = {
      prefixCls: 'am-input',
      prefixListCls: 'am-list',
      type: 'text',
      editable: true,
      disabled: false,
      placeholder: '',
      clear: false,
      onChange: noop,
      onBlur: noop,
      onFocus: noop,
      extra: '',
      onExtraClick: noop,
      error: false,
      onErrorClick: noop,
      labelNumber: 5,
      updatePlaceholder: false,
      moneyKeyboardAlign: 'right'
  };
  InputItem.contextTypes = {
      antLocale: PropTypes.object
  };
  export default InputItem;