import{a as e,o as t,t as n}from"./i18n-CjHYiQIU.js";import{P as r}from"./index-D2kkGKae.js";var i=t(),a=e(),o=1400,s=5e3;function c({soundEnabled:e,soundVolume:t,reward:c,onComplete:l}){let{strings:u}=n(),d=(0,i.useRef)(null),f=(0,i.useRef)(null),p=(0,i.useRef)(null),m=(0,i.useRef)(l),h=(0,i.useRef)(!1),g=(0,i.useRef)(!1),_=(0,i.useRef)(!1),[v,y]=(0,i.useState)(!1);(0,i.useEffect)(()=>{m.current=l},[l]);let b=(0,i.useCallback)(()=>{if(!h.current){h.current=!0,p.current!==null&&(window.clearTimeout(p.current),p.current=null);try{d.current?.pause()}catch{}try{f.current?.stop()}catch{}f.current=null,m.current()}},[]),x=(0,i.useCallback)(e=>{p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(b,e)},[b]),S=(0,i.useCallback)(()=>{if(!(h.current||_.current)){_.current=!0,y(!0),x(o);try{d.current?.pause()}catch{}try{f.current?.stop()}catch{}if(f.current=null,!g.current)try{f.current=r(`chest-open`,e,t)}catch{f.current=null}}},[x,e,t]);return(0,i.useEffect)(()=>{let n=d.current;if(!n){S();return}n.preload=`auto`,n.defaultMuted=!0,n.muted=!0,n.playsInline=!0,n.autoplay=!0,x(s);let i=!0;try{n.currentTime=0;let a=n.play(),o=()=>{!i||h.current||_.current||(g.current=!0,f.current=r(`chest-open`,e,t))};a?a.then(o).catch(()=>{i&&S()}):o()}catch{S()}return()=>{i=!1,p.current!==null&&(window.clearTimeout(p.current),p.current=null),f.current?.stop(),f.current=null,n.pause()}},[S,x,e,t]),(0,a.jsxs)(`div`,{className:`chest-unlock-overlay${v?` is-fallback`:``}`,role:`button`,tabIndex:0,"aria-label":u.chestUnlock.skipAnimation,onClick:b,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&b()},children:[(0,a.jsxs)(`video`,{ref:d,autoPlay:!0,muted:!0,playsInline:!0,preload:`none`,onEnded:b,onError:S,onVolumeChange:e=>{e.currentTarget.muted=!0},children:[(0,a.jsx)(`source`,{src:`./assets/cinematics/thornlock-chest-open.webm`,type:`video/webm`}),(0,a.jsx)(`source`,{src:`./assets/cinematics/thornlock-chest-open.mp4`,type:`video/mp4`})]}),v&&(0,a.jsx)(`img`,{className:`chest-unlock-fallback`,src:`./assets/cinematics/chest-open-fallback.webp`,alt:``,"aria-hidden":`true`}),c!==void 0&&(0,a.jsx)(`p`,{className:`chest-unlock-reward`,role:`status`,children:c}),(0,a.jsx)(`span`,{children:u.chestUnlock.continue})]})}export{c as ChestUnlockOverlay};