
class ControllTracker{constructor(){this.scormApi=pipwerks.SCORM.API;this.scorm=pipwerks.SCORM;this.api=pipwerks.SCORM.API.getHandle();this.lmsConnected=null;this.statusCurso=null;}
async renderControllerTracker(objeto){this.statusCurso=objeto.checkProject.completed;if(this.scormApi.isFound){objeto.config.LMSGetValue=true;this.initCourse();this.scorm.connection.isActive=true;}else{objeto.config.LMSGetValue=false;}
const arrModulos=this.generateTracker(objeto);if(objeto.config.LMSGetValue===false||objeto.config.LMSGetValue===undefined){objeto.config.controlTrackModulo=arrModulos;}
if(this.scorm.get("cmi.suspend_data")===""&&objeto.config.LMSGetValue===true){objeto.config.controlTrackModulo=arrModulos;}
if(objeto.config.LMSGetValue===true){objeto.config.controlTrackModulo=this.scorm.get("cmi.suspend_data")?JSON.parse(this.scorm.get("cmi.suspend_data")):objeto.config.controlTrackModulo;objeto.config.controllerStatusTracker=false;}
return config;}
generateTracker(objeto){let arrModulos=[];objeto.config.modulos.map((modulo,index_modulo)=>{const trackModulo=objeto.checkProject.controllArticle[index_modulo];const sectionCheck=objeto.checkProject.sectionCheck[index_modulo];const status=objeto.checkProject.status[index_modulo];arrModulos.push({trackModulo:trackModulo.article,sectionCheck:sectionCheck,status:status});});return arrModulos;}
initCourse(){this.lmsConnected=this.api.LMSInitialize("");this.scorm.init();if(this.lmsConnected){console.log("lmsConnected",this.lmsConnected);console.log("Curso Conectado");console.log("Versão do scorm",this.scorm.version);var completionstatus=this.scorm.get("cmi.core.lesson_status");if(completionstatus=="completed"||completionstatus=="passed"){this.handleError("You have already completed this course. You do not need to continue.");config.producao=this.statusCurso?true:false;}}else{this.handleError("Error: Course could not connect with the LMS");}}
finalizarCurso(objeto){console.log("Concluido");if(config.LMSGetValue===true){this.api.LMSSetValue("cmi.core.lesson_status","completed");this.api.LMSCommit("");window.controllerLocalStorage({action:"home",actionModulo:0,completed:true,controllArticle:objeto.controllArticle,status:objeto.status,sectionCheck:objeto.sectionCheck});}}
sairCurso(){var completionstatus=this.scorm.get("cmi.core.lesson_status");if(completionstatus=="completed"||completionstatus=="passed"){console.log("Curso concluido");this.api.LMSFinish();}else{console.log("Curso não concluido");}}
handleError(msg){console.log(msg);}
async updateTracker(dados){var arrModulos=this.generateTracker(dados);dados.config.controlTrackModulo=arrModulos;if(this.scormApi.isFound==false){return;}else{this.api.LMSSetValue("cmi.suspend_data",JSON.stringify(arrModulos));this.api.LMSCommit("");return dados.config;}}}