"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),React=_interopRequireWildcard(require("react")),_classnames=_interopRequireDefault(require("classnames")),_propTypes=_interopRequireDefault(require("prop-types")),_withStyles=_interopRequireDefault(require("../../hoc/withStyles")),_ErrorBoundary=_interopRequireDefault(require("../../hoc/ErrorBoundary")),_TriangleArrow=_interopRequireDefault(require("../../bosons/TriangleArrow")),_FieldLabel=_interopRequireDefault(require("../../bosons/FieldLabel")),_moment=_interopRequireDefault(require("moment")),_styles=_interopRequireDefault(require("./styles"));function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function(){var result,Super=(0,_getPrototypeOf2["default"])(Derived);if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2["default"])(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else result=Super.apply(this,arguments);return(0,_possibleConstructorReturn2["default"])(this,result)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}_moment["default"].locale("en-us",{week:{dow:1// Monday is the first day of the week.
}});var WeekPeriod=/*#__PURE__*/function(_React$Component){function WeekPeriod(_props){var _this;return(0,_classCallCheck2["default"])(this,WeekPeriod),_this=_super.call(this,_props),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_this),"_updateWeekPeriod",function(props,updateType){var state=_this.state,finalYear="year"===updateType?props.year:state.year,finalWeek="week"===updateType?props.week:state.week,startWeekDay=(0,_moment["default"])().year(finalYear).week(finalWeek).startOf("week").format(),endWeekDay=(0,_moment["default"])().year(finalYear).week(finalWeek).endOf("week").format(),weekObj={week:finalWeek,year:finalYear,month:(0,_moment["default"])(endWeekDay).month(),startWeekDay:startWeekDay,endWeekDay:endWeekDay};_this.setState(weekObj,function(){props.onWeekChange(weekObj)})}),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_this),"_handleWeekChange",function(isNext){return function(){var _this$state=_this.state,year=_this$state.year,week=_this$state.week,onWeekChange=_this.props.onWeekChange,newWeek=(0,_moment["default"])().year(year).week(week);isNext?newWeek.add(1,"w"):newWeek.subtract(1,"w");var startWeekDay=newWeek.startOf("week").format(),endWeekDay=newWeek.endOf("week").format(),weekObj={week:newWeek.week(),year:(0,_moment["default"])(endWeekDay).year(),month:(0,_moment["default"])(endWeekDay).month(),startWeekDay:startWeekDay,endWeekDay:endWeekDay};_this.setState(weekObj,function(){onWeekChange(weekObj)})}}),_this.state={week:_props.week,year:_props.year,startWeekDay:(0,_moment["default"])().year(_props.year).week(_props.week).startOf("week").format(),endWeekDay:(0,_moment["default"])().year(_props.year).week(_props.week).endOf("week").format()},_this}(0,_inherits2["default"])(WeekPeriod,_React$Component);var _super=_createSuper(WeekPeriod);return(0,_createClass2["default"])(WeekPeriod,[{key:"componentDidMount",value:function componentDidMount(){this._updateWeekPeriod(this.props,"mount")}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){var props=this.props,state=this.state;props.week!==prevProps.week&&props.week!==state.week&&this._updateWeekPeriod(props,"week"),props.year!==prevProps.year&&props.year!==state.year&&this._updateWeekPeriod(props,"year")}},{key:"render",value:function render(){var classes=this.props.classes,_this$state2=this.state,startWeekDay=_this$state2.startWeekDay,endWeekDay=_this$state2.endWeekDay;return/*#__PURE__*/React.createElement(_ErrorBoundary["default"],null,/*#__PURE__*/React.createElement("div",{className:classes.component},/*#__PURE__*/React.createElement(_FieldLabel["default"],{label:"Week Period"}),/*#__PURE__*/React.createElement("div",{className:classes.root},/*#__PURE__*/React.createElement("div",{className:(0,_classnames["default"])(classes.button,classes.prevButton),onClick:this._handleWeekChange(!1)},/*#__PURE__*/React.createElement(_TriangleArrow["default"],{direction:"left",classes:{arrow:classes.arrow}})),/*#__PURE__*/React.createElement("div",{className:classes.dateText},(0,_moment["default"])(startWeekDay).format("DD MMM YYYY")," -"," ",(0,_moment["default"])(endWeekDay).format("DD MMM YYYY")),/*#__PURE__*/React.createElement("div",{className:(0,_classnames["default"])(classes.button,classes.nextButton),onClick:this._handleWeekChange(!0)},/*#__PURE__*/React.createElement(_TriangleArrow["default"],{direction:"right",classes:{arrow:classes.arrow}})))))}}]),WeekPeriod}(React.Component);(0,_defineProperty2["default"])(WeekPeriod,"propTypes",{week:_propTypes["default"].number,year:_propTypes["default"].number,onWeekChange:_propTypes["default"].func,classes:_propTypes["default"].object// will come from withStyles HOC
}),(0,_defineProperty2["default"])(WeekPeriod,"defaultProps",{week:(0,_moment["default"])().week(),year:(0,_moment["default"])().year(),onWeekChange:function onWeekChange(){}});var _default=(0,_withStyles["default"])(_styles["default"])(WeekPeriod);exports["default"]=_default;