"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),_createChainedFunction=require("rc-util/es/createChainedFunction"),_createChainedFunction2=_interopRequireDefault(_createChainedFunction),_KeyCode=require("rc-util/es/KeyCode"),_KeyCode2=_interopRequireDefault(_KeyCode),_placements=require("./picker/placements"),_placements2=_interopRequireDefault(_placements),_rcTrigger=require("rc-trigger"),_rcTrigger2=_interopRequireDefault(_rcTrigger);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 n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function noop(){}function refFn(e,t){this[e]=t}var Picker=(0,_createReactClass2.default)({displayName:"Picker",propTypes:{animation:PropTypes.oneOfType([PropTypes.func,PropTypes.string]),disabled:PropTypes.bool,transitionName:PropTypes.string,onChange:PropTypes.func,onOpenChange:PropTypes.func,children:PropTypes.func,getCalendarContainer:PropTypes.func,calendar:PropTypes.element,style:PropTypes.object,open:PropTypes.bool,defaultOpen:PropTypes.bool,prefixCls:PropTypes.string,placement:PropTypes.any,value:PropTypes.oneOfType([PropTypes.object,PropTypes.array]),defaultValue:PropTypes.oneOfType([PropTypes.object,PropTypes.array]),align:PropTypes.object},getDefaultProps:function(){return{prefixCls:"rc-calendar-picker",style:{},align:{},placement:"bottomLeft",defaultOpen:!1,onChange:noop,onOpenChange:noop}},getInitialState:function(){var e=this.props,t=void 0;t="open"in e?e.open:e.defaultOpen;var n=e.value||e.defaultValue;return this.saveCalendarRef=refFn.bind(this,"calendarInstance"),{open:t,value:n}},componentWillReceiveProps:function(e){var t=e.value,n=e.open;"value"in e&&this.setState({value:t}),void 0!==n&&this.setState({open:n})},componentDidUpdate:function(e,t){!t.open&&this.state.open&&(this.focusTimeout=setTimeout(this.focusCalendar,0,this))},componentWillUnmount:function(){clearTimeout(this.focusTimeout)},onCalendarKeyDown:function(e){e.keyCode===_KeyCode2.default.ESC&&(e.stopPropagation(),this.close(this.focus))},onCalendarSelect:function(e,t){var n=1<arguments.length&&void 0!==t?t:{},o=this.props;"value"in o||this.setState({value:e}),"keyboard"!==n.source&&(o.calendar.props.timePicker||"dateInput"===n.source)&&"todayButton"!==n.source||this.close(this.focus),o.onChange(e)},onKeyDown:function(e){e.keyCode!==_KeyCode2.default.DOWN||this.state.open||(this.open(),e.preventDefault())},onCalendarOk:function(){this.close(this.focus)},onCalendarClear:function(){this.close(this.focus)},onVisibleChange:function(e){this.setOpen(e)},getCalendarElement:function(){var e=this.props,t=this.state,n=e.calendar.props,o=t.value,a=o,r={ref:this.saveCalendarRef,defaultValue:a||n.defaultValue,selectedValue:o,onKeyDown:this.onCalendarKeyDown,onOk:(0,_createChainedFunction2.default)(n.onOk,this.onCalendarOk),onSelect:(0,_createChainedFunction2.default)(n.onSelect,this.onCalendarSelect),onClear:(0,_createChainedFunction2.default)(n.onClear,this.onCalendarClear)};return React.cloneElement(e.calendar,r)},setOpen:function(e,t){var n=this.props.onOpenChange;this.state.open!==e&&("open"in this.props||this.setState({open:e},t),n(e))},open:function(e){this.setOpen(!0,e)},close:function(e){this.setOpen(!1,e)},focus:function(){this.state.open||ReactDOM.findDOMNode(this).focus()},focusCalendar:function(){this.state.open&&null!==this.calendarInstance&&this.calendarInstance.focus()},render:function(){var e=this.props,t=e.prefixCls,n=e.placement,o=e.style,a=e.getCalendarContainer,r=e.align,i=e.animation,p=e.disabled,s=e.transitionName,l=e.children,c=this.state;return React.createElement(_rcTrigger2.default,{popup:this.getCalendarElement(),popupAlign:r,builtinPlacements:_placements2.default,popupPlacement:n,action:p&&!c.open?[]:["click"],destroyPopupOnHide:!0,getPopupContainer:a,popupStyle:o,popupAnimation:i,popupTransitionName:s,popupVisible:c.open,onPopupVisibleChange:this.onVisibleChange,prefixCls:t},React.cloneElement(l(c,e),{onKeyDown:this.onKeyDown}))}});exports.default=Picker,module.exports=exports.default;