"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _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),_propTypes=require("prop-types"),PropTypes=_interopRequireWildcard(_propTypes),_moment=require("moment"),_moment2=_interopRequireDefault(_moment);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}}var Header=function(e){function n(e){(0,_classCallCheck3.default)(this,n);var C=(0,_possibleConstructorReturn3.default)(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));C.onInputChange=function(e){var t=e.target.value;C.setState({str:t});var r=C.props,n=r.format,o=r.hourOptions,s=r.minuteOptions,i=r.secondOptions,a=r.disabledHours,u=r.disabledMinutes,l=r.disabledSeconds,p=r.onChange,c=r.allowEmpty;if(t){var d=C.props.value,f=C.getProtoValue().clone(),h=(0,_moment2.default)(t,n,!0);if(!h.isValid())return void C.setState({invalid:!0});if(f.hour(h.hour()).minute(h.minute()).second(h.second()),o.indexOf(f.hour())<0||s.indexOf(f.minute())<0||i.indexOf(f.second())<0)return void C.setState({invalid:!0});var y=a(),m=u(f.hour()),v=l(f.hour(),f.minute());if(y&&0<=y.indexOf(f.hour())||m&&0<=m.indexOf(f.minute())||v&&0<=v.indexOf(f.second()))return void C.setState({invalid:!0});if(d){if(d.hour()!==f.hour()||d.minute()!==f.minute()||d.second()!==f.second()){var _=d.clone();_.hour(f.hour()),_.minute(f.minute()),_.second(f.second()),p(_)}}else d!==f&&p(f)}else{if(!c)return void C.setState({invalid:!0});p(null)}C.setState({invalid:!1})},C.onKeyDown=function(e){var t=C.props,r=t.onEsc,n=t.onKeyDown;27===e.keyCode&&r(),n(e)},C.onClear=function(){C.setState({str:""}),C.props.onClear()};var t=e.value,r=e.format;return C.state={str:t&&t.format(r)||"",invalid:!1},C}return(0,_inherits3.default)(n,e),(0,_createClass3.default)(n,[{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,r=e.format;this.setState({str:t&&t.format(r)||"",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,r=e.placeholder,n=e.inputReadOnly,o=this.state,s=o.invalid,i=o.str,a=s?t+"-input-invalid":"";return React.createElement("input",{className:t+"-input  "+a,onKeyDown:this.onKeyDown,value:i,placeholder:r,onChange:this.onInputChange,readOnly:!!n})}},{key:"render",value:function(){var e=this.props.prefixCls;return React.createElement("div",{className:e+"-input-wrap"},this.getInput(),this.getClearButton())}}]),n}(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},exports.default=Header,module.exports=exports.default;