import*as React from"react";import*as ReactDOM from"react-dom";import createReactClass from"create-react-class";import*as PropTypes from"prop-types";import*as moment from"moment";var DateInput=createReactClass({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,n=this.props,s=n.disabledDate,i=n.format,o=n.onChange;if(t){var r=moment(t,i,!0);if(!r.isValid())return void this.setState({invalid:!0});if((a=this.props.value.clone()).year(r.year()).month(r.month()).date(r.date()).hour(r.hour()).minute(r.minute()).second(r.second()),!a||s&&s(a))return void this.setState({invalid:!0});var c=this.props.selectedValue;c&&a?c.isSame(a)||o(a):c!==a&&o(a)}else o(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,n=t.str,s=e.locale,i=e.prefixCls,o=e.placeholder,r=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 "+r,value:n,disabled:e.disabled,placeholder:o,onChange:this.onInputChange})),e.showClear?React.createElement("a",{className:i+"-clear-btn",role:"button",title:s.clear,onClick:this.onClear}):null)}});export default DateInput;