
class ScormPlayer{constructor({controllTracker,exerciciosScorm,componentScorm}){this.projeto="complaince";this.project=JSON.parse(localStorage.getItem("project"));this.loader=`<div class="loader"><img class="w-25 pull-center" src="./src/img/loading.gif" alt=""></div>`;this.body=document.querySelector("body");this.menuPartes=null;this.loaderClass=null;this.controllTracker=controllTracker;this.exerciciosScorm=exerciciosScorm;this.componentScorm=componentScorm;this.dadosSession={};this.retornoDados=null;this.articlesClasses=null;this.articlesDivs=null;this.conteudo=null;this.returnCheckProject=null;this.arrAulas=[];this.valueArticle=[];this.aulas=null;this.limit=null;this.renderScrollAction=true;}
initializeScorm(){if(this.project){this.returnCheckProject=this.project.find(elem=>elem.projeto===this.projeto);this.retornoDados=this.returnCheckProject===undefined?this.addLocalStorage():this.returnCheckProject;this.dadosSession.action=this.retornoDados.action;this.dadosSession.actionModulo=this.retornoDados.actionModulo;}else{this.retornoDados=this.setLocalStorage();this.dadosSession.action=this.retornoDados.action;this.dadosSession.actionModulo=this.retornoDados.actionModulo;}
this.valueArticle=this.retornoDados.controllArticle;this.renderConteudo(this.dadosSession.action,this.dadosSession.actionModulo).then(res=>{});this.controllTracker.renderControllerTracker({config:config,checkProject:this.returnCheckProject}).then(res=>{config=res;});}
async renderConteudo(url,idModulo){config.id_modulo=idModulo;this.body.innerHTML="";$("body").prepend(this.loader);var self=this;setTimeout(function(){$.ajax({url:`./${url}.html`,error:function(xhr,ajaxOptions,thrownError){alert(1111);renderConteudo("home",0);},success:function(data){$("body").append(data);switch(url){case"home":self.renderHome();break;case"modulos":self.renderHome();break;case"modulo":self.renderModulo(idModulo);break;}
self.controllerLocalStorage({projeto:self.projeto,action:url,controllArticle:self.valueArticle,status:self.returnCheckProject.status,sectionCheck:self.returnCheckProject.sectionCheck,actionModulo:idModulo});}});},1500);}
renderHome(){this.loaderClass=document.querySelector(".loader");this.componentScorm.modulosCursos().then(res=>{this.loaderClass.remove();});}
async renderModulo(id){config.id_modulo=id;var self=this;this.conteudo=document.querySelector(".conteudo");this.loaderClass=document.querySelector(".loader");config.selected_modulo=config.modulos[config.id_modulo];$(".scripts").remove();$("html").append(`<script class="scripts" src="./src/js/scripts/controller/modulo${config.id_modulo}.js"></script>`);this.componentScorm.renderListaMenuHamburgue(this.returnCheckProject);this.renderPartesAulas().then(res=>{self.limit=config.selected_modulo.limit;if(self.loaderClass){self.loaderClass.remove();}
self.conteudo.innerHTML=res;self.renderManagerAulas();self.rendeResizeScroll();});}
async renderPartesAulas(){const id=this.returnCheckProject.controllArticle[config.id_modulo].article;return $.ajax({url:`modulos/modulo${config.id_modulo}/parte_${id}.html`,error:function(xhr,ajaxOptions,thrownError){},success:function(data){}});}
renderManagerAulas(){this.articlesClasses=document.querySelectorAll(".article");this.articlesDivs=document.querySelectorAll("article");this.tituloPagina=document.querySelectorAll(".titulo-pagina");const titulo_modulo=document.querySelector(`.titulo-modulo-aula`);const sectionCheck=this.returnCheckProject.sectionCheck[config.id_modulo];const id=this.returnCheckProject.controllArticle[config.id_modulo].article;var ListPagina=config.modulos[config.id_modulo].aulas[id-1];var count=1;this.articlesDivs.forEach((elem,i)=>{elem.classList.add(`section_`);elem.classList.add(`section_${count}`);elem.setAttribute("id",count);if(ListPagina.paginas[i]!=undefined){$(`.section_${count}`).prepend(`<div class="row container-titulo">
          <div class="col-md-10">
              <div class="titulo-pagina float-left">${ListPagina.paginas[i].titulo}</div>
          </div>
          <div class="col-md-2 text-right">
              <small>${count}/${this.articlesDivs.length}</small>
          </div>
      </div>`);}
count++;});if(titulo_modulo){titulo_modulo.innerHTML=config.selected_modulo.titulo;}
this.componentScorm.renderNavArticle({aulaSub:ListPagina.sub_titulo,article:".article",atividade:sectionCheck[id-1].atividade,aula:ListPagina.titulo});this.componentScorm.renderListItemModulo(id);document.querySelectorAll(`#menu_${config.id_modulo} .menu-item__sub a`).forEach((elem,i)=>{if(i+1==id){elem.classList.add("active");}});}
renderSectionModulo(objeto){config.id_modulo=objeto.idModulo;if(objeto.update==true){this.returnCheckProject.status[objeto.idModulo]=true;this.setTrackerUpdate(this.returnCheckProject);}
this.returnCheckProject.controllArticle[config.id_modulo].article=objeto.id;this.renderConteudo("modulo",objeto.idModulo);}
renderControllerNextSection(val){var statusSection=this.returnCheckProject.status;if(val.update==true){const sectionCheck=this.returnCheckProject.sectionCheck[config.id_modulo];const article=this.valueArticle[config.id_modulo].article-1;sectionCheck[article].sessao=true;sectionCheck[article==0?article:article-1].atividade=1;document.querySelector(".article").remove();$("body").prepend(this.loader);var self=this;this.renderPartesAulas().then(res=>{document.querySelector(".loader").remove();self.conteudo.innerHTML=res;self.renderManagerAulas();});const countArticle=this.returnCheckProject.controllArticle[config.id_modulo].article;const countSection=this.returnCheckProject.sectionCheck[config.id_modulo].length;if(countArticle===countSection){statusSection[config.id_modulo+1]=true;}}
if(val.id){const controllArticle=this.returnCheckProject.controllArticle;const returnArticle=controllArticle[config.id_modulo];if(val.id>returnArticle.article||val.id===returnArticle.article){returnArticle.article=val.id;}
this.valueArticle=controllArticle;}
const dados={projeto:this.projeto,action:"modulo",actionModulo:config.id_modulo,controllArticle:this.valueArticle,status:statusSection,sectionCheck:this.returnCheckProject.sectionCheck};if(val.update==true){this.setTrackerUpdate(dados);}
this.controllerLocalStorage(dados);this.componentScorm.renderListaMenuHamburgue(this.returnCheckProject);}
setTrackerUpdate(dados){var Rconfig;this.controllTracker.updateTracker({config:config,checkProject:dados}).then(res=>{Rconfig=res;});Rconfig=config;}
toogleMenu(){const menu=document.querySelector(".menu-hamburg");menu.classList.toggle("active");}
renderSectionCheck(id){const sectionCheck=this.returnCheckProject.sectionCheck[config.id_modulo][this.valueArticle[config.id_modulo].article-1];sectionCheck.section=parseInt(id);const dados={projeto:this.projeto,action:"modulo",controllArticle:this.valueArticle,sectionCheck:this.returnCheckProject.sectionCheck};this.controllerLocalStorage(dados);}
renderControllStatus(){return config.modulos.map((modulos,i)=>{return i==0?true:false;});}
renderControllArticle(){return config.modulos.map((modulos,i)=>{return{article:1};});}
renderControllCheckSection(){config.modulos.map((modulos,i)=>{let aulas=modulos.aulas.map((aulas,j)=>{return{section:0,atividade:0,sessao:j==0?true:false};});this.arrAulas.push(aulas);});return this.arrAulas;}
setSectionCheck(){this.returnCheckProject.sectionCheck=this.renderControllCheckSection();}
addLocalStorage(){const dados={projeto:this.projeto,action:"home",actionModulo:0,completed:false,status:this.renderControllStatus(),controllArticle:this.renderControllArticle(),sectionCheck:this.renderControllCheckSection()};this.project.push(dados);this.returnCheckProject=dados;localStorage.setItem("project",JSON.stringify(this.project));return dados;}
setLocalStorage(){const dados={projeto:this.projeto,action:"home",actionModulo:0,completed:false,status:this.renderControllStatus(),controllArticle:this.renderControllArticle(),sectionCheck:this.renderControllCheckSection()};this.returnCheckProject=dados;localStorage.setItem("project",JSON.stringify([dados]));this.project=JSON.parse(localStorage.getItem("project"));return dados;}
controllerLocalStorage(objeto){var updateDados=this.project.find(elem=>elem.projeto===this.projeto);if(updateDados.controllArticle[config.id_modulo]!=undefined||objeto.controllArticle[config.id_modulo]!=undefined){var dadosArticle=updateDados.controllArticle[config.id_modulo].article;var objetoArticle=objeto.controllArticle[config.id_modulo].article;dadosArticle=objetoArticle==undefined?dadosArticle:objetoArticle;}
var dadosSectionCheck=updateDados.sectionCheck;var objetoSectionCheck=objeto.sectionCheck;updateDados.action=objeto.action;updateDados.status=objeto.status==undefined?updateDados.status:objeto.status;updateDados.actionModulo=objeto.actionModulo==undefined?updateDados.actionModulo:objeto.actionModulo;updateDados.sectionCheck=objetoSectionCheck==undefined?updateDados.sectionCheck:objetoSectionCheck;updateDados.completed=updateDados.completed?true:objeto.completed;localStorage.setItem("project",JSON.stringify(this.project));}
rendeResizeScroll(){$.fn.isInViewport=function(){var elementTop=$(this).offset().top;var elementBottom=elementTop+$(this).outerHeight();var viewportTop=$(window).scrollTop();var viewportBottom=viewportTop+$(window).height();return elementBottom>viewportTop&&elementTop<viewportBottom;};var self=this;$(".article").on("resize scroll",function(){const article=self.returnCheckProject.controllArticle[config.id_modulo].article;const postsLimit=document.querySelectorAll(".post").length;const moduloLimit=config.modulos.length-1;const moduloId=config.id_modulo;const articleLimit=self.returnCheckProject.sectionCheck[config.id_modulo].length;$(`.article .section_`).each(function(event){var id=$(this).attr("id");if($(this).isInViewport()){if(moduloId===moduloLimit&&article===articleLimit){if(id==postsLimit){console.log("Final do Curso");self.returnCheckProject.sectionCheck[config.id_modulo][article-1].sessao=true;self.controllTracker.finalizarCurso(self.returnCheckProject);}}
self.renderSectionCheck(id);self.section({section:`section_${id}`,parte:article,id:id});}});});}
section(params){$(`#${params.id}`).removeClass("section_");sectionAction(params);this.renderRemoveClass(params);}
renderRemoveClass(params){setInterval(()=>{$(`.${params.section} ${params.class != undefined ? params.class : ".hide"}`).removeClass();},500);}
exerciocioTable(){this.exerciciosScorm.exerciocioTable({dadosScorm:this.returnCheckProject});}
renderExercicio(params){this.exerciciosScorm.renderQuestao({dados:params,dadosScorm:this.returnCheckProject});}}
var _this=this;