import*as t from"@wordpress/interactivity";var e={d:(t,o)=>{for(var s in o)e.o(o,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:o[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const o=(t=>{var o={};return e.d(o,t),o})({getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store});const{state:s,actions:n}=(0,o.store)("web-stories-block",{state:{lightboxElement:null,player:null,stories:[],instanceId:null,currentLocation:null},actions:{storyContentReady:(t,e,o=5)=>{const s=setInterval((()=>{!0===t.storyContentLoaded&&(window.clearInterval(s),e()),--o||window.clearInterval(s)}),250)},close:()=>{history.pushState({},"",s.currentLocation);const{player:t,lightboxElement:e}=s;t&&(t.rewind(),t.pause(),t.mute(),e?.classList.toggle("show"),document.body.classList.toggle("web-stories-lightbox-open"))},open:t=>{t.preventDefault();const e=(0,o.getContext)(),r=document.querySelector(`.ws-lightbox-${e.instanceId} .web-stories-list__lightbox`)||document.querySelector(`.ws-lightbox-singleton-${e.instanceId} .web-stories-singleton__lightbox`);if(!r)return;const i=r.querySelector("amp-story-player"),l=i.getStories();s.lightboxElement=r,s.player=i,s.stories=l,s.instanceId=e.instanceId,s.currentLocation=location.href;const{ref:a}=(0,o.getElement)(),c=l.find((t=>t.href===a?.querySelector("a")?.href));var h;c&&(i.show(c.href),i.play(),n.storyContentReady(c,(()=>{history.pushState({},"",c.href)}))),h=()=>{r.classList.toggle("show"),document.body.classList.toggle("web-stories-lightbox-open")},document.startViewTransition?document.startViewTransition((()=>h())):h()},navigation:t=>{const e=s.stories[t.detail.index];e&&e.href!==document.location.href&&n.storyContentReady(e,(()=>{history.pushState({},"",e.href)}))},onPopstate:()=>{const t=s.lightboxElement,e=s.player,o=t?.classList.contains("show"),r=s.stories.find((t=>t.href===document.location.href));r?(o||(t?.classList.toggle("show"),document.body.classList.toggle("web-stories-lightbox-open"),e?.play()),e?.show(r.href)):o&&n.close()}}});