/**
 * Copyright 2021
 * @license Apache-2.0, see License.md for full text.
 */
globalThis.PouchDb=globalThis.PouchDb||{},globalThis.PouchDb.requestAvailability=()=>(globalThis.PouchDb.instance||(globalThis.PouchDb.instance=globalThis.document.createElement("pouch-db"),globalThis.document.body.appendChild(globalThis.PouchDb.instance)),globalThis.PouchDb.instance);export const PouchDBElement=globalThis.PouchDb.requestAvailability();class PouchDb extends HTMLElement{constructor(){super(),this.windowControllers=new AbortController,this.type="xapi",import("./lib/pouchdb.min.js").then((()=>{this.db=new PouchDB(this.type)}))}static get tag(){return"pouch-db"}connectedCallback(){globalThis.addEventListener("user-engagement",this.userEngagmentFunction.bind(this),{signal:this.windowControllers.signal}),globalThis.addEventListener("pouch-db-get-data",this.getDataFunction.bind(this),{signal:this.windowControllers.signal})}disconnectedCallback(){this.windowControllers.abort()}userEngagmentFunction(e){var t=e.detail;if("MULTIPLE-CHOICE"===e.target.tagName)var o=t.activityDisplay,s="http://adlnet.gov/expapi/verbs/"+o,i="http://haxcms.psu.edu/haxQuiz",a=t.objectName,n="HAX Quiz",l=1,c=0,u=100,r=100,b=t.resultSuccess,d=!0,h="sample",g="sample";var p={actor:{mbox:"mailto:dave@gmail.com",name:"Dave Fusco",objectType:"Agent"},verb:{id:s,display:{"en-US":o}},object:{id:i,definition:{name:{"en-US":a},description:{"en-US":n}},objectType:"Activity"},result:{score:{scaled:l,min:c,max:u,raw:r},success:b,completion:d,response:h,duration:g}},m={_id:(new Date).toISOString(),title:JSON.stringify(p),completed:!1};console.log(m),this.db.put(m,(function callback(e,t){e||console.log("Successfully posted a statement!")})),this.db.allDocs({include_docs:!0,descending:!0},(function(e,t){console.log(t.rows)}))}getDataFunction(e){var t=e.detail;e.target.tagName;switch(t.queryRequest){case"all-quizzes":break;case"single-quiz":t.objectName;break;case"future-query":t.activityDisplay,t.objectName,t.resultSuccess,t.resultCompletion;break;default:}this.db.allDocs({include_docs:!0,descending:!0},(function(e,t){!function processxAPI(e,t){var o=[];e.forEach((function(e){var t=JSON.parse(e.doc.title).object.definition.name["en-US"];o.push(t)})),t(o)}(t.rows,(function displayxAPI(e){!function processItems(e,t){var o={};e.forEach((function(e){o[e]=(o[e]||0)+1})),t(o)}(e,(function display(e){var t=[],o=[];for(let o of Object.keys(e))t.push(o);for(let t of Object.values(e))o.push(t);let s=[""];s={labels:t,series:[o]},globalThis.dispatchEvent(new CustomEvent("pouch-db-show-data",{bubbles:!0,composed:!0,cancelable:!1,detail:s}))}))}))}))}}customElements.define(PouchDb.tag,PouchDb);export{PouchDb};