import _extends from"babel-runtime/helpers/extends";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 Calendar from"../calendarbase";import RcDatePicker from"../calendarbase/Picker";import classNames from"classnames";import Icon from"../icon";function formatValue(e,a){return e&&e.format(a)||""}var WeekPicker=function(e){function a(e){_classCallCheck(this,a);var t=_possibleConstructorReturn(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,e));t.weekDateRender=function(e){var a=t.state.value,r=t.props.prefixCls;return a&&e.year()===a.year()&&e.week()===a.week()?React.createElement("div",{className:r+"-selected-day"},React.createElement("div",{className:r+"-date"},e.date())):React.createElement("div",{className:r+"-calendar-date"},e.date())},t.handleChange=function(e){"value"in t.props||t.setState({value:e}),t.props.onChange(e,formatValue(e,t.props.format))},t.clearSelection=function(e){e.preventDefault(),e.stopPropagation(),t.handleChange(null)},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},t}return _inherits(a,e),_createClass(a,[{key:"componentWillReceiveProps",value:function(e){"value"in e&&this.setState({value:e.value})}},{key:"focus",value:function(){this.input.focus()}},{key:"blur",value:function(){this.input.blur()}},{key:"render",value:function(){var e=this,a=this.props,t=a.prefixCls,r=a.className,l=a.disabled,s=a.pickerClass,n=a.popupStyle,o=a.pickerInputClass,c=a.format,i=a.allowClear,p=a.locale,u=a.localeCode,m=a.disabledDate,d=this.state.value;d&&u&&d.locale(u);var f="placeholder"in this.props?this.props.placeholder:p.lang.placeholder,h=React.createElement(Calendar,{showWeekNumber:!0,dateRender:this.weekDateRender,prefixCls:t,format:c,locale:p.lang,showDateInput:!1,showToday:!1,disabledDate:m}),v=!l&&i&&this.state.value?React.createElement(Icon,{type:"close-circle",className:t+"-picker-clear",onClick:this.clearSelection}):null;return React.createElement("span",{className:classNames(r,s),id:this.props.id},React.createElement(RcDatePicker,_extends({},this.props,{calendar:h,prefixCls:t+"-picker-container",value:d,onChange:this.handleChange,style:n}),function(a){var r=a.value;return React.createElement("span",null,React.createElement("input",{ref:e.saveInput,disabled:l,readOnly:!0,value:r&&r.format(c)||"",placeholder:f,className:o,onFocus:e.props.onFocus,onBlur:e.props.onBlur}),v,React.createElement("span",{className:t+"-picker-icon"}))}))}}]),a}(React.Component);export default WeekPicker;WeekPicker.defaultProps={format:"YYYY-wo",allowClear:!0};