"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var React = _interopRequireWildcard(require("react"));

var _one = require("remax/one");

var _classnames = _interopRequireDefault(require("classnames"));

var _common = require("./../common");

var _cell = _interopRequireDefault(require("../cell"));

var _utils = require("./../_utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var prefixCls = (0, _common.getPrefixCls)('field');

var myInput = function myInput(props) {
  var name = props.name,
      icon = props.icon,
      label = props.label,
      labelWidth = props.labelWidth,
      _props$colon = props.colon,
      colon = _props$colon === void 0 ? false : _props$colon,
      _props$required = props.required,
      required = _props$required === void 0 ? false : _props$required,
      _props$border = props.border,
      border = _props$border === void 0 ? false : _props$border,
      _props$type = props.type,
      type = _props$type === void 0 ? 'text' : _props$type,
      size = props.size,
      value = props.value,
      defaultValue = props.defaultValue,
      prefix = props.prefix,
      suffix = props.suffix,
      className = props.className,
      style = props.style,
      inputStyle = props.inputStyle,
      placeholderStyle = props.placeholderStyle,
      align = props.align,
      placeholder = props.placeholder,
      disabled = props.disabled,
      maxLength = props.maxLength,
      onChange = props.onChange,
      onFocus = props.onFocus,
      onBlur = props.onBlur;

  var _type = type === 'password' ? 'text' : type;

  var inputElement = /*#__PURE__*/React.createElement(_one.Input, {
    className: (0, _classnames.default)(prefixCls, _defineProperty({}, "".concat(prefixCls, "-align-").concat(align), align)),
    style: inputStyle,
    placeholderStyle: Object.assign({
      color: '#bfbfbf'
    }, placeholderStyle),
    name: name,
    type: _type,
    password: type === 'password',
    value: value,
    defaultValue: defaultValue,
    placeholder: placeholder,
    disabled: disabled,
    maxLength: maxLength,
    onInput: onChange,
    onFocus: onFocus,
    onBlur: onBlur
  });

  var renderLabel = function renderLabel() {
    var new_colon = colon ? ':' : '';

    if (label) {
      return /*#__PURE__*/React.createElement(_one.View, null, "".concat(label, " ").concat(new_colon));
    }
  };

  var labelStyle = function labelStyle() {
    if (labelWidth) {
      return {
        width: (0, _utils.addUnit)(labelWidth)
      };
    }
  };

  return /*#__PURE__*/React.createElement(_cell.default, {
    className: (0, _classnames.default)(prefixCls, className),
    icon: icon,
    required: required,
    style: style,
    border: border,
    labelStyle: labelStyle(),
    label: renderLabel(),
    titleClass: (0, _classnames.default)("".concat(prefixCls, "__label"))
  }, /*#__PURE__*/React.createElement(_one.View, {
    className: "".concat(prefixCls, "-prefix")
  }, prefix), inputElement, /*#__PURE__*/React.createElement(_one.View, {
    className: "".concat(prefixCls, "-suffix")
  }, suffix));
};

var _default = myInput;
exports.default = _default;