(()=>{var t=document.querySelector("#complete_lesson_enabled")?document.querySelector("#complete_lesson_enabled").value:0;var e=document.querySelector('button[name="complete_lesson_btn"]');var n=[];document.querySelectorAll("[data-content-id]").forEach(function(t){n.push(t.dataset.contentId)});var o=document.querySelector(".tutor-spotlight-h5p-lesson-content");window.jQuery(document).ready(function(o){var a=wp.i18n.__;if(t){o(e).attr("disabled",true);o(e).wrap('<div class="tooltip-wrap"></div>').after('<span class="tooltip-txt tooltip-bottom">'.concat(a("Finish the content to complete the lesson ","tutor-pro"),"</span>"))}if(H5P||H5P.externalDispatcher){var r=o(".tutor-spotlight-h5p-lesson-content");var i=parseInt(r.data("course-id"),10);var s=parseInt(r.data("topic-id"),10);var c=parseInt(r.data("lesson-id"),10);var d="h5p-local-content-id";var l=function t(e){var n=e.data.statement.object.definition.extensions["http://h5p.org/x-api/"+d];o.ajax({url:_tutorobject.ajaxurl,type:"POST",data:{action:"save_h5p_lesson_xAPI_statement",course_id:i,content_id:n,topic_id:s,lesson_id:c,statement:JSON.stringify(e.data.statement)}})};H5P.externalDispatcher.on("xAPI",l);H5P.externalDispatcher.on("initialized",function(){if(H5P.instances.length>0){H5P.instances.forEach(function(t){H5P.on(t,"xAPI",function(t){var o=this;if((t.getVerb()==="completed"||t.getVerb()==="answered")&&!t.getVerifiedStatementValue(["context","contextActivities","parent"])){n=n.filter(function(t){return parseInt(t)!==parseInt(o.contentId)});if(n.length===0){e.attributes.removeNamedItem("disabled");e.parentNode.removeChild(e.nextSibling);jQuery.ajax({url:_tutorobject.ajaxurl,type:"POST",data:{action:"set_h5p_lesson_finished",_tutor_nonce:_tutorobject._tutor_nonce,lesson_id:c}})}}})})}})}});window.addEventListener("message",function(t){if(t.data&&t.data.action==="h5p_setFinished"){n=n.filter(function(e){return e!==t.data.contentId});var a=jQuery(o).data("lesson-id");if(n.length===0){e.attributes.removeNamedItem("disabled");e.parentNode.removeChild(e.nextSibling);jQuery.ajax({url:_tutorobject.ajaxurl,type:"POST",data:{action:"set_h5p_lesson_finished",_tutor_nonce:_tutorobject._tutor_nonce,lesson_id:a}})}}})})();