"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _react=require("react"),React=_interopRequireWildcard(_react),_propTypes=require("prop-types"),PropTypes=_interopRequireWildcard(_propTypes),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_moment=require("moment"),_moment2=_interopRequireDefault(_moment),_index=require("../util/index");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}function noop(){}function getNow(){return(0,_moment2.default)()}function getNowByCurrentStateValue(e){return e?(0,_index.getTodayTime)(e):getNow()}var CalendarMixin={propTypes:{value:PropTypes.object,defaultValue:PropTypes.object,onKeyDown:PropTypes.func},getDefaultProps:function(){return{onKeyDown:noop}},getInitialState:function(){var e=this.props;return{value:e.value||e.defaultValue||getNow(),selectedValue:e.selectedValue||e.defaultSelectedValue}},componentWillReceiveProps:function(e){var t=e.value,a=e.selectedValue;"value"in e&&(t=t||e.defaultValue||getNowByCurrentStateValue(this.state.value),this.setState({value:t})),"selectedValue"in e&&this.setState({selectedValue:a})},onSelect:function(e,t){e&&this.setValue(e),this.setSelectedValue(e,t)},renderRoot:function(e){var t=void 0,a=this.props,s=a.prefixCls,r=((t={})[s]=1,t[s+"-hidden"]=!a.visible,t[a.className]=!!a.className,t[e.className]=!!e.className,t);return React.createElement("div",{ref:this.saveRoot,className:""+(0,_classnames2.default)(r),style:this.props.style,tabIndex:"0",onKeyDown:this.onKeyDown},e.children)},setSelectedValue:function(e,t){"selectedValue"in this.props||this.setState({selectedValue:e}),this.props.onSelect(e,t)},setValue:function(e){var t=this.state.value;"value"in this.props||this.setState({value:e}),(t&&e&&!t.isSame(e)||!t&&e||t&&!e)&&this.props.onChange(e)},isAllowedDate:function(e){var t=this.props.disabledDate,a=this.props.disabledTime;return(0,_index.isAllowedDate)(e,t,a)}};exports.default=CalendarMixin,module.exports=exports.default;