"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _constants = require("../../constants");

var _FormField = _interopRequireDefault(require("../FormField"));

var _Input = _interopRequireDefault(require("../Input"));

var _TextArea = _interopRequireDefault(require("../TextArea"));

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.

/* eslint-disable react/prefer-stateless-function */

/**
 * `FormFieldText` component is used for entering of user data in text format.
 *
 * [FormField](#!/FormField) with [InputNumber](#!/InputNumber) can be used for entering of integer numbers.
 * @since 0.0.58
 */
class FormFieldText extends _react.Component {
  render() {
    const {
      baseClassName,
      className,
      size,
      placeholder,
      multiline,
      rows,
      autoFocus,
      autoComplete,
      autoheight,
      ...props
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_FormField.default, (0, _extends2.default)({
      className: (0, _classnames.default)(baseClassName, {
        ["".concat(baseClassName, "--multiline")]: multiline
      }, className)
    }, props), ({
      getId,
      getName,
      getValue,
      setValue,
      isDisabled
    }) => multiline ? /*#__PURE__*/_react.default.createElement(_TextArea.default, {
      id: getId(),
      name: getName(),
      value: getValue(''),
      onChange: e => setValue(e.target.value),
      disabled: isDisabled(),
      size: size,
      rows: rows,
      placeholder: placeholder,
      autoFocus: autoFocus,
      autoComplete: autoComplete,
      autoheight: autoheight
    }) : /*#__PURE__*/_react.default.createElement(_Input.default, {
      id: getId(),
      name: getName(),
      className: "".concat(baseClassName, "__input"),
      value: getValue(''),
      onChange: e => setValue(e.target.value),
      disabled: isDisabled(),
      size: size,
      placeholder: placeholder,
      autoFocus: autoFocus,
      autoComplete: autoComplete
    }));
  }

}

FormFieldText.propTypes = {
  /**
   * Size of the input
   * @since 0.0.58
   */
  size: _propTypes.default.oneOf(['sm', 'md', 'lg', 'xl', 'fill']),

  /**
   * If `true`, a textarea element will be rendered.
   * @since 1.3.0
   */
  multiline: _propTypes.default.bool,

  /**
   * Number of rows to display when multiline option is set to true.
   * @since 1.3.0
   */
  rows: _propTypes.default.oneOfType([_propTypes.default.number.isRequired, _propTypes.default.shape({
    min: _propTypes.default.number.isRequired,
    max: _propTypes.default.number.isRequired
  })]),

  /**
   * Placeholder of the input
   * @since 0.0.58
   */
  placeholder: _propTypes.default.string,

  /**
   * Disabled state of field.
   * @since 0.2.0
   */
  disabled: _propTypes.default.bool,

  /**
   * The browser will automatically focus on the component upon rendering the screen
   * @since 1.9.0
   */
  autoFocus: _propTypes.default.bool,

  /**
   * Whether the value of the control can be automatically completed by the browser or not.
   * @since 2.5.1
   */
  autoComplete: _propTypes.default.oneOf(['on', 'off']),

  /**
   * If 'true', a field will be multiple
   * @since 1.12.0
   */
  multi: _propTypes.default.bool,

  /**
   * @ignore
   */
  className: _propTypes.default.string,

  /**
   * @ignore
   */
  baseClassName: _propTypes.default.string,

  /**
   * Adjust height automatically when multiline option is set to true.
   * @since 1.9.0
   */
  autoheight: _propTypes.default.bool
};
FormFieldText.defaultProps = {
  size: undefined,
  placeholder: undefined,
  disabled: undefined,
  multiline: false,
  rows: 4,
  autoFocus: undefined,
  autoComplete: undefined,
  multi: undefined,
  className: undefined,
  baseClassName: "".concat(_constants.CLS_PREFIX, "form-field-text"),
  autoheight: false
};
var _default = FormFieldText;
exports.default = _default;