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; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-12 11:04:00
 * @LastEditTime: 2021-09-07 13:59:09
 * @FilePath: \young\components\field\index.tsx
 */
import * as React from 'react';
import { Input, View } from 'remax/one';
import classNames from 'classnames';
import { getPrefixCls } from './../common';
import Cell from '../cell';
import { addUnit } from './../_utils';
var prefixCls = 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(Input, {
    className: classNames(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(View, null, "".concat(label, " ").concat(new_colon));
    }
  };

  var labelStyle = function labelStyle() {
    if (labelWidth) {
      return {
        width: addUnit(labelWidth)
      };
    }
  };

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

export default myInput;