"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _react=require("react"),React=_interopRequireWildcard(_react),_reactDom=require("react-dom"),ReactDOM=_interopRequireWildcard(_reactDom),_createReactClass=require("create-react-class"),_createReactClass2=_interopRequireDefault(_createReactClass),_propTypes=require("prop-types"),PropTypes=_interopRequireWildcard(_propTypes),_moment=require("moment"),moment=_interopRequireWildcard(_moment);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}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}var DateInput=(0,_createReactClass2.default)({displayName:"DateInput",propTypes:{prefixCls:PropTypes.string,timePicker:PropTypes.object,value:PropTypes.object,disabledTime:PropTypes.any,format:PropTypes.string,locale:PropTypes.object,disabledDate:PropTypes.func,onChange:PropTypes.func,onClear:PropTypes.func,placeholder:PropTypes.string,onSelect:PropTypes.func,selectedValue:PropTypes.object},getInitialState:function(){var e=this.props.selectedValue;return{str:e&&e.format(this.props.format)||"",invalid:!1}},componentWillReceiveProps:function(e){this.cachedSelectionStart=this.dateInputInstance.selectionStart,this.cachedSelectionEnd=this.dateInputInstance.selectionEnd;var t=e.selectedValue;this.setState({str:t&&t.format(e.format)||"",invalid:!1})},componentDidUpdate:function(){this.state.invalid||this.dateInputInstance.setSelectionRange(this.cachedSelectionStart,this.cachedSelectionEnd)},onInputChange:function(e){var t=e.target.value;this.setState({str:t});var a=void 0,r=this.props,n=r.disabledDate,i=r.format,s=r.onChange;if(t){var o=moment(t,i,!0);if(!o.isValid())return void this.setState({invalid:!0});if((a=this.props.value.clone()).year(o.year()).month(o.month()).date(o.date()).hour(o.hour()).minute(o.minute()).second(o.second()),!a||n&&n(a))return void this.setState({invalid:!0});var c=this.props.selectedValue;c&&a?c.isSame(a)||s(a):c!==a&&s(a)}else s(null);this.setState({invalid:!1})},onClear:function(){this.setState({str:""}),this.props.onClear(null)},getRootDOMNode:function(){return ReactDOM.findDOMNode(this)},focus:function(){this.dateInputInstance&&this.dateInputInstance.focus()},saveDateInput:function(e){this.dateInputInstance=e},render:function(){var e=this.props,t=this.state,a=t.invalid,r=t.str,n=e.locale,i=e.prefixCls,s=e.placeholder,o=a?i+"-input-invalid":"";return React.createElement("div",{className:i+"-input-wrap"},React.createElement("div",{className:i+"-date-input-wrap"},React.createElement("input",{ref:this.saveDateInput,className:i+"-input "+o,value:r,disabled:e.disabled,placeholder:s,onChange:this.onInputChange})),e.showClear?React.createElement("a",{className:i+"-clear-btn",role:"button",title:n.clear,onClick:this.onClear}):null)}});exports.default=DateInput,module.exports=exports.default;