"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_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),_react=require("react"),React=_interopRequireWildcard(_react),_moment=require("moment"),moment=_interopRequireWildcard(_moment),_calendarbase=require("../calendarbase"),_calendarbase2=_interopRequireDefault(_calendarbase),_Picker=require("../calendarbase/Picker"),_Picker2=_interopRequireDefault(_Picker),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_icon=require("../icon"),_icon2=_interopRequireDefault(_icon);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var a={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(a[t]=e[t]);return a.default=e,a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function formatValue(e,a){return e&&e.format(a)||""}var WeekPicker=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var r=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));r.weekDateRender=function(e){var a=r.state.value,t=r.props.prefixCls;return a&&e.year()===a.year()&&e.week()===a.week()?React.createElement("div",{className:t+"-selected-day"},React.createElement("div",{className:t+"-date"},e.date())):React.createElement("div",{className:t+"-calendar-date"},e.date())},r.handleChange=function(e){"value"in r.props||r.setState({value:e}),r.props.onChange(e,formatValue(e,r.props.format))},r.clearSelection=function(e){e.preventDefault(),e.stopPropagation(),r.handleChange(null)},r.saveInput=function(e){r.input=e};var a=e.value||e.defaultValue;if(a&&!moment.isMoment(a))throw new Error("The value/defaultValue of DatePicker or MonthPicker must be a moment object after `dtd@2.0`, see: #");return r.state={value:a},r}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{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 t=this,e=this.props,r=e.prefixCls,a=e.className,l=e.disabled,n=e.pickerClass,s=e.popupStyle,i=e.pickerInputClass,u=e.format,o=e.allowClear,c=e.locale,p=e.localeCode,d=e.disabledDate,f=this.state.value;f&&p&&f.locale(p);var _="placeholder"in this.props?this.props.placeholder:c.lang.placeholder,m=React.createElement(_calendarbase2.default,{showWeekNumber:!0,dateRender:this.weekDateRender,prefixCls:r,format:u,locale:c.lang,showDateInput:!1,showToday:!1,disabledDate:d}),h=!l&&o&&this.state.value?React.createElement(_icon2.default,{type:"close-circle",className:r+"-picker-clear",onClick:this.clearSelection}):null;return React.createElement("span",{className:(0,_classnames2.default)(a,n),id:this.props.id},React.createElement(_Picker2.default,(0,_extends3.default)({},this.props,{calendar:m,prefixCls:r+"-picker-container",value:f,onChange:this.handleChange,style:s}),function(e){var a=e.value;return React.createElement("span",null,React.createElement("input",{ref:t.saveInput,disabled:l,readOnly:!0,value:a&&a.format(u)||"",placeholder:_,className:i,onFocus:t.props.onFocus,onBlur:t.props.onBlur}),h,React.createElement("span",{className:r+"-picker-icon"}))}))}}]),t}(React.Component);(exports.default=WeekPicker).defaultProps={format:"YYYY-wo",allowClear:!0},module.exports=exports.default;