const namespace="presto-player.progress";let nonce,visit_time=Date.now();export default o=>{var e,i;if(!o.automations)return;(null===(i=null===(e=null===window||void 0===window?void 0:window.wp)||void 0===e?void 0:e.hooks)||void 0===i?void 0:i.hasAction("presto.nonceRefreshed",namespace))||window.wp.hooks.addAction("presto.nonceRefreshed",namespace,o=>{nonce=o}),null===window||void 0===window||window.wp.hooks.addAction("presto.playerTimeUpdate","presto-player",d),null===window||void 0===window||window.wp.hooks.addAction("presto.playerEnded","presto-player",o=>d(o,100));let n={0:!1,10:!1,20:!1,30:!1,40:!1,50:!1,60:!1,70:!1,80:!1,90:!1,100:!1};function d(o,e=null){var i;nonce&&(null===(i=null==o?void 0:o.config)||void 0===i?void 0:i.ajaxProgress)&&(e||(e=parseFloat(o.currentTime)/parseFloat(o.duration)*100),o.watched=o.watched||{},Object.keys(n).forEach(i=>{var n,d,l,t,a,r,w,s,p;const v=parseInt(i);if(!o.watched[v]&&e>=v){o.watched[v]=!0;let e=new FormData;if(e.append("action","presto_player_progress_percent"),e.append("id",null===(n=null==o?void 0:o.config)||void 0===n?void 0:n.id),e.append("percent",v.toString()),e.append("visit_time",visit_time.toString()),e.append("nonce",nonce),(null===(d=null===window||void 0===window?void 0:window.prestoPlayer)||void 0===d?void 0:d.debug)&&console.log(`${v} percent watched.`),null===(l=null===window||void 0===window?void 0:window.prestoPlayer)||void 0===l?void 0:l.debug_navigator)window.jQuery.ajax({type:"POST",url:null===(s=null===window||void 0===window?void 0:window.prestoPlayer)||void 0===s?void 0:s.ajaxurl,dataType:"json",cache:!1,data:{action:"presto_player_progress_percent",id:null===(p=null==o?void 0:o.config)||void 0===p?void 0:p.id,visit_time,percent:v,nonce}});else{let i=navigator.sendBeacon(null===(t=null===window||void 0===window?void 0:window.prestoPlayer)||void 0===t?void 0:t.ajaxurl,e);(null===(a=null===window||void 0===window?void 0:window.prestoPlayer)||void 0===a?void 0:a.debug)&&(i?console.log("Successfully queued progress:",{id:null===(r=null==o?void 0:o.config)||void 0===r?void 0:r.id,percent:v,visit_time,nonce}):console.log("Failed to queue progress",{id:null===(w=null==o?void 0:o.config)||void 0===w?void 0:w.id,percent:v,visit_time,nonce}))}}}))}};