const hookNamespace="presto-player.daily-views",trackedVideos=new Set;let beaconRegistered=!1,beaconSent=!1;function sendViewCount(){if(beaconSent||0===trackedVideos.size)return;if("function"!=typeof navigator.sendBeacon)return;const e=window?.prestoPlayer?.ajaxurl;if(!e)return;const n=new FormData;n.append("action","presto_player_daily_views"),n.append("count",String(trackedVideos.size)),navigator.sendBeacon(e,n)&&(trackedVideos.clear(),beaconSent=!0)}function registerBeacon(){beaconRegistered||(beaconRegistered=!0,document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState&&sendViewCount(),"visible"===document.visibilityState&&(beaconSent=!1)}),window.addEventListener("pagehide",sendViewCount))}function onPlay(e){const n=e?.config?.id;n&&!trackedVideos.has(n)&&trackedVideos.add(n)}export default function viewTracking(e){window?.prestoPlayer?.trackViews&&window?.wp?.hooks&&(registerBeacon(),wp.hooks.hasAction("presto.playerPlay",hookNamespace)||wp.hooks.addAction("presto.playerPlay",hookNamespace,onPlay))}