import _extends from"babel-runtime/helpers/extends";import _defineProperty from"babel-runtime/helpers/defineProperty";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 moment from"moment";import MonthCalendar from"../calendarbase/MonthCalendar";import RcDatePicker from"../calendarbase/Picker";import classNames from"classnames";import omit from"omit.js";import Icon from"../icon";import warning from"../_util/warning";import callMoment from"../_util/callMoment";export default function createPicker(e){var t;return(t=function(t){function a(e){_classCallCheck(this,a);var t=_possibleConstructorReturn(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,e));t.renderFooter=function(){var e=t.props,a=e.prefixCls,r=e.renderExtraFooter;return r?React.createElement("div",{className:a+"-footer-extra"},r.apply(void 0,arguments)):null},t.clearSelection=function(e){e.preventDefault(),e.stopPropagation(),t.handleChange(null)},t.handleChange=function(e){var a=t.props;"value"in a||t.setState({value:e,showDate:e}),a.onChange(e,e&&e.format(a.format)||"")},t.handleCalendarChange=function(e){t.setState({showDate:e})},t.saveInput=function(e){t.input=e};var r=e.value||e.defaultValue;if(r&&!moment.isMoment(r))throw new Error("The value/defaultValue of DatePicker or MonthPicker must be a moment object after `dtd@2.0`, see: #");return t.state={value:r,showDate:r},t}return _inherits(a,t),_createClass(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 t,a=this,r=this.state,n=r.value,o=r.showDate,l=omit(this.props,["onChange"]),s=l.prefixCls,i=l.locale,c=l.localeCode,m="placeholder"in l?l.placeholder:i.lang.placeholder,u=l.showTime?l.disabledTime:null,d=classNames((_defineProperty(t={},s+"-time",l.showTime),_defineProperty(t,s+"-month",MonthCalendar===e),t));n&&c&&n.locale(c);var p={},h={};l.showTime?h={onSelect:this.handleChange}:p={onChange:this.handleChange},"mode"in l&&(h.mode=l.mode),warning(!("onOK"in l),"It should be `DatePicker[onOk]` or `MonthPicker[onOk]`, instead of `onOK`!");var f=React.createElement(e,_extends({},h,{disabledDate:l.disabledDate,disabledTime:u,locale:i.lang,timePicker:l.timePicker,defaultValue:l.defaultPickerValue||callMoment(moment),dateInputPlaceholder:m,prefixCls:s,className:d,onOk:l.onOk,dateRender:l.dateRender,format:l.format,showToday:l.showToday,monthCellContentRender:l.monthCellContentRender,renderFooter:this.renderFooter,onPanelChange:l.onPanelChange,onChange:this.handleCalendarChange,value:o})),C=!l.disabled&&l.allowClear&&n?React.createElement(Icon,{type:"close-circle",className:s+"-picker-clear",onClick:this.clearSelection}):null;return React.createElement("span",{id:l.id,className:classNames(l.className,l.pickerClass),style:l.style,onFocus:l.onFocus,onBlur:l.onBlur},React.createElement(RcDatePicker,_extends({},l,p,{calendar:f,value:n,prefixCls:s+"-picker-container",style:l.popupStyle}),function(e){var t=e.value;return React.createElement("div",null,React.createElement("input",{ref:a.saveInput,disabled:l.disabled,readOnly:!0,value:t&&t.format(l.format)||"",placeholder:m,className:l.pickerInputClass}),C,React.createElement("span",{className:s+"-picker-icon"}))}))}}]),a}(React.Component)).defaultProps={prefixCls:"dt-calendar",allowClear:!0,showToday:!0},t};