"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_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),_index=require("../index");function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var Edit=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var a=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.state={value:a.props.value,editable:!1},a.handleChange=function(e){var t=e.target.value;a.setState({value:t})},a.check=function(){a.setState({editable:!1}),a.props.onChange&&a.props.onChange(a.state.value)},a.edit=function(){a.setState({editable:!0})},a}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidUpdate",value:function(){if(this.state.editable){this.inputComponent.focus();var e=this.inputComponent.input;if(null!=e.selectionStart)e.selectionStart=this.state.value.toString().length,e.selectionEnd=this.state.value.toString().length;else{var t=e.createTextRange();t.moveStart("character",e.value.length),t.collapse(!0),t.select()}}}},{key:"componentWillReceiveProps",value:function(e){this.props.value!==e.value&&this.setState((0,_extends3.default)({},this.state,{value:e.value}))}},{key:"render",value:function(){var t=this,e=this.state,a=e.value,r=e.editable;return React.createElement("div",{className:"editable-cell"},r?React.createElement("div",{className:"editable-cell-input-wrapper"},React.createElement(_index.Input,{ref:function(e){return t.inputComponent=e},value:a,onChange:this.handleChange,onPressEnter:this.check}),React.createElement(_index.Icon,{type:"check",className:"editable-cell-icon-check",onClick:this.check})):React.createElement("div",{className:"editable-cell-text-wrapper"},a||" ",React.createElement(_index.Icon,{type:"edit",className:"editable-cell-icon",onClick:this.edit})))}}]),t}(React.Component);exports.default=Edit,module.exports=exports.default;