aboutsummaryrefslogblamecommitdiff
path: root/dist/index.js
blob: 5974a44b6d140cf0de13330c6054005c4e9a446b (plain) (tree)
1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
!function(e){function t(t){for(var a,s,i=t[0],l=t[1],c=t[2],f=0,d=[];f<i.length;f++)s=i[f],r[s]&&d.push(r[s][0]),r[s]=0;for(a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a]);for(u&&u(t);d.length;)d.shift()();return o.push.apply(o,c||[]),n()}function n(){for(var e,t=0;t<o.length;t++){for(var n=o[t],a=!0,i=1;i<n.length;i++){var l=n[i];0!==r[l]&&(a=!1)}a&&(o.splice(t--,1),e=s(s.s=n[0]))}return e}var a={},r={1:0},o=[];function s(t){if(a[t])return a[t].exports;var n=a[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,s),n.l=!0,n.exports}s.m=e,s.c=a,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)s.d(n,a,function(t){return e[t]}.bind(null,a));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="";var i=window.webpackJsonp=window.webpackJsonp||[],l=i.push.bind(i);i.push=t,i=i.slice();for(var c=0;c<i.length;c++)t(i[c]);var u=l;o.push([849,2]),n()}({27:function(e,t,n){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,"c",function(){return f}),n.d(t,"a",function(){return p}),n.d(t,"b",function(){return h});var s="updatePatterns",i="getPatterns",l="updateCalendars",c="getCalendars",u="getCalEvents",f=Object.freeze({updatePatterns:Symbol(s),getPatterns:Symbol(i),updateCalendars:Symbol(l),getCalendars:Symbol(c),getCalEvents:Symbol(u)});function d(e){switch(e){case f.updatePatterns:return s;case f.getPatterns:return i;case f.updateCalendars:return l;case f.getCalendars:return c;case f.getCalEvents:return u;default:console.error("unreachable")}}var p=function(){function e(t,n,r){a(this,e),this.id=t,this.type=n,this.data=r}var t,n,o;return t=e,(n=[{key:"genResp",value:function(t){return new e(this.id,this.type,t)}},{key:"deflate",value:function(){return{id:this.id,type:d(this.type),data:this.data}}}])&&r(t.prototype,n),o&&r(t,o),e}();o(p,"inflate",function(e){return new p(e.id,function(e){switch(e){case s:return f.updatePatterns;case i:return f.getPatterns;case l:return f.updateCalendars;case c:return f.getCalendars;case u:return f.getCalEvents;default:console.error("unreachable")}}(e.type),e.data)});var h=function e(t){var n=this;a(this,e),o(this,"sendMsg",function(e){var t,a,r=e.type,o=e.data,s=n.requestCallback,i=new Promise(function(e){t=e});return a=s.ids.length>0?s.ids.pop():s.maxId++,s.inFlight[a]=t,n.port.postMessage(new p(a,r,o).deflate()),i});var r=chrome.runtime.connect({name:t});r.onMessage.addListener(function(e){console.log(e);var t=(e.type,n.requestCallback),a=t.inFlight[e.id];console.assert(void 0!==a),t.ids.push(e.id),a(e)}),this.port=r,this.requestCallback={inFlight:{},ids:[],maxId:0}}},43:function(e,t,n){"use strict";n.d(t,"e",function(){return p}),n.d(t,"b",function(){return h}),n.d(t,"f",function(){return m}),n.d(t,"g",function(){return g}),n.d(t,"c",function(){return y}),n.d(t,"d",function(){return v}),n.d(t,"a",function(){return j});var a=n(109),r=n.n(a);function o(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function s(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],a=!0,r=!1,o=void 0;try{for(var s,i=e[Symbol.iterator]();!(a=(s=i.next()).done)&&(n.push(s.value),!t||n.length!==t);a=!0);}catch(e){r=!0,o=e}finally{try{a||null==i.return||i.return()}finally{if(r)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l="https://www.googleapis.com/calendar/v3",c=Object.freeze({invalidSyncToken:Symbol("invalidSyncToken"),notLoggedIn:Symbol("notLoggedIn"),notLoggedOut:Symbol("notLoggedOut"),otherError:Symbol("otherError")});function u(e){return Object.entries(e).filter(function(e){var t=i(e,2);t[0];return t[1]}).map(function(e){var t=i(e,2),n=t[0],a=t[1];return"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(a))}).join("&")}var f=null;function d(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise(function(t){return chrome.identity.getAuthToken({interactive:e},function(e){return t([e,!chrome.runtime.lastError])})}).then(function(e){var t=i(e,2),n=t[0];if(t[1])return n;throw c.notLoggedIn})}function p(){return null===f?d(!1).then(function(){return f=!0}).catch(function(){return f=!1}).then(function(){return f}):Promise.resolve(f)}function h(){return p().then(function(e){if(e)return d(!1);throw c.notLoggedIn})}function m(){return p().then(function(e){if(e)throw c.notLoggedOut;return d(!0).then(function(){return f=!0})})}function g(){return h().then(function(e){return fetch("https://accounts.google.com/o/oauth2/revoke?".concat(u({token:e})),{method:"GET",async:!0}).then(function(t){return function(e){return new Promise(function(t){return chrome.identity.removeCachedAuthToken({token:e},function(){return t()})})}(e)})}).then(function(){return f=!1})}function y(e){return fetch("".concat(l,"/users/me/calendarList?").concat(u({access_token:e})),{method:"GET",async:!0}).then(function(e){return e.json()}).then(function(e){return e.items})}function v(e){return fetch("".concat(l,"/colors?").concat(u({access_token:e})),{method:"GET",async:!0}).then(function(e){return e.json()})}function b(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:100,i=[];return function n(f,d){return fetch("".concat(l,"/calendars/").concat(e,"/events?").concat(u({access_token:t,pageToken:f,syncToken:d,timeMin:a,timeMax:r,maxResults:o})),{method:"GET",async:!0}).then(function(e){if(200===e.status)return e.json();throw 410===e.status?c.invalidSyncToken:c.otherError}).then(function(e){return i.push.apply(i,s(e.items)),e.nextPageToken?n(e.nextPageToken,""):{nextSyncToken:e.nextSyncToken,results:i}})}("",n)}var j=function(){function e(t,n){var a=this,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{maxCachedItems:100,nDaysPerSlot:10,largeQuery:10};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.calId=t,this.name=n,this.syncToken="",this.cache=new r.a({max:o.maxCachedItems,dispose:function(e,t){return a.onRemoveSlot(e,t)}}),this.eventMeta={},this.options=o,this.divider=864e5*this.options.nDaysPerSlot}var t,n,a;return t=e,(n=[{key:"dateToCacheKey",value:function(e){return Math.floor(e/this.divider)}},{key:"dateRangeToCacheKeys",value:function(e){return{start:this.dateToCacheKey(e.start),end:this.dateToCacheKey(new Date(e.end.getTime()-1))}}},{key:"getSlot",value:function(e){if(this.cache.has(e))return this.cache.get(e);var t={};return this.cache.set(e,t),t}},{key:"onRemoveSlot",value:function(e,t){for(var n in t){console.assert(this.eventMeta[n]);var a=this.eventMeta[n].keys;a.delete(e),0===a.size&&delete this.eventMeta[n]}}},{key:"slotStartDate",value:function(e){return new Date(e*this.divider)}},{key:"slotEndDate",value:function(e){return new Date((e+1)*this.divider)}},{key:"addEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.eventMeta.hasOwnProperty(e.id)&&this.removeEvent(e);for(var n=this.dateRangeToCacheKeys(e),a=n.start,r=n.end,o=this.cache.length,s=new Set,i=a;i<=r;i++)s.add(i),this.cache.has(i)||o++;if(this.eventMeta[e.id]={keys:s,summary:e.summary},t||!(o>this.options.maxCachedItems))if(a===r)this.getSlot(a)[e.id]={start:e.start,end:e.end,id:e.id};else{this.getSlot(a)[e.id]={start:e.start,end:this.slotEndDate(a),id:e.id},this.getSlot(r)[e.id]={start:this.slotStartDate(r),end:e.end,id:e.id};for(var l=a+1;l<r;l++)this.getSlot(l)[e.id]={start:this.slotStartDate(l),end:this.slotEndDate(l),id:e.id}}}},{key:"removeEvent",value:function(e){var t=this,n=this.eventMeta[e.id].keys;console.assert(n),n.forEach(function(n){return delete t.getSlot(n)[e.id]}),delete this.eventMeta[e.id]}},{key:"getSlotEvents",value:function(e,t,n){var a=this.getSlot(e),r=[];for(var o in a)a[o].start>=n||a[o].end<=t||r.push({id:o,start:a[o].start<t?t:a[o].start,end:a[o].end>n?n:a[o].end,summary:this.eventMeta[o].summary});return r}},{key:"getCachedEvents",value:function(e){for(var t=this.dateRangeToCacheKeys(e),n=t.start,a=t.end,r=this.getSlotEvents(n,e.start,e.end),o=n+1;o<a;o++){var i=this.getSlot(o);for(var l in i)r.push(i[l])}return a>n&&r.push.apply(r,s(this.getSlotEvents(a,e.start,e.end))),r}},{key:"sync",value:function(){var e=this;return this.token.then(function(t){return b(e.calId,t,e.syncToken).then(function(n){var a=n.results.map(function(n){return n.start?Promise.resolve(n):function(e,t,n){return fetch("".concat(l,"/calendars/").concat(e,"/events/").concat(t,"?").concat(u({access_token:n})),{method:"GET",async:!0}).then(function(e){return e.json()})}(e.calId,n.id,t)});return Promise.all(a).then(function(t){t.forEach(function(t){t.start=new Date(t.start.dateTime),t.end=new Date(t.end.dateTime),"confirmed"===t.status?e.addEvent(t):"cancelled"===t.status&&e.removeEvent(t)}),e.syncToken=n.nextSyncToken})})}).catch(function(t){if(t!==c.invalidSyncToken)throw t;e.syncToken="",e.sync()})}},{key:"getEvents",value:function(e,t){for(var n=this,a=this.dateRangeToCacheKeys({start:e,end:t}),r={},o=a.start;o<=a.end;o++)this.cache.has(o)||(r.hasOwnProperty("start")||(r.start=o),r.end=o);return console.log("start: ".concat(e," end: ").concat(t)),r.hasOwnProperty("start")?(console.assert(r.start<=r.end),r.end-r.start+1>this.options.largeQuery?(console.log("encounter large query, use direct fetch"),this.token.then(function(a){return b(n.calId,a,null,e.toISOString(),t.toISOString()).then(function(n){var a=[];return n.results.forEach(function(e){console.assert(e.start),e.start=new Date(e.start.dateTime),e.end=new Date(e.end.dateTime),a.push(e)}),a.filter(function(n){return!(n.start>=t||n.end<=e)}).map(function(n){return{id:n.id,start:n.start<e?e:n.start,end:n.end>t?t:n.end,summary:n.summary}})})})):(console.log("fetching short event list"),this.token.then(function(e){return b(n.calId,e,null,n.slotStartDate(r.start).toISOString(),n.slotEndDate(r.end).toISOString()).then(function(e){e.results.forEach(function(e){"confirmed"===e.status&&(console.assert(e.start),e.start=new Date(e.start.dateTime),e.end=new Date(e.end.dateTime),n.addEvent(e,!0))}),""===n.syncToken&&(n.syncToken=e.nextSyncToken)})}).then(function(){return n.sync()}).then(function(){return n.getCachedEvents({start:e,end:t})}))):(console.log("cache hit"),this.sync().then(function(){return n.getCachedEvents({start:e,end:t})}))}},{key:"token",get:function(){return h()}}])&&o(t.prototype,n),a&&o(t,a),e}()},467:function(e,t,n){"use strict";(function(e){n.d(t,"a",function(){return a});Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));function a(){"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(function(e){e.unregister()})}}).call(this,n(414))},589:function(e,t,n){var a={"./af":232,"./af.js":232,"./ar":233,"./ar-dz":234,"./ar-dz.js":234,"./ar-kw":235,"./ar-kw.js":235,"./ar-ly":236,"./ar-ly.js":236,"./ar-ma":237,"./ar-ma.js":237,"./ar-sa":238,"./ar-sa.js":238,"./ar-tn":239,"./ar-tn.js":239,"./ar.js":233,"./az":240,"./az.js":240,"./be":241,"./be.js":241,"./bg":242,"./bg.js":242,"./bm":243,"./bm.js":243,"./bn":244,"./bn.js":244,"./bo":245,"./bo.js":245,"./br":246,"./br.js":246,"./bs":247,"./bs.js":247,"./ca":248,"./ca.js":248,"./cs":249,"./cs.js":249,"./cv":250,"./cv.js":250,"./cy":251,"./cy.js":251,"./da":252,"./da.js":252,"./de":253,"./de-at":254,"./de-at.js":254,"./de-ch":255,"./de-ch.js":255,"./de.js":253,"./dv":256,"./dv.js":256,"./el":257,"./el.js":257,"./en-SG":258,"./en-SG.js":258,"./en-au":259,"./en-au.js":259,"./en-ca":260,"./en-ca.js":260,"./en-gb":261,"./en-gb.js":261,"./en-ie":262,"./en-ie.js":262,"./en-il":263,"./en-il.js":263,"./en-nz":264,"./en-nz.js":264,"./eo":265,"./eo.js":265,"./es":266,"./es-do":267,"./es-do.js":267,"./es-us":268,"./es-us.js":268,"./es.js":266,"./et":269,"./et.js":269,"./eu":270,"./eu.js":270,"./fa":271,"./fa.js":271,"./fi":272,"./fi.js":272,"./fo":273,"./fo.js":273,"./fr":274,"./fr-ca":275,"./fr-ca.js":275,"./fr-ch":276,"./fr-ch.js":276,"./fr.js":274,"./fy":277,"./fy.js":277,"./ga":278,"./ga.js":278,"./gd":279,"./gd.js":279,"./gl":280,"./gl.js":280,"./gom-latn":281,"./gom-latn.js":281,"./gu":282,"./gu.js":282,"./he":283,"./he.js":283,"./hi":284,"./hi.js":284,"./hr":285,"./hr.js":285,"./hu":286,"./hu.js":286,"./hy-am":287,"./hy-am.js":287,"./id":288,"./id.js":288,"./is":289,"./is.js":289,"./it":290,"./it-ch":291,"./it-ch.js":291,"./it.js":290,"./ja":292,"./ja.js":292,"./jv":293,"./jv.js":293,"./ka":294,"./ka.js":294,"./kk":295,"./kk.js":295,"./km":296,"./km.js":296,"./kn":297,"./kn.js":297,"./ko":298,"./ko.js":298,"./ku":299,"./ku.js":299,"./ky":300,"./ky.js":300,"./lb":301,"./lb.js":301,"./lo":302,"./lo.js":302,"./lt":303,"./lt.js":303,"./lv":304,"./lv.js":304,"./me":305,"./me.js":305,"./mi":306,"./mi.js":306,"./mk":307,"./mk.js":307,"./ml":308,"./ml.js":308,"./mn":309,"./mn.js":309,"./mr":310,"./mr.js":310,"./ms":311,"./ms-my":312,"./ms-my.js":312,"./ms.js":311,"./mt":313,"./mt.js":313,"./my":314,"./my.js":314,"./nb":315,"./nb.js":315,"./ne":316,"./ne.js":316,"./nl":317,"./nl-be":318,"./nl-be.js":318,"./nl.js":317,"./nn":319,"./nn.js":319,"./pa-in":320,"./pa-in.js":320,"./pl":321,"./pl.js":321,"./pt":322,"./pt-br":323,"./pt-br.js":323,"./pt.js":322,"./ro":324,"./ro.js":324,"./ru":325,"./ru.js":325,"./sd":326,"./sd.js":326,"./se":327,"./se.js":327,"./si":328,"./si.js":328,"./sk":329,"./sk.js":329,"./sl":330,"./sl.js":330,"./sq":331,"./sq.js":331,"./sr":332,"./sr-cyrl":333,"./sr-cyrl.js":333,"./sr.js":332,"./ss":334,"./ss.js":334,"./sv":335,"./sv.js":335,"./sw":336,"./sw.js":336,"./ta":337,"./ta.js":337,"./te":338,"./te.js":338,"./tet":339,"./tet.js":339,"./tg":340,"./tg.js":340,"./th":341,"./th.js":341,"./tl-ph":342,"./tl-ph.js":342,"./tlh":343,"./tlh.js":343,"./tr":344,"./tr.js":344,"./tzl":345,"./tzl.js":345,"./tzm":346,"./tzm-latn":347,"./tzm-latn.js":347,"./tzm.js":346,"./ug-cn":348,"./ug-cn.js":348,"./uk":349,"./uk.js":349,"./ur":350,"./ur.js":350,"./uz":351,"./uz-latn":352,"./uz-latn.js":352,"./uz.js":351,"./vi":353,"./vi.js":353,"./x-pseudo":354,"./x-pseudo.js":354,"./yo":355,"./yo.js":355,"./zh-cn":356,"./zh-cn.js":356,"./zh-hk":357,"./zh-hk.js":357,"./zh-tw":358,"./zh-tw.js":358};function r(e){var t=o(e);return n(t)}function o(e){var t=a[e];if(!(t+1)){var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}return t}r.keys=function(){return Object.keys(a)},r.resolve=o,e.exports=r,r.id=589},849:function(e,t,n){"use strict";n.r(t);var a=n(1),r=n.n(a),o=n(30),s=n.n(o),i=n(0),l=n.n(i),c=(n(475),n(28)),u=n(142),f=n.n(u),d=n(464),p=n.n(d),h=n(193),m=n.n(h),g=n(40),y=n.n(g),v=n(465),b=n.n(v),j=n(198),E=n.n(j),w=n(853),k=n(854),O=n(857),S=n(858),P=n(856),C=function(e){return r.a.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 98.905998 93.557997",version:"1.1",style:e.style},r.a.createElement("g",{id:"g13",transform:"translate(-153.533,-203.047)"},r.a.createElement("g",{id:"g29"},r.a.createElement("g",{id:"g27"},r.a.createElement("polygon",{id:"polygon7",points:"252.439,241.924 234.556,288.703 185.103,296.605 153.533,257.728 171.416,210.949 220.869,203.047 ",style:{fill:"#ff8000"}}),r.a.createElement("g",{id:"g11",transform:"translate(167.24355,224.20734)"},r.a.createElement("text",{id:"text9",style:{fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",fontStretch:"normal",fontSize:75,fontFamily:"TypoPRO Fantasque Sans Mono",fill:"#ffeade"},transform:"translate(0.586,49.072)"},"Cr"))))))},x=n(153),T=n.n(x),D=Object(c.createMuiTheme)({palette:{primary:{light:T.a[300],main:T.a[500],dark:T.a[700],contrastText:"#fff"}},typography:{useNextVariants:!0}}),R=(n(560),n(586),n(435)),M=n(115),_=n.n(M),I=n(46),z=n.n(I),A=n(71),B=n.n(A),N=n(73),L=n.n(N),G=n(37),q=n.n(G),W=n(150),F=n.n(W),H=n(53),K=n.n(H),U=n(43),V=n(27);function Y(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function $(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function J(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Q=function(){function e(t,n,a,r){Y(this,e),this.id=t,this.isRegex=n,this.value=a,this.label=r}var t,n,a;return t=e,(n=[{key:"regex",get:function(){return new RegExp(this.isRegex?this.value:"^".concat(this.value,"$"))}},{key:"isEmpty",get:function(){return null===this.label}}])&&$(t.prototype,n),a&&$(t,a),e}();J(Q,"emptyPattern",function(){return new Q(0,!0,"",null)}),J(Q,"anyPattern",function(){return new Q("any",!0,".*","Any")}),J(Q,"revive",function(e){return new Q(e.id,e.isRegex,e.value,e.label)});var X=function e(t,n,a,r){Y(this,e),this.name=t,this.idx=n,this.cal=a,this.event=r};J(X,"defaultPatternEntry",function(e){return new X("",e,Q.emptyPattern(),Q.anyPattern())}),J(X,"revive",function(e){return new X(e.name,e.idx,Q.revive(e.cal),Q.revive(e.event))});var Z=n(448),ee=n.n(Z),te=n(855),ne=n(468),ae=n(155),re=n(445);function oe(e){var t=e.cx,n=e.cy,a=e.x,o=e.y,s=e.fill,i=e.name,l="middle",c=0,u=0;return a<t-2?(c=-5,l="end"):a>t+2&&(c=5,l="start"),o<n-2?u=-5:o>n+2&&(u=10),r.a.createElement("text",{x:a,y:o,dx:c,dy:u,fill:s,textAnchor:l},"".concat(i))}function se(e){return r.a.createElement(q.a,{container:!0,spacing:0},r.a.createElement(q.a,{item:!0,xs:12,lg:6},r.a.createElement("div",{className:e.classes.patternTableWrapper},r.a.createElement(te.a,{width:400,height:250,className:e.classes.pieChart},r.a.createElement(ne.a,{data:e.patternGraphData,dataKey:"value",cx:200,cy:125,outerRadius:60,fill:ee.a[300],label:oe}),r.a.createElement(ae.a,{formatter:function(e){return"".concat(e.toFixed(2)," hr")}})))),r.a.createElement(q.a,{item:!0,xs:12,lg:6},r.a.createElement("div",{className:e.classes.patternTableWrapper},r.a.createElement(te.a,{width:400,height:250,className:e.classes.pieChart},r.a.createElement(ne.a,{data:e.calendarGraphData,dataKey:"value",cx:200,cy:125,innerRadius:40,outerRadius:70,fill:_.a[300],label:oe},e.calendarGraphData.map(function(e,t){return r.a.createElement(re.a,{key:t,fill:e.color})})),r.a.createElement(ae.a,{formatter:function(e){return"".concat(e.toFixed(2)," hr")}})))))}se.propTypes={patternGraphData:l.a.array.isRequired,calendarGraphData:l.a.array.isRequired};var ie=Object(c.withStyles)(function(e){return{pieChart:{margin:"0 auto"}}})(se),le=n(147),ce=n.n(le),ue=n(148),fe=n.n(ue),de=n(149),pe=n.n(de),he=n(62),me=n.n(he),ge=n(72),ye=n.n(ge),ve=n(192),be=n.n(ve),je=n(450),Ee=n.n(je),we=n(449),ke=n.n(we),Oe=n(141),Se=n.n(Oe),Pe=n(189),Ce=n.n(Pe);function xe(e){return(xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Te(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function De(e,t){return!t||"object"!==xe(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function Re(e){return(Re=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Me(e,t){return(Me=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var _e=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),De(this,Re(t).apply(this,arguments))}var n,a,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Me(e,t)}(t,r.a.Component),n=t,(a=[{key:"render",value:function(){var e=this,t=this.props.classes,n=[],a=this.props.options,o=new Q.emptyPattern;for(var s in a[o.id]=o,a){var i=a[s].isEmpty?r.a.createElement("span",{style:{color:this.props.theme.palette.primary.dark}},"Custom"):a[s].label;n.push(r.a.createElement(Ce.a,{key:s,value:s},i))}var l=this.props.value.isRegex?t.fieldRegex:t.fieldNoRegex;return r.a.createElement(B.a,null,r.a.createElement("span",null,r.a.createElement(Se.a,{value:this.props.value.id,onChange:function(t){var n;n=null==a[t.target.value].label?new Q(0,!0,e.props.value.isRegex?e.props.value.value:"^".concat(e.props.value.value,"$"),null):a[t.target.value],e.props.onChange({target:{value:n}})},className:l},n),null==this.props.value.label&&r.a.createElement(ce.a,{value:this.props.value.value,onChange:function(t){return e.props.onChange({target:{value:new Q(0,!0,t.target.value,null)}})}})))}}])&&Te(n.prototype,a),o&&Te(n,o),t}();_e.propTypes={classes:l.a.object.isRequired};var Ie=Object(c.withStyles)(function(e){return{fieldNoRegex:{width:200},fieldRegex:{marginRight:"0.5em"}}})(_e);function ze(e){return(ze="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ae(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function Be(e){return(Be=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Ne(e,t){return(Ne=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Le(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ge(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var qe=[{label:"Name",field:"name",elem:ce.a},{label:"Calendar",field:"cal",elem:Object(c.withTheme)(D)(function(e){var t={};for(var n in e.calendars)t[n]=new Q(n,!1,e.calendars[n].name,e.calendars[n].name);return r.a.createElement(Ie,{value:e.value,options:t,onChange:e.onChange,theme:e.theme})})},{label:"Event",field:"event",elem:Object(c.withTheme)(D)(function(e){var t=Q.anyPattern(),n={};return n[t.id]=t,r.a.createElement(Ie,{value:e.value,options:n,onChange:e.onChange,theme:e.theme})})}],We=function(e){function t(){var e,n,a,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,s=new Array(o),i=0;i<o;i++)s[i]=arguments[i];return a=this,r=(e=Be(t)).call.apply(e,[this].concat(s)),n=!r||"object"!==ze(r)&&"function"!=typeof r?Le(a):r,Ge(Le(Le(n)),"state",{page:0,rowsPerPage:5,activePattern:null}),Ge(Le(Le(n)),"handleChangePage",function(e,t){n.setState({page:t})}),Ge(Le(Le(n)),"handleChangeRowsPerPage",function(e){n.setState({rowsPerPage:e.target.value})}),n}var n,a,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ne(e,t)}(t,r.a.Component),n=t,(a=[{key:"render",value:function(){var e=this,t=this.props,n=t.classes,a=t.calendars,o=t.patterns,s=this.state,i=s.rowsPerPage,l=s.page,c=i-Math.min(i,o.length-l*i),u=o.slice(l*i,(l+1)*i).map(function(t){return r.a.createElement(me.a,{onMouseOver:function(){return e.setState({activePattern:t.idx})},onMouseOut:function(){return e.setState({activePattern:null})}},qe.map(function(n){var o=n.elem;return r.a.createElement(ye.a,null,r.a.createElement(o,{value:t[n.field],calendars:a,onChange:function(a){return e.props.onUpdatePattern(n.field,t.idx,a.target.value)}}))}),r.a.createElement("span",{className:e.state.activePattern===t.idx?n.deleteButtonShow:n.deleteButtonHide},r.a.createElement(ke.a,{className:n.deleteIcon,onClick:function(){return e.props.onRemovePattern(t.idx)}})))});return r.a.createElement("div",null,r.a.createElement("div",{className:n.patternTableWrapper},r.a.createElement(fe.a,{className:n.patternTable},r.a.createElement(be.a,null,r.a.createElement(me.a,null,qe.map(function(e,t){return r.a.createElement(ye.a,{key:t},e.label)}))),r.a.createElement(pe.a,null,u,c>0&&r.a.createElement(me.a,{style:{height:48*c}},r.a.createElement(ye.a,{colSpan:qe.length}))))),r.a.createElement(Ee.a,{rowsPerPageOptions:[5,10,25],component:"div",count:o.length,rowsPerPage:i,page:l,backIconButtonProps:{"aria-label":"Previous Page"},nextIconButtonProps:{"aria-label":"Next Page"},onChangePage:this.handleChangePage,onChangeRowsPerPage:this.handleChangeRowsPerPage}))}}])&&Ae(n.prototype,a),o&&Ae(n,o),t}();We.propTypes={classes:l.a.object.isRequired,patterns:l.a.array.isRequired,calendars:l.a.object.isRequired,onRemovePattern:l.a.func.isRequired,onUpdatePattern:l.a.func.isRequired};var Fe=Object(c.withStyles)(function(e){return{deleteButtonShow:{position:"absolute",right:0,height:48},deleteButtonHide:{display:"none"},deleteIcon:{height:"100%",cursor:"pointer"},patternTableWrapper:{overflowX:"auto",overflowY:"hidden"},patternTable:{minWidth:600}}})(We),He=n(6),Ke=n.n(He),Ue=n(453),Ve=n.n(Ue),Ye=n(454),$e=n.n(Ye),Je=n(195),Qe=n.n(Je),Xe=n(451),Ze=n.n(Xe),et=n(452),tt=n.n(et),nt=n(455),at=n.n(nt);function rt(){return(rt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function ot(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)n=o[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)n=o[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var st={error:Ze.a,warning:tt.a};var it=Object(c.withStyles)(function(e){return{error:{backgroundColor:e.palette.error.dark},warning:{backgroundColor:Ve.a[700]},icon:{fontSize:20},iconVariant:{opacity:.9,marginRight:e.spacing.unit},message:{display:"flex",alignItems:"center"}}})(function(e){var t=e.classes,n=e.className,a=e.message,o=e.variant,s=e.open,i=e.onClose,l=ot(e,["classes","className","message","variant","open","onClose"]),c=st[o];return r.a.createElement($e.a,{anchorOrigin:{vertical:"top",horizontal:"center"},open:s,autoHideDuration:1e4,onClose:i},r.a.createElement(Qe.a,rt({className:Ke()(t[o],n),"aria-describedby":"snackbar-content",message:r.a.createElement("span",{id:"snackbar-content",className:t.message},r.a.createElement(c,{className:Ke()(t.icon,t.iconVariant)}),a),action:[r.a.createElement(K.a,{key:"close","aria-label":"Close",color:"inherit",className:t.close,onClick:i},r.a.createElement(at.a,{className:t.icon}))]},l)))}),lt=n(456),ct=n.n(lt),ut=n(460),ft=n.n(ut),dt=n(458),pt=n.n(dt),ht=n(459),mt=n.n(ht),gt=n(457),yt=n.n(gt),vt=n(194),bt=n.n(vt);function jt(){return(jt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function Et(e){return r.a.createElement(bt.a,jt({direction:"up"},e))}var wt=function(e){return r.a.createElement(ct.a,{open:e.open,TransitionComponent:Et,keepMounted:!0,onClose:function(){return e.handleClose(!1)},"aria-labelledby":"alert-dialog-slide-title","aria-describedby":"alert-dialog-slide-description"},r.a.createElement(yt.a,{id:"alert-dialog-slide-title"},e.title),r.a.createElement(pt.a,null,r.a.createElement(mt.a,{id:"alert-dialog-slide-description"},e.message)),r.a.createElement(ft.a,null,r.a.createElement(z.a,{onClick:function(){return e.handleClose(!1)},color:"primary"},"No"),r.a.createElement(z.a,{onClick:function(){return e.handleClose(!0)},color:"primary"},"Yes")))};function kt(e){return(kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ot(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function St(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function Pt(e){return(Pt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Ct(e,t){return(Ct=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function xt(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Tt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Dt=[{name:"Work",value:10,color:_.a[300]},{name:"Wasted",value:10,color:_.a[300]}];var Rt=function(e){function t(e){var n,a,r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),a=this,r=Pt(t).call(this,e),n=!r||"object"!==kt(r)&&"function"!=typeof r?xt(a):r,Tt(xt(xt(n)),"state",{patterns:[],calendars:{},startDate:null,endDate:null,patternGraphData:Dt,calendarGraphData:Dt,snackBarOpen:!1,snackBarMsg:"unknown",snackBarVariant:"error",dialogOpen:!1,dialogMsg:{title:"",message:""}}),Tt(xt(xt(n)),"updatePattern",function(e,t,a){var r=n.state.patterns;r[t][e]=a,n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"analyze",patterns:r}}).then(function(){return n.setState({patterns:r})})}),Tt(xt(xt(n)),"removePattern",function(e){var t=n.state.patterns;t.splice(e,1);for(var a=0;a<t.length;a++)t[a].idx=a;n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"analyze",patterns:t}}).then(function(){return n.setState({patterns:t})})}),Tt(xt(xt(n)),"newPattern",function(){for(var e=[X.defaultPatternEntry(0)].concat(Ot(n.state.patterns)),t=1;t<e.length;t++)e[t].idx=t;n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"analyze",patterns:e}}).then(function(){return n.setState({patterns:e})})}),Tt(xt(xt(n)),"loadPatterns",function(e){n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"analyze",patterns:e}}).then(function(){return n.setState({patterns:e})})}),Tt(xt(xt(n)),"getCalEvents",function(e,t,a){return n.msgClient.sendMsg({type:V.c.getCalEvents,data:{id:e,start:t.getTime(),end:a.getTime()}}).then(function(e){return e.data.map(function(e){return{id:e.id,start:new Date(e.start),end:new Date(e.end)}})})}),Tt(xt(xt(n)),"analyze",function(){if(n.state.startDate&&n.state.endDate){var e=n.state.startDate.startOf("day").toDate(),t=n.state.endDate.startOf("day").toDate(),a=[],r=n.state.calendars,o=function(o){var s=function(e,t){return e.filter(function(e){return e.cal.regex.test(t)})}(n.state.patterns,r[o].name);s.length>0&&a.push(n.getCalEvents(o,e,t).then(function(e){return{id:o,events:e,patterns:s}}))};for(var s in r)o(s);Promise.all(a).then(function(e){console.log(e);var t={},a={},o={},s={};e.forEach(function(e){t[e.id]=e.events,a[e.id]=e.patterns});for(var i=0;i<n.state.patterns.length;i++)o[i]=0;var l=function(e){if(!t[e])return"continue";t[e].forEach(function(t){a[e].forEach(function(n){if(n.event.regex.test(t.summary)){s.hasOwnProperty(e)||(s[e]=0);var a=(t.end-t.start)/6e4;o[n.idx]+=a,s[e]+=a}})})};for(var c in r)l(c);for(var u=[],f=[],d=0;d<n.state.patterns.length;d++)u.push({name:n.state.patterns[d].name,value:o[d]/60});for(var c in s)f.push({name:r[c].name,value:s[c]/60,color:r[c].color.background});console.log(u,f),n.setState({patternGraphData:u,calendarGraphData:f})})}else n.handleSnackbarOpen("Please choose a valid time range.","error")}),Tt(xt(xt(n)),"reset",function(){n.handleDialogOpen("Reset","Are you sure to reset the patterns?").then(function(e){e&&(n.loadPatterns([]),n.setState({startDate:null,endDate:null}))})}),Tt(xt(xt(n)),"default",function(){n.handleDialogOpen("Load Default","Load the calendars as patterns?").then(function(e){e&&n.loadPatterns(Object.keys(n.state.calendars).map(function(e,t){var a=n.state.calendars[e];return new X(a.name,t,new Q(e,!1,a.name,a.name),Q.anyPattern())}))})}),Tt(xt(xt(n)),"handleSnackbarClose",function(e,t){"clickaway"!==t&&n.setState({snackBarOpen:!1})}),Tt(xt(xt(n)),"handleSnackbarOpen",function(e,t){n.setState({snackBarOpen:!0,snackBarMsg:e,snackBarVariant:t})}),Tt(xt(xt(n)),"handleDialogOpen",function(e,t){var a=new Promise(function(e){n.dialogPromiseResolver=e});return n.setState({dialogOpen:!0,dialogMsg:{title:e,message:t}}),a}),Tt(xt(xt(n)),"handleDialogClose",function(e){n.dialogPromiseResolver(e),n.setState({dialogOpen:!1})}),n.msgClient=new V.b("main"),n.msgClient.sendMsg({type:V.c.getPatterns,data:{id:"analyze"}}).then(function(e){n.setState({patterns:e.data.map(function(e){return X.revive(e)})})}),n.msgClient.sendMsg({type:V.c.getCalendars,data:{enabledOnly:!0}}).then(function(e){n.setState({calendars:e.data})}),U.e().then(function(e){return!e&&n.handleSnackbarOpen("Not logged in. Operating in offline mode.","warning")}),n.dialogPromiseResolver=null,n}var n,a,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ct(e,t)}(t,r.a.Component),n=t,(a=[{key:"render",value:function(){var e=this,t=this.props.classes;return r.a.createElement(q.a,{container:!0,spacing:16},r.a.createElement(wt,{title:this.state.dialogMsg.title,message:this.state.dialogMsg.message,open:this.state.dialogOpen,handleClose:this.handleDialogClose}),r.a.createElement(it,{message:this.state.snackBarMsg,open:this.state.snackBarOpen,variant:this.state.snackBarVariant,onClose:this.handleSnackbarClose}),r.a.createElement(q.a,{item:!0,md:6,xs:12},r.a.createElement(B.a,{fullWidth:!0},r.a.createElement(L.a,null,r.a.createElement(y.a,{variant:"h6",component:"h1",gutterBottom:!0},"Analyzed Events",r.a.createElement(K.a,{style:{marginBottom:"0.12em",marginLeft:"0.5em"},onClick:function(){return e.newPattern()}},r.a.createElement(F.a,null))),r.a.createElement(Fe,{patterns:this.state.patterns,calendars:this.state.calendars,onRemovePattern:this.removePattern,onUpdatePattern:this.updatePattern})),r.a.createElement(L.a,null,r.a.createElement(y.a,{variant:"h6",component:"h1",gutterBottom:!0},"Time Range"),r.a.createElement("div",{style:{textAlign:"center"}},r.a.createElement(R.DateRangePicker,{startDate:this.state.startDate,startDateId:"start_date_id",endDate:this.state.endDate,endDateId:"end_date_id",onDatesChange:function(t){var n=t.startDate,a=t.endDate;e.setState({startDate:n,endDate:a})},focusedInput:this.state.focusedInput,onFocusChange:function(t){return e.setState({focusedInput:t})},isOutsideRange:function(){return!1}}))),r.a.createElement("div",{className:t.buttonSpacer}),r.a.createElement(q.a,{container:!0,spacing:16},r.a.createElement(q.a,{item:!0,md:4,xs:12},r.a.createElement(L.a,null,r.a.createElement(z.a,{variant:"contained",color:"primary",onClick:this.default},"Load Default"))),r.a.createElement(q.a,{item:!0,md:4,xs:12},r.a.createElement(L.a,null,r.a.createElement(z.a,{variant:"contained",color:"primary",onClick:this.reset},"Reset"))),r.a.createElement(q.a,{item:!0,md:4,xs:12},r.a.createElement(L.a,null,r.a.createElement(z.a,{variant:"contained",color:"primary",onClick:this.analyze},"Analyze")))))),r.a.createElement(q.a,{item:!0,md:6,xs:12},r.a.createElement(y.a,{variant:"h6",component:"h1",gutterBottom:!0},"Results"),r.a.createElement(ie,{patternGraphData:this.state.patternGraphData,calendarGraphData:this.state.calendarGraphData})))}}])&&St(n.prototype,a),o&&St(n,o),t}();Rt.propTypes={classes:l.a.object.isRequired};var Mt=Object(c.withStyles)(function(e){return{buttonSpacer:{marginBottom:4*e.spacing.unit}}})(Rt),_t=n(461),It=n.n(_t),zt=n(191),At=n.n(zt),Bt=n(190),Nt=n.n(Bt),Lt=n(463),Gt=n.n(Lt),qt=n(462),Wt=n.n(qt);function Ft(e){return(Ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ht(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function Kt(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],a=!0,r=!1,o=void 0;try{for(var s,i=e[Symbol.iterator]();!(a=(s=i.next()).done)&&(n.push(s.value),!t||n.length!==t);a=!0);}catch(e){r=!0,o=e}finally{try{a||null==i.return||i.return()}finally{if(r)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function Ut(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function Vt(e){return(Vt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Yt(e,t){return(Yt=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function $t(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Jt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Qt=Object(c.withStyles)(function(e){return{body:{fontSize:16}}})(ye.a),Xt=Object(c.withStyles)(function(e){return{dense:{paddingTop:0,paddingBottom:0}}})(Nt.a),Zt=function(e){function t(e){var n,a,r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),a=this,r=Vt(t).call(this,e),n=!r||"object"!==Ft(r)&&"function"!=typeof r?$t(a):r,Jt($t($t(n)),"state",{isLoggedIn:!1,patterns:[],calendars:{},snackBarOpen:!1,snackBarMsg:"unknown",dialogOpen:!1,dialogMsg:{title:"",message:""}}),Jt($t($t(n)),"handleLogin",function(){U.f().then(function(){n.setState({isLoggedIn:!0}),n.loadAll(!0)}).catch(function(){return n.handleSnackbarOpen("Failed to login!")})}),Jt($t($t(n)),"handleLogout",function(){n.handleDialogOpen("Logout","Are you sure to logout?").then(function(e){e&&U.g().then(function(){n.setState({isLoggedIn:!1})}).catch(function(){return n.handleSnackbarOpen("Failed to logout!")})})}),Jt($t($t(n)),"handleToggleCalendar",function(e){var t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},a=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),a.forEach(function(t){Jt(e,t,n[t])})}return e}({},n.state.calendars);t[e].enabled=!t[e].enabled,n.msgClient.sendMsg({type:V.c.updateCalendars,data:t}).then(function(){return n.setState({calendars:t})})}),Jt($t($t(n)),"loadAll",function(e){var t=U.b().then(U.d).then(function(e){return e.calendar}),a=U.b().then(U.c);Promise.all([t,a]).then(function(t){var a=Kt(t,2),r=a[0],o=a[1],s={};o.forEach(function(e){s[e.id]={name:e.summary,color:r[e.colorId],enabled:!0}}),n.loadCalendars(s),e&&n.loadPatterns(o.map(function(e,t){return new X(e.summary,t,new Q(e.id,!1,e.summary,e.summary),Q.anyPattern())}),"main")})}),Jt($t($t(n)),"loadCalendars",function(e){for(var t in n.state.calendars)e.hasOwnProperty(t)&&(e[t].enabled=n.state.calendars[t].enabled);n.msgClient.sendMsg({type:V.c.updateCalendars,data:e}).then(function(){return n.setState({calendars:e})})}),Jt($t($t(n)),"loadPatterns",function(e,t){n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:t,patterns:e}}).then(function(){return n.setState({patterns:e})})}),Jt($t($t(n)),"updatePattern",function(e,t,a){var r=n.state.patterns;r[t][e]=a,n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"main",patterns:r}}).then(function(){return n.setState({patterns:r})})}),Jt($t($t(n)),"removePattern",function(e){var t=n.state.patterns;t.splice(e,1);for(var a=0;a<t.length;a++)t[a].idx=a;n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"main",patterns:t}}).then(function(){return n.setState({patterns:t})})}),Jt($t($t(n)),"newPattern",function(){for(var e=[X.defaultPatternEntry(0)].concat(Ht(n.state.patterns)),t=1;t<e.length;t++)e[t].idx=t;n.msgClient.sendMsg({type:V.c.updatePatterns,data:{id:"main",patterns:e}}).then(function(){return n.setState({patterns:e})})}),Jt($t($t(n)),"handleSnackbarClose",function(e,t){"clickaway"!==t&&n.setState({snackBarOpen:!1})}),Jt($t($t(n)),"handleSnackbarOpen",function(e){n.setState({snackBarOpen:!0,snackBarMsg:e})}),Jt($t($t(n)),"handleDialogOpen",function(e,t){var a=new Promise(function(e){n.dialogPromiseResolver=e});return n.setState({dialogOpen:!0,dialogMsg:{title:e,message:t}}),a}),Jt($t($t(n)),"handleDialogClose",function(e){n.dialogPromiseResolver(e),n.setState({dialogOpen:!1})}),n.msgClient=new V.b("main"),U.e().then(function(e){return n.setState({isLoggedIn:e})}),n.msgClient.sendMsg({type:V.c.getPatterns,data:{id:"main"}}).then(function(e){n.setState({patterns:e.data.map(function(e){return X.revive(e)})})}),n.msgClient.sendMsg({type:V.c.getCalendars,data:{enabledOnly:!1}}).then(function(e){n.setState({calendars:e.data})}),n.dialogPromiseResolver=null,n}var n,a,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Yt(e,t)}(t,r.a.Component),n=t,(a=[{key:"render",value:function(){var e=this,t=this.props.classes;return r.a.createElement("div",null,r.a.createElement(wt,{title:this.state.dialogMsg.title,message:this.state.dialogMsg.message,open:this.state.dialogOpen,handleClose:this.handleDialogClose}),r.a.createElement(it,{message:this.state.snackBarMsg,open:this.state.snackBarOpen,variant:"error",onClose:this.handleSnackbarClose}),r.a.createElement(y.a,{variant:"h6",component:"h1",gutterBottom:!0},"General"),r.a.createElement(fe.a,null,r.a.createElement(pe.a,null,r.a.createElement(me.a,null,r.a.createElement(Qt,{className:t.tableHead},"Account"),r.a.createElement(Qt,{className:t.tableContent},this.state.isLoggedIn&&r.a.createElement(z.a,{variant:"contained",color:"primary",onClick:this.handleLogout},"Logout")||r.a.createElement(z.a,{variant:"contained",color:"primary",onClick:this.handleLogin},"Login"))),r.a.createElement(me.a,null,r.a.createElement(Qt,{className:t.tableHead},r.a.createElement(K.a,{style:{marginBottom:"0.12em",marginRight:"0.5em"},onClick:function(){return e.loadAll(!1)},disabled:!this.state.isLoggedIn},r.a.createElement(It.a,null)),"Calendars"),r.a.createElement(Qt,{className:t.tableContent},this.state.isLoggedIn&&r.a.createElement(At.a,{className:t.calendarList},Object.keys(this.state.calendars).map(function(t){return r.a.createElement(Xt,{key:t,onClick:function(){return e.handleToggleCalendar(t)},disableGutters:!0,dense:!0,button:!0},r.a.createElement(Wt.a,{checked:e.state.calendars[t].enabled,disableRipple:!0}),r.a.createElement(Gt.a,{primary:e.state.calendars[t].name}))}))||"Please Login.")),r.a.createElement(me.a,null,r.a.createElement(Qt,{className:t.tableHead},r.a.createElement(K.a,{style:{marginBottom:"0.12em",marginRight:"0.5em"},onClick:function(){return e.newPattern()},disabled:!this.state.isLoggedIn},r.a.createElement(F.a,null)),"Tracked Events"),r.a.createElement(Qt,{className:t.tableContent},this.state.isLoggedIn&&r.a.createElement(B.a,{fullWidth:!0},r.a.createElement(Fe,{patterns:this.state.patterns,calendars:this.state.calendars,onRemovePattern:this.removePattern,onUpdatePattern:this.updatePattern}))||"Please Login.")))))}}])&&Ut(n.prototype,a),o&&Ut(n,o),t}();Zt.propTypes={classes:l.a.object.isRequired};var en=Object(c.withStyles)(function(e){return{tableHead:{verticalAlign:"top",textAlign:"right",lineHeight:"3em"},tableContent:{textAlign:"left",maxWidth:600},calendarList:{maxHeight:400,overflowY:"auto"}}})(Zt);function tn(e){return(tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function nn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function an(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function rn(e,t,n){return t&&an(e.prototype,t),n&&an(e,n),e}function on(e,t){return!t||"object"!==tn(t)&&"function"!=typeof t?un(e):t}function sn(e){return(sn=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ln(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&cn(e,t)}function cn(e,t){return(cn=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function un(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var fn=function(e){return{root:{display:"flex",height:"100vh"},appBar:{zIndex:e.zIndex.drawer+1,transition:e.transitions.create(["width","margin"],{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen})},title:{flexGrow:1,display:"inline-block"},appBarSpacer:e.mixins.toolbar,content:{flexGrow:1,padding:3*e.spacing.unit,overflow:"auto"},indicator:{backgroundColor:e.palette.primary.contrastText}}},dn=function(e){function t(){var e,n,a,r,o;nn(this,t);for(var s=arguments.length,i=new Array(s),l=0;l<s;l++)i[l]=arguments[l];return n=on(this,(e=sn(t)).call.apply(e,[this].concat(i))),a=un(un(n)),o=function(e,t){n.props.history.push(t)},(r="handleChangeTab")in a?Object.defineProperty(a,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):a[r]=o,n}return ln(t,r.a.Component),rn(t,[{key:"render",value:function(){var e=this.props.classes;return r.a.createElement("div",{className:e.root},r.a.createElement(p.a,{position:"absolute",className:e.appBar},r.a.createElement(m.a,{className:e.toolbar},r.a.createElement(y.a,{component:"h1",variant:"h6",color:"inherit",noWrap:!0,className:e.title},r.a.createElement(C,{style:{width:"2em",verticalAlign:"bottom",marginRight:"0.2em"}}),"Chromicle"),r.a.createElement(b.a,{styles:{display:"inline-block "},classes:{indicator:e.indicator},value:this.props.history.location.pathname,onChange:this.handleChangeTab},r.a.createElement(E.a,{label:"Settings",component:w.a,to:"/settings",value:"/settings"}),r.a.createElement(E.a,{label:"Analyze",component:w.a,to:"/analyze",value:"/analyze"})))),r.a.createElement(f.a,null),r.a.createElement("main",{className:e.content},r.a.createElement("div",{className:e.appBarSpacer}),r.a.createElement(k.a,{exact:!0,path:"/settings",component:en}),r.a.createElement(k.a,{exact:!0,path:"/analyze",component:Mt}),r.a.createElement(k.a,{exact:!0,path:"/",render:function(){return r.a.createElement(O.a,{to:"/settings"})}})))}}]),t}();dn.propTypes={classes:l.a.object.isRequired};var pn=function(e){function t(){return nn(this,t),on(this,sn(t).apply(this,arguments))}return ln(t,r.a.Component),rn(t,[{key:"render",value:function(){this.props.classes;var e=Object(S.a)(Object(c.withStyles)(fn)(dn));return r.a.createElement(c.MuiThemeProvider,{theme:D},r.a.createElement(P.a,null,r.a.createElement(e,null)))}}]),t}(),hn=n(467);s.a.render(r.a.createElement(pn,null),document.getElementById("root")),hn.a()}});