'use strict';

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

var _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _View = require('../View');

var _View2 = _interopRequireDefault(_View);

var _styles = require('../helpers/styles');

var _theme = require('../const/theme.js');

var _helpers = require('./helpers');

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var TextInputControl = function (_React$Component) {
	_inherits(TextInputControl, _React$Component);

	function TextInputControl() {
		_classCallCheck(this, TextInputControl);

		return _possibleConstructorReturn(this, (TextInputControl.__proto__ || Object.getPrototypeOf(TextInputControl)).apply(this, arguments));
	}

	_createClass(TextInputControl, [{
		key: '_renderControl',
		value: function _renderControl() {
			var props = this.props;

			return _react2.default.createElement(props.isMultiLine ? 'textarea' : 'input', Object.assign({}, {
				value: props.value,
				disabled: props.isDisabled,
				autoFocus: props.autoFocus,
				onFocus: props.onFocus,
				onBlur: props.onBlur,
				onChange: props.onChange,
				onKeyDown: props.onKeyDown,
				onKeyPress: props.onKeyPress,
				onKeyUp: props.onKeyUp,
				className: (0, _styles.css)(STYLE.control, STYLE.getPreset('size', props.size), props.isMultiLine && STYLE.textarea)
			}, props.isMultiLine && { rows: props.rows }));
		}
	}, {
		key: '_renderPlaceholder',
		value: function _renderPlaceholder() {
			var props = this.props;

			if (!props.placeholder || props.value) {
				return null;
			}

			return _jsx('div', {
				className: (0, _styles.css)(STYLE.placeholder, STYLE.getPreset('placeholderSize', props.size))
			}, void 0, props.placeholder);
		}
	}, {
		key: 'render',
		value: function render() {
			return _jsx(_View2.default, {
				styles: [STYLE.controlRoot]
			}, void 0, this._renderPlaceholder(), _jsx(_View2.default, {
				styles: [STYLE.controlWrapper]
			}, void 0, this._renderControl()));
		}
	}]);

	return TextInputControl;
}(_react2.default.Component);

TextInputControl.__TEXT_INPUT_CONTROL__ = true;
exports.default = TextInputControl;


var STYLE = _styles.StyleSheet.create(Object.assign((0, _helpers.generateTextStyles)(), (0, _helpers.generateTextStyles)('placeholderSize'), {
	controlRoot: {
		position: 'relative',
		flex: 1
	},
	controlWrapper: {
		position: 'relative',
		flex: 1
	},
	control: {
		position: 'relative',
		display: 'inline-block',
		verticalAlign: 'top',
		margin: 0,
		padding: 0,
		border: 'none',
		outline: 'none',
		lineHeight: '1rem',
		background: 'transparent',
		minWidth: '40px',
		width: '100%',
		cursor: 'text',
		resize: 'vertical'
	},
	placeholder: {
		position: 'absolute',
		top: 0,
		left: 0,
		width: '100%',
		color: _theme.COLOR.MUTED,
		background: 'transparent',
		whiteSpace: 'nowrap',
		overflow: 'hidden',
		textOverflow: 'ellipsis'
	},
	textarea: {
		height: 'auto!important'
	}
}));