import{getContext as e,getElement as t,store as r}from"@wordpress/interactivity";const{__}=wp.i18n,{state:o,actions:n}=r("presto-player/popup",{state:{activePopupId:null,screenReaderText:"",triggerRef:null,inertElements:[],get overlayEnabled(){const t=e();return o?.activePopupId===t?.id},get roleAttribute(){return o?.overlayEnabled?"dialog":null},get ariaModal(){return o?.overlayEnabled?"true":null}},actions:{showPopup(){const r=e(),{ref:n}=t();o.activePopupId=r?.id,document.querySelectorAll("body > :not(.presto-popup__overlay)").forEach(e=>{e?.hasAttribute("inert")||(e?.setAttribute("inert",""),o?.inertElements?.push(e))}),o.triggerRef=n},hidePopup(){o.activePopupId=null,(o?.inertElements||[]).forEach(e=>{e?.removeAttribute("inert")}),o.inertElements=[],setTimeout(()=>{o?.triggerRef?.focus()},0),o.screenReaderText=""}},callbacks:{setOverlayFocus(){if(!o?.overlayEnabled)return;const{ref:e}=t();setTimeout(()=>{e?.focus()},0),o.screenReaderText=__("Presto Popup dialog opened.","presto-player")},handleKeydown(e){"Enter"!==e?.key||o?.overlayEnabled||n.showPopup(),"Escape"===e?.key&&o?.overlayEnabled&&n.hidePopup()},updatePopupList(){const t=e();t.popupList=o?.overlayEnabled?[t?.id]:[]}}});