"use strict";const prevent_default=e=>{e.preventDefault()};function toggle_mark_complete(e){var t=jQuery(".llms-complete-lesson-form"),o=jQuery('.llms-complete-lesson-form button[type="submit"]'),n=jQuery("#llms_start_quiz, #llms-start-assignment");!0===e?(t.off("submit",prevent_default),o.removeAttr("disabled"),n.removeClass("llms-av-disabled").off("click",prevent_default)):(t.on("submit",prevent_default),o.attr("disabled","disabled"),n.addClass("llms-av-disabled").on("click",prevent_default))}const getEventMeta=e=>({ts:e.currentTime,duration:e.duration,url:e.source,provider:e.provider,id:e.config.id}),track_event=(e,t)=>{llms.tracking.addEvent("video."+e,{meta:t})};function start_countdown(e){var t,o=e.find(".llms-av-pv--seconds");setInterval((function(){1==(t=1*o.text()-1)&&o.closest("a")[0].click(),t>=0&&o.text(t)}),1e3)}function do_ajax_completion(e,t){LLMS.Ajax.call({data:{action:"llms_av_video_ended",id:t.post_id,nonce:t.nonce},beforeSend:function(){LLMS.Spinner.start(e)},error:function(t,o,n){LLMS.Spinner.stop(e),console.error(t.responseText+" ("+n+" "+o+")"),console.log(t)},success:function(t){LLMS.Spinner.stop(e),t?.html&&(e.append(t.html),start_countdown(e))}})}const onPauseVideo=e=>{const t=e.detail.plyr;let o=getEventMeta(t);track_event("paused",o)},onPlayingVideo=e=>{const t=e.detail.plyr;let o=getEventMeta(t),n=o.ts<1?"started":"played";track_event(n,o)},onEndedVideo=(e,t,o)=>{const n=e.detail.plyr;let l=getEventMeta(n);track_event("ended",l),do_ajax_completion(t,o),toggle_mark_complete(!0)};function lifter(e){var t={},o=llms?.tracking?.getSettings()||null;o?.av&&(t=o.av),t.require_video_completion&&!t.video_completed&&toggle_mark_complete(!1);let n=jQuery(".presto-block-video");e.on("pause",onPauseVideo),e.on("playing",onPlayingVideo),e.on("ended",(e=>onEndedVideo(e,n,t)))}exports.default=lifter,exports.onEndedVideo=onEndedVideo,exports.onPauseVideo=onPauseVideo,exports.onPlayingVideo=onPlayingVideo;