import{getContext as e,getElement as i,store as s,useEffect as a}from"@wordpress/interactivity";s("twentig/video-play-pause",{state:{get ariaLabel(){const{isVideoPlaying:i,isVideoEnded:s,ariaLabelPause:a,ariaLabelPlay:t,ariaLabelReplay:o}=e();return s?o:i?a:t}},actions:{playVideo(){const{ref:e}=i(),s=e.closest(".wp-block-video").querySelector("video");s&&s.play().catch((()=>{}))},playPauseVideo:()=>{const{ref:e}=i(),s=e.closest(".wp-block-video").querySelector("video");s&&(s.paused||s.ended?s.play().catch((()=>{})):s.pause())},handleVideoEvent:i=>{const s=e();switch(i.type){case"playing":s.isVideoPlaying=!0,s.isVideoPaused=!1,s.isVideoEnded=!1,s.isVideoStarted=!0;break;case"ended":s.isVideoPaused=!1,s.isVideoPlaying=!1,s.isVideoEnded=!0;break;case"pause":s.isVideoPlaying=!1,s.isVideoEnded||(s.isVideoPaused=!0)}}},callbacks:{checkVisibility:()=>{a((()=>{const{ref:e}=i();if(e&&"IntersectionObserver"in window){const i=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&(e.target.play().catch((()=>{})),i.unobserve(e.target))}))}),{threshold:.75});return i.observe(e),()=>i.disconnect()}return()=>{}}),[])}}});