Liferay.Loader.define("analytics-reports-web@2.0.38/js/context/ChartStateContext",["module","exports","require","liferay!frontend-js-react-web$react"],(function(t,e,a){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.ChartStateContextProvider=function({children:t,publishDate:e,timeRange:a,timeSpanKey:r}){const[o,s]=(0,n.useReducer)(c,i(i({},g),{},{publishDate:e,timeRange:a,timeSpanKey:r}));return n.default.createElement(O.Provider,{value:s},n.default.createElement(C.Provider,{value:o},t))},e.useDateTitle=l,e.useIsPreviousPeriodButtonDisabled=function(){const{publishDate:t}=(0,n.useContext)(C),{firstDate:e}=l(),a=new Date(t);return e<a},e.ChartStateContext=e.ChartDispatchContext=void 0;var n=function(t){if(t&&t.__esModule)return t;if(null===t||"object"!=typeof t&&"function"!=typeof t)return{default:t};var e=r();if(e&&e.has(t))return e.get(t);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=n?Object.getOwnPropertyDescriptor(t,o):null;i&&(i.get||i.set)?Object.defineProperty(a,o,i):a[o]=t[o]}a.default=t,e&&e.set(t,a);return a}(a("liferay!frontend-js-react-web$react"));function r(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return r=function(){return t},t}function o(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),a.push.apply(a,n)}return a}function i(t){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?o(Object(a),!0).forEach((function(e){s(t,e,a[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):o(Object(a)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))}))}return t}function s(t,e,a){return e in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}const t="ADD_DATA_SET_ITEMS",p="CHANGE_TIME_SPAN_KEY",d="NEXT_TIME_SPAN",y="PREV_TIME_SPAN",h="SET_LOADING",b="SET_PIE_CHART_LOADING",g={dataSet:{histogram:[],keyList:[],totals:[]},lineChartloading:!0,pieChartLoading:!0,publishDate:null,timeRange:null,timeSpanKey:null,timeSpanOffset:0},m={histogram:[],value:null},D="last-7-days",S="last-30-days",O=(0,n.createContext)((()=>{}));e.ChartDispatchContext=O;const C=(0,n.createContext)(g);function l(){const{timeRange:t,timeSpanKey:e,timeSpanOffset:a}=(0,n.useContext)(C),r=new Date(t.startDate.concat("T00:00:00")),o=new Date(t.endDate.concat("T00:00:00")),i=e===D?7:e===S?30:0;return e===S&&r.setDate(r.getDate()+6-(i-1)),a>0?(o.setDate(o.getDate()-i*a),r.setDate(r.getDate()-i*a),{firstDate:r,lastDate:o}):{firstDate:r,lastDate:o}}function c(e,a){let n;switch(a.type){case t:n=u(e),n=[...a.payload.keys].reduce(((t,e)=>{var n,r;const o=null!==(n=null===(r=a.payload.dataSetItems)||void 0===r?void 0:r[e])&&void 0!==n?n:m;return function(t,e,a){const n=!0===t.lineChartLoading?void 0:t.dataSet;return i(i({},t),{},{dataSet:f({key:e.key,newData:e.dataSetItem,previousDataSet:n,publishDate:t.publishDate,timeSpanComparator:e.timeSpanComparator,validAnalyticsConnection:a}),lineChartLoading:!1})}(t,i(i({},a.payload),{},{dataSetItem:o,key:e}),a.validAnalyticsConnection)}),e);break;case p:n=i(i({},e),{},{lineChartLoading:!0,timeSpanKey:a.payload.key,timeSpanOffset:0});break;case d:n=i(i({},e),{},{lineChartLoading:!0,timeSpanOffset:e.timeSpanOffset-1});break;case y:n=i(i({},e),{},{lineChartLoading:!0,timeSpanOffset:e.timeSpanOffset+1});break;case h:n=u(e);break;case b:n=i(i({},e),{},{pieChartLoading:a.payload.loading});break;default:n=e}return n}function u(t){if(!t.dataSet)return i(i({},t),{},{lineChartLoading:!0});if(t.dataSet.histogram.length)return i(i({},t),{},{lineChartLoading:!1});const e=t.dataSet.histogram.map((t=>{const e={},a=Object.entries(t);for(const t in a){const[n,r]=a[t];e[n]="label"===n?r:null}return e})),a=Object.entries(t.dataSet.totals),n={};for(const t in a){const[e]=a[t];n[e]=null}return i(i({},t),{},{dataSet:i(i({},t.dataSet),{},{histogram:e,totals:n}),lineChartLoading:!0})}function f({key:t,newData:e,previousDataSet:a={histogram:[],keyList:[],totals:[]},publishDate:n,timeSpanComparator:r,validAnalyticsConnection:o}){const s={keyList:[...a.keyList,t],totals:i(i({},a.totals),{},{[t]:e.value})},l=new Date(n),c=e.histogram.map((e=>{const a=new Date(e.key);return a<l&&l-a>r||!o?{[t]:null,label:e.key}:{[t]:e.value,label:e.key}}));if(0===c.length)return i(i({},s),{},{histogram:a.histogram});let u=0;const f=[];for(;u<e.histogram.length;)a.histogram[u]?c[u].label===a.histogram[u].label&&f.push(i(i({},c[u]),a.histogram[u])):f.push(i({},c[u])),u+=1;return s.histogram=f,s}e.ChartStateContext=C}}));
//# sourceMappingURL=ChartStateContext.js.map