"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_omit=require("omit.js"),_omit2=_interopRequireDefault(_omit),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_calculateNodeHeight=require("./calculateNodeHeight"),_calculateNodeHeight2=_interopRequireDefault(_calculateNodeHeight);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function onNextFrame(e){return window.requestAnimationFrame?window.requestAnimationFrame(e):window.setTimeout(e,1)}function clearNextFrameAction(e){window.cancelAnimationFrame?window.cancelAnimationFrame(e):window.clearTimeout(e)}var TextArea=function(e){function t(){(0,_classCallCheck3.default)(this,t);var n=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return n.state={textareaStyles:{}},n.resizeTextarea=function(){var e=n.props.autosize;if(e&&n.textAreaRef){var t=e?e.minRows:null,r=e?e.maxRows:null,a=(0,_calculateNodeHeight2.default)(n.textAreaRef,!1,t,r);n.setState({textareaStyles:a})}},n.handleTextareaChange=function(e){"value"in n.props||n.resizeTextarea();var t=n.props.onChange;t&&t(e)},n.handleKeyDown=function(e){var t=n.props,r=t.onPressEnter,a=t.onKeyDown;13===e.keyCode&&r&&r(e),a&&a(e)},n.saveTextAreaRef=function(e){n.textAreaRef=e},n}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidMount",value:function(){this.resizeTextarea()}},{key:"componentWillReceiveProps",value:function(e){this.props.value!==e.value&&(this.nextFrameActionId&&clearNextFrameAction(this.nextFrameActionId),this.nextFrameActionId=onNextFrame(this.resizeTextarea))}},{key:"focus",value:function(){this.textAreaRef.focus()}},{key:"blur",value:function(){this.textAreaRef.blur()}},{key:"getTextAreaClassName",value:function(){var e=this.props,t=e.prefixCls,r=e.className,a=e.disabled;return(0,_classnames2.default)(t,r,(0,_defineProperty3.default)({},t+"-disabled",a))}},{key:"render",value:function(){var e=this.props,t=(0,_omit2.default)(e,["prefixCls","onPressEnter","autosize"]),r=(0,_extends3.default)({},e.style,this.state.textareaStyles);return"value"in t&&(t.value=t.value||""),React.createElement("textarea",(0,_extends3.default)({},t,{className:this.getTextAreaClassName(),style:r,onKeyDown:this.handleKeyDown,onChange:this.handleTextareaChange,ref:this.saveTextAreaRef}))}}]),t}(React.Component);(exports.default=TextArea).defaultProps={prefixCls:"dt-input"},module.exports=exports.default;