var t=globalThis.H5P=globalThis.H5P||{};t.XAPIEvent=function(){t.Event.call(this,"xAPI",{statement:{}},{bubbles:!0,external:!0})},t.XAPIEvent.prototype=Object.create(t.Event.prototype),t.XAPIEvent.prototype.constructor=t.XAPIEvent,t.XAPIEvent.prototype.setScoredResult=function(t,e,n,a,o){if(this.data.statement.result={},void 0!==t&&(void 0===e?this.data.statement.result.score={raw:t}:(this.data.statement.result.score={min:0,max:e,raw:t},e>0&&(this.data.statement.result.score.scaled=Math.round(t/e*1e4)/1e4))),this.data.statement.result.completion=void 0===a?"completed"===this.getVerb()||"answered"===this.getVerb():a,void 0!==o&&(this.data.statement.result.success=o),n&&n.activityStartTime){var i=Math.round((Date.now()-n.activityStartTime)/10)/100;this.data.statement.result.duration="PT"+i+"S"}},t.XAPIEvent.prototype.setVerb=function(e){-1!==t.jQuery.inArray(e,t.XAPIEvent.allowedXAPIVerbs)?this.data.statement.verb={id:"http://adlnet.gov/expapi/verbs/"+e,display:{"en-US":e}}:void 0!==e.id&&(this.data.statement.verb=e)},t.XAPIEvent.prototype.getVerb=function(t){var e=this.data.statement;return"verb"in e?!0===t?e.verb:e.verb.id.slice(31):null},t.XAPIEvent.prototype.setObject=function(e){if(e.contentId)if(this.data.statement.object={id:this.getContentXAPIId(e),objectType:"Activity",definition:{extensions:{"http://h5p.org/x-api/h5p-local-content-id":e.contentId}}},e.subContentId)this.data.statement.object.definition.extensions["http://h5p.org/x-api/h5p-subContentId"]=e.subContentId,"function"==typeof e.getTitle&&(this.data.statement.object.definition.name={"en-US":e.getTitle()});else{var n=t.getContentForInstance(e.contentId);n&&n.metadata&&n.metadata.title&&(this.data.statement.object.definition.name={"en-US":t.createTitle(n.metadata.title)})}},t.XAPIEvent.prototype.setContext=function(t){t.parent&&(t.parent.contentId||t.parent.subContentId)&&(this.data.statement.context={contextActivities:{parent:[{id:this.getContentXAPIId(t.parent),objectType:"Activity"}]}}),t.libraryInfo&&(void 0===this.data.statement.context&&(this.data.statement.context={contextActivities:{}}),this.data.statement.context.contextActivities.category=[{id:"http://h5p.org/libraries/"+t.libraryInfo.versionedNameNoSpaces,objectType:"Activity"}])},t.XAPIEvent.prototype.setActor=function(){if(void 0!==H5PIntegration.user)this.data.statement.actor={name:H5PIntegration.user.name,mbox:"mailto:"+H5PIntegration.user.mail,objectType:"Agent"};else{var e;try{localStorage.H5PUserUUID?e=localStorage.H5PUserUUID:(e=t.createUUID(),localStorage.H5PUserUUID=e)}catch(n){e="not-trackable-"+t.createUUID()}this.data.statement.actor={account:{name:e,homePage:H5PIntegration.siteUrl},objectType:"Agent"}}},t.XAPIEvent.prototype.getMaxScore=function(){return this.getVerifiedStatementValue(["result","score","max"])},t.XAPIEvent.prototype.getScore=function(){return this.getVerifiedStatementValue(["result","score","raw"])},t.XAPIEvent.prototype.getContentXAPIId=function(t){var e;return t.contentId&&H5PIntegration&&H5PIntegration.contents&&H5PIntegration.contents["cid-"+t.contentId]&&(e=H5PIntegration.contents["cid-"+t.contentId].url,t.subContentId&&(e+="?subContentId="+t.subContentId)),e},t.XAPIEvent.prototype.isFromChild=function(){var t=this.getVerifiedStatementValue(["context","contextActivities","parent",0,"id"]);return!t||-1===t.indexOf("subContentId")},t.XAPIEvent.prototype.getVerifiedStatementValue=function(t){for(var e=this.data.statement,n=0;n<t.length;n++){if(void 0===e[t[n]])return null;e=e[t[n]]}return e},t.XAPIEvent.allowedXAPIVerbs=["answered","asked","attempted","attended","commented","completed","exited","experienced","failed","imported","initialized","interacted","launched","mastered","passed","preferred","progressed","registered","responded","resumed","scored","shared","suspended","terminated","voided","downloaded","accessed-embed","accessed-copyright"];