/*! builder: oce-mpa-builder - version: 2.1.0  framework: ewizardjs - version: 5.9.0 */
(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{241:function(P,a,h){"use strict";h.r(a);class d{constructor(t,e,s){this.navigator=t,this.settings=e,this.storage=s,this.standardKPIKey="slides",this.KPI={},this.timestamp=Date.now(),this.pause=!1,this.initKPI(),this.navigator.onenter(this.start.bind(this),{global:!0}),this.navigator.onbeforeleave(i=>{this.pause||this.stop(i)},{global:!0})}suspend(){if(!this.pause){const{slide:t,subslide:e}=this.navigator.getNavigation();this.stop({slide:t,subslide:e}),this.pause=!0}}proceed(){this.pause&&this.start()}initKPI(){this.KPI[this.standardKPIKey]=this.getStorageKPI(),this.writeKPI()}start(){this.resetTime(),this.pause=!1}stop({slide:t,subslide:e}){this.KPI[this.standardKPIKey]=this.getStorageKPI();const s=this.getTime();this.resetTime(),!(s<this.settings.kpi.startTime)&&(e?this.updateSubslideKPI(t,e,s):this.updateKPI(this.KPI[this.standardKPIKey],"id",this.updateKPISlide,{time:s,id:t}),this.writeKPI())}updateSubslideKPI(t,e,s){const i=this.KPI[this.standardKPIKey];let n=i.find(r=>r.id===t);(!i.length||!n)&&(i.push({id:t}),n=i[i.length-1]),n.subslide=!0,n.subslides=n.subslides||[],this.updateKPI(n.subslides,"id",this.updateKPISlide,{time:s,id:e})}updateKPI(t,e,s,i){const n=t.findIndex(r=>r[e]===i[e]);n!==-1?s(t[n],i):t.push(i)}getStorageKPI(){const t=this.readKPI();return t&&t[this.standardKPIKey]||[]}updateKPISlide(t,e){t.time+=e.time}readKPI(){return JSON.parse(this.storage.get())}writeKPI(){this.storage.set(this.KPI)}getTime(){return Math.round((Date.now()-this.timestamp)/1e3)}resetTime(){this.timestamp=Date.now()}}function u(o){return typeof o=="object"&&o.constructor===Object}function c(o,t,e){const s=new XMLHttpRequest;return s.onload=t,s.open("GET",o,!!e),s.send(),s}class K{constructor(t,e){this.navigator=t,this.storage=e,this.customKPIKey="customKPI",this.KPI={},this.onLeaveStorage=[],this.initKPI(),t.onleave(()=>{this.onLeaveStorage.forEach(s=>{const{value:i,options:n}=s.getData();this.submit(s.key,i,n)})},{global:!0})}async submit(t,e,s){this.updateKPI(t,e,s),this.writeKPI()}async submitOnLeave(t,e){this.onLeaveStorage.push({key:t,getData:e})}setKPI(t){if(u(t)){const{key:e,value:s,options:i}=t;this.submit(e,s,i)}else if(Array.isArray(t))t.forEach(({key:e,value:s,options:i})=>this.submit(e,s,i));else throw new Error("Monitoring data should be an object or array of objects")}initKPI(){this.KPI[this.customKPIKey]=this.getStorageKPI(),this.writeKPI()}updateKPI(t,e,s){this.validate(t,e),this.KPI[this.customKPIKey]=this.getStorageKPI();const i=this.KPI[this.customKPIKey].findIndex(n=>n.key===t);i!==-1?this.KPI[this.customKPIKey][i]={key:t,value:e,options:s}:this.KPI[this.customKPIKey].push({key:t,value:e,options:s})}readKPI(){return JSON.parse(this.storage.get())}writeKPI(){this.storage.set(this.KPI)}getStorageKPI(){const t=this.readKPI();return t&&t[this.customKPIKey]||[]}validate(t,e){if(!t||typeof t!="string")throw new Error("Monitoring key should be a non-empty string");if(typeof e=="undefined")throw new Error("Monitoring value is undefined")}}function I(o,t,e){return{getKPI:e.get.bind(e),clearStorage:e.clear.bind(e),proceed:o.proceed.bind(o),suspend:o.suspend.bind(o),setCustomKPI:t.setKPI.bind(t),executeMethod(s){if(["getKPI","clearStorage","setCustomKPI"].includes(s))return console.warn(`${s} method is deprecated use ewizardjs.monitoring.${s} instead`),this[s].call(this)},invokeEvent(s){["suspend","proceed","setCustomKPI"].includes(s)&&(console.warn(`${s} event is deprecated use ewizardjs.monitoring.${s} instead`),this[s].call(this))}}}var l=a.default=(o,t,e)=>{const s=new d(o,t,e),i=new K(o,e),n=I(s,i,e);return window.executeMethod=n.executeMethod.bind(n),window.invokeEvent=n.invokeEvent.bind(n),{customMonitoringAPI:i,externalMonitoringAPI:n}}}}]);
