"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_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);exports.default=createPicker;var _react=require("react"),React=_interopRequireWildcard(_react),_moment=require("moment"),moment=_interopRequireWildcard(_moment),_MonthCalendar=require("../calendarbase/MonthCalendar"),_MonthCalendar2=_interopRequireDefault(_MonthCalendar),_Picker=require("../calendarbase/Picker"),_Picker2=_interopRequireDefault(_Picker),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_omit=require("omit.js"),_omit2=_interopRequireDefault(_omit),_icon=require("../icon"),_icon2=_interopRequireDefault(_icon),_warning=require("../_util/warning"),_warning2=_interopRequireDefault(_warning),_callMoment=require("../_util/callMoment"),_callMoment2=_interopRequireDefault(_callMoment);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 _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function createPicker(m){var e,t;return t=React.Component,(0,_inherits3.default)(a,t),(0,_createClass3.default)(a,[{key:"componentWillReceiveProps",value:function(e){"value"in e&&this.setState({value:e.value,showDate:e.value})}},{key:"focus",value:function(){this.input.focus()}},{key:"blur",value:function(){this.input.blur()}},{key:"render",value:function(){var e,a=this,t=this.state,r=t.value,l=t.showDate,n=(0,_omit2.default)(this.props,["onChange"]),o=n.prefixCls,i=n.locale,s=n.localeCode,u="placeholder"in n?n.placeholder:i.lang.placeholder,c=n.showTime?n.disabledTime:null,d=(0,_classnames2.default)((e={},(0,_defineProperty3.default)(e,o+"-time",n.showTime),(0,_defineProperty3.default)(e,o+"-month",_MonthCalendar2.default===m),e));r&&s&&r.locale(s);var _={},p={};n.showTime?p={onSelect:this.handleChange}:_={onChange:this.handleChange},"mode"in n&&(p.mode=n.mode),(0,_warning2.default)(!("onOK"in n),"It should be `DatePicker[onOk]` or `MonthPicker[onOk]`, instead of `onOK`!");var f=React.createElement(m,(0,_extends3.default)({},p,{disabledDate:n.disabledDate,disabledTime:c,locale:i.lang,timePicker:n.timePicker,defaultValue:n.defaultPickerValue||(0,_callMoment2.default)(moment),dateInputPlaceholder:u,prefixCls:o,className:d,onOk:n.onOk,dateRender:n.dateRender,format:n.format,showToday:n.showToday,monthCellContentRender:n.monthCellContentRender,renderFooter:this.renderFooter,onPanelChange:n.onPanelChange,onChange:this.handleCalendarChange,value:l})),h=!n.disabled&&n.allowClear&&r?React.createElement(_icon2.default,{type:"close-circle",className:o+"-picker-clear",onClick:this.clearSelection}):null;return React.createElement("span",{id:n.id,className:(0,_classnames2.default)(n.className,n.pickerClass),style:n.style,onFocus:n.onFocus,onBlur:n.onBlur},React.createElement(_Picker2.default,(0,_extends3.default)({},n,_,{calendar:f,value:r,prefixCls:o+"-picker-container",style:n.popupStyle}),function(e){var t=e.value;return React.createElement("div",null,React.createElement("input",{ref:a.saveInput,disabled:n.disabled,readOnly:!0,value:t&&t.format(n.format)||"",placeholder:u,className:n.pickerInputClass}),h,React.createElement("span",{className:o+"-picker-icon"}))}))}}]),(e=a).defaultProps={prefixCls:"dt-calendar",allowClear:!0,showToday:!0},e;function a(e){(0,_classCallCheck3.default)(this,a);var r=(0,_possibleConstructorReturn3.default)(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,e));r.renderFooter=function(){var e=r.props,t=e.prefixCls,a=e.renderExtraFooter;return a?React.createElement("div",{className:t+"-footer-extra"},a.apply(void 0,arguments)):null},r.clearSelection=function(e){e.preventDefault(),e.stopPropagation(),r.handleChange(null)},r.handleChange=function(e){var t=r.props;"value"in t||r.setState({value:e,showDate:e}),t.onChange(e,e&&e.format(t.format)||"")},r.handleCalendarChange=function(e){r.setState({showDate:e})},r.saveInput=function(e){r.input=e};var t=e.value||e.defaultValue;if(t&&!moment.isMoment(t))throw new Error("The value/defaultValue of DatePicker or MonthPicker must be a moment object after `dtd@2.0`, see: #");return r.state={value:t,showDate:t},r}}module.exports=exports.default;