'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 = LineInput;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _ReadOnlyInput2 = _interopRequireDefault(_ReadOnlyInput);

var _LineInput = require('../../styles/cspace-input/LineInput.css');

var _LineInput2 = _interopRequireDefault(_LineInput);

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 only a single line of text. If a value prop is
 * supplied that contains a newline character, the behavior is unspecified; newline characters may
 * be stripped, replaced with other characters, or retained but not displayed. If this presents a
 * problem, use TextInput or MultilineInput.
 */
function LineInput(props) {
  var embedded = props.embedded,
      name = props.name,
      readOnly = props.readOnly,
      value = props.value,
      parentPath = props.parentPath,
      subpath = props.subpath,
      remainingProps = _objectWithoutProperties(props, ['embedded', 'name', 'readOnly', 'value', 'parentPath', 'subpath']);

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

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

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

LineInput.propTypes = propTypes;