import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import*as PropTypes from"prop-types";import moment from"moment";var Header=function(e){function t(e){_classCallCheck(this,t);var n=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));n.onInputChange=function(e){var t=e.target.value;n.setState({str:t});var o=n.props,r=o.format,s=o.hourOptions,a=o.minuteOptions,i=o.secondOptions,p=o.disabledHours,l=o.disabledMinutes,u=o.disabledSeconds,c=o.onChange,d=o.allowEmpty;if(t){var f=n.props.value,m=n.getProtoValue().clone(),h=moment(t,r,!0);if(!h.isValid())return void n.setState({invalid:!0});if(m.hour(h.hour()).minute(h.minute()).second(h.second()),s.indexOf(m.hour())<0||a.indexOf(m.minute())<0||i.indexOf(m.second())<0)return void n.setState({invalid:!0});var y=p(),v=l(m.hour()),C=u(m.hour(),m.minute());if(y&&y.indexOf(m.hour())>=0||v&&v.indexOf(m.minute())>=0||C&&C.indexOf(m.second())>=0)return void n.setState({invalid:!0});if(f){if(f.hour()!==m.hour()||f.minute()!==m.minute()||f.second()!==m.second()){var P=f.clone();P.hour(m.hour()),P.minute(m.minute()),P.second(m.second()),c(P)}}else f!==m&&c(m)}else{if(!d)return void n.setState({invalid:!0});c(null)}n.setState({invalid:!1})},n.onKeyDown=function(e){var t=n.props,o=t.onEsc,r=t.onKeyDown;27===e.keyCode&&o(),r(e)},n.onClear=function(){n.setState({str:""}),n.props.onClear()};var o=e.value,r=e.format;return n.state={str:o&&o.format(r)||"",invalid:!1},n}return _inherits(t,e),_createClass(t,[{key:"componentDidMount",value:function(){var e=this;this.props.focusOnOpen&&(window.requestAnimationFrame||window.setTimeout)(function(){e.refs.input.focus(),e.refs.input.select()})}},{key:"componentWillReceiveProps",value:function(e){var t=e.value,n=e.format;this.setState({str:t&&t.format(n)||"",invalid:!1})}},{key:"getClearButton",value:function(){var e=this.props,t=e.prefixCls;return e.allowEmpty?React.createElement("a",{className:t+"-clear-btn",role:"button",title:this.props.clearText,onMouseDown:this.onClear}):null}},{key:"getProtoValue",value:function(){return this.props.value||this.props.defaultOpenValue}},{key:"getInput",value:function(){var e=this.props,t=e.prefixCls,n=e.placeholder,o=e.inputReadOnly,r=this.state,s=r.invalid,a=r.str,i=s?t+"-input-invalid":"";return React.createElement("input",{className:t+"-input  "+i,onKeyDown:this.onKeyDown,value:a,placeholder:n,onChange:this.onInputChange,readOnly:!!o})}},{key:"render",value:function(){var e=this.props.prefixCls;return React.createElement("div",{className:e+"-input-wrap"},this.getInput(),this.getClearButton())}}]),t}(React.Component);Header.propTypes={format:PropTypes.string,prefixCls:PropTypes.string,disabledDate:PropTypes.func,placeholder:PropTypes.string,clearText:PropTypes.string,value:PropTypes.object,inputReadOnly:PropTypes.bool,hourOptions:PropTypes.array,minuteOptions:PropTypes.array,secondOptions:PropTypes.array,disabledHours:PropTypes.func,disabledMinutes:PropTypes.func,disabledSeconds:PropTypes.func,onChange:PropTypes.func,onClear:PropTypes.func,onEsc:PropTypes.func,allowEmpty:PropTypes.bool,defaultOpenValue:PropTypes.object,currentSelectPanel:PropTypes.string,focusOnOpen:PropTypes.bool,onKeyDown:PropTypes.func},Header.defaultProps={inputReadOnly:!1};export default Header;