'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = MultilineInput;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _pathHelpers = require('../helpers/pathHelpers');

var _ReadOnlyInput = require('./ReadOnlyInput');

var _ReadOnlyInput2 = _interopRequireDefault(_ReadOnlyInput);

var _MultilineInput = require('../../styles/cspace-input/MultilineInput.css');

var _MultilineInput2 = _interopRequireDefault(_MultilineInput);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var propTypes = {
  embedded: _react.PropTypes.bool,
  name: _react.PropTypes.string,
  parentPath: _pathHelpers.pathPropType,
  subpath: _pathHelpers.pathPropType,
  value: _react.PropTypes.string,
  readOnly: _react.PropTypes.bool
};

/**
 * A text input that accepts and is able to display multiple lines of text. This component takes up
 * more screen space when rendered than LineInput.
 */
function MultilineInput(props) {
  var embedded = props.embedded,
      value = props.value,
      readOnly = props.readOnly,
      parentPath = props.parentPath,
      subpath = props.subpath,
      remainingProps = _objectWithoutProperties(props, ['embedded', 'value', 'readOnly', 'parentPath', 'subpath']);

  if (readOnly) {
    return _react2.default.createElement(_ReadOnlyInput2.default, { value: value });
  }

  var className = embedded ? _MultilineInput2.default.embedded : _MultilineInput2.default.normal;
  var normalizedValue = value === null || typeof value === 'undefined' ? '' : value;

  return _react2.default.createElement('textarea', _extends({}, remainingProps, {
    className: className,
    readOnly: !remainingProps.onChange,
    value: normalizedValue
  }));
}

MultilineInput.propTypes = propTypes;