import{t as e}from"./defineProperty-BbfpZ9Tg.js";import{a as t}from"./jsx-runtime-DHSfUA5-.js";import{F as n,I as r,K as i,P as a,U as o}from"./test.id-DxQrYxPk.js";import{n as s}from"./fileAssetService-gA4Q8V3n.js";import{r as c,t as l}from"./WorkbenchOverlayService-D9CSrozm.js";var u=15e3;function d(e){return new Promise((t,n)=>{let r=new Image,i=!1,a,o=e=>{i||(i=!0,a&&clearTimeout(a),r.onload=null,r.onerror=null,e())};if(a=setTimeout(()=>{o(()=>n(Error(`Image load timed out.`)))},u),r.onload=()=>o(t),r.onerror=()=>o(()=>n(Error(`Failed to load image.`))),r.src=e,r.complete&&r.naturalWidth>0){o(t);return}r.decode?.().then(()=>o(t),()=>o(()=>n(Error(`Failed to decode image.`))))})}function f(e){return new Promise((t,n)=>{let r=setTimeout(()=>n(Error(`Image URL load timed out.`)),u);e.then(e=>{clearTimeout(r),t(e)},e=>{clearTimeout(r),n(e)})})}async function p(e,t,n){let r=await f(e.getFileUrl(t,n));if(r)try{return await d(r),r}catch{throw Error(`Failed to load image.`)}}var m,h=m=class{static create(e,n){return n.invokeFunction(e=>e.get(l)).createOverlay(`image-preview`,c.imagePreview,t.imagePreview,t=>n.createInstance(m,e,t))}constructor(t,n,r,i){e(this,`fileAssetService`,void 0),e(this,`workbenchOverlayService`,void 0),e(this,`_onStatusChange`,new o),e(this,`onStatusChange`,this._onStatusChange.event),e(this,`zIndex`,void 0),e(this,`instanceId`,void 0),e(this,`images`,void 0),e(this,`loads`,new Map),e(this,`disposed`,!1),e(this,`_visible`,!0),e(this,`_index`,void 0),this.fileAssetService=r,this.workbenchOverlayService=i,this.zIndex=n.zIndex,this.instanceId=n.instanceId;let a=t.attachments.find(e=>e.id===t.initialAttachmentId),s=t.attachments.length?t.attachments:a?[a]:[];this.images=s.map(e=>({attachment:e,status:`idle`})),this._index=Math.max(0,this.images.findIndex(e=>e.attachment.id===t.initialAttachmentId));let c=this.images[this._index];c&&t.originRef&&(c.originRef=t.originRef),this.loadCurrent()}get visible(){return this._visible}get index(){return this._index}get previewImages(){return this.images}setIndex(e){this._index=e,this.loadCurrent(),this._onStatusChange.fire()}close(){this._visible&&(this._visible=!1,this._onStatusChange.fire())}loadCurrent(){let e=this.images[this._index];e&&this.loadImage(e)}dispose(){this.disposed||(this.disposed=!0,this.workbenchOverlayService.removeOverlay(this.instanceId))}loadImage(e){let{attachment:t}=e;if(!t.s3Key){e.status=`failed`,this._onStatusChange.fire();return}if(this.loads.has(t.id))return;e.src||(e.status=`loading`,this._onStatusChange.fire());let n=p(this.fileAssetService,t.s3Key,{role:`large`}).then(t=>{this.disposed||(e.src=t,e.status=t?`loaded`:`failed`)}).catch(()=>{this.disposed||e.src||(e.status=`failed`)}).finally(()=>{this.loads.delete(t.id),this._onStatusChange.fire()});this.loads.set(t.id,n)}};h=m=n([r(2,s),r(3,l)],h);function g(){let e=a(i);return t=>h.create(t,e)}var _,v=_=class{static create(e,n){return n.invokeFunction(e=>e.get(l)).createOverlay(`video-player`,c.videoPlayer,t.videoPlayer,t=>n.createInstance(_,e,t))}constructor(t,n,r){e(this,`workbenchOverlayService`,void 0),e(this,`_onStatusChange`,new o),e(this,`onStatusChange`,this._onStatusChange.event),e(this,`zIndex`,void 0),e(this,`instanceId`,void 0),e(this,`disposed`,!1),e(this,`_status`,`loading`),e(this,`_url`,void 0),this.workbenchOverlayService=r,this.zIndex=n.zIndex,this.instanceId=n.instanceId,this.load(t)}get status(){return this._status}get url(){return this._url}async load(e){try{let t=await e.loadUrl();if(this.disposed)return;this._url=t,this._status=this._url?`ready`:`failed`}catch{this._status=`failed`}this._onStatusChange.fire()}close(){this.dispose()}dispose(){this.disposed||(this.disposed=!0,this.workbenchOverlayService.removeOverlay(this.instanceId))}};v=_=n([r(2,l)],v);function y(){let e=a(i);return t=>v.create(t,e)}export{g as n,p as r,y as t};
//# sourceMappingURL=useVideoPlayer-wOvz1MmI.js.map