let player;const namespace="presto-player.analytics";let nonce="",currentTime=0;export default function(e){player=e,player.config.analytics&&window?.wp?.hooks&&(wp.hooks.hasAction("presto.nonceRefreshed",namespace)||wp.hooks.addAction("presto.nonceRefreshed",namespace,e=>{nonce=e}),wp.hooks.hasAction("presto.playerPlay",namespace)||wp.hooks.addAction("presto.playerPlay",namespace,sendVideoData),wp.hooks.hasAction("presto.playerEnded",namespace)||wp.hooks.addAction("presto.playerEnded",namespace,sendVideoData),wp.hooks.hasAction("presto.playerHidden",namespace)||wp.hooks.addAction("presto.playerHidden",namespace,sendVideoData),wp.hooks.hasAction("presto.playerPause",namespace)||wp.hooks.addAction("presto.playerPause",namespace,sendVideoData),wp.hooks.hasAction("presto.playerSeeked",namespace)||wp.hooks.addAction("presto.playerSeeked",namespace,sendVideoData))}export function videoData(e){return e.currentTime>currentTime&&(currentTime=e.currentTime),e.currentTime>=e.duration&&(currentTime=e.duration),{video_current_time:parseInt(currentTime),video_provider:e?.provider||"html5",...e?.duration?{video_duration:parseInt(e?.duration)}:{},...e?.source?{video_url:e?.source}:{},...e?.config?.title?{video_title:e?.config?.title}:{}}}export function sendVideoData(e){isNaN(e?.currentTime)||sendData(videoData(e))}export function sendData(e){if(!nonce)return;let a=new FormData;a.append("action","presto_player_progress"),a.append("duration",e?.video_current_time),a.append("video_id",player?.config?.id),a.append("nonce",nonce),window?.prestoPlayer?.debug_navigator?"undefined"!=typeof jQuery&&jQuery.ajax({type:"POST",url:window?.prestoPlayer?.ajaxurl,dataType:"json",cache:!1,data:{action:"presto_player_progress",duration:e?.video_current_time,video_id:player?.config?.id,nonce}}):navigator.sendBeacon(window?.prestoPlayer?.ajaxurl,a)}