import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,o as n}from"./jsx-runtime-DHSfUA5-.js";import{P as r}from"./test.id-DxQrYxPk.js";import{n as i}from"./fileAssetService-gA4Q8V3n.js";var a=t(`circle-dot-dashed`,[[`path`,{d:`M10.1 2.18a9.93 9.93 0 0 1 3.8 0`,key:`1qdqn0`}],[`path`,{d:`M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7`,key:`1bq7p6`}],[`path`,{d:`M21.82 10.1a9.93 9.93 0 0 1 0 3.8`,key:`1rlaqf`}],[`path`,{d:`M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69`,key:`1xk03u`}],[`path`,{d:`M13.9 21.82a9.94 9.94 0 0 1-3.8 0`,key:`l7re25`}],[`path`,{d:`M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7`,key:`1v18p6`}],[`path`,{d:`M2.18 13.9a9.93 9.93 0 0 1 0-3.8`,key:`xdo6bj`}],[`path`,{d:`M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69`,key:`1jjmaz`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),o=t(`wifi`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M2 8.82a15 15 0 0 1 20 0`,key:`dnpr2z`}],[`path`,{d:`M5 12.859a10 10 0 0 1 14 0`,key:`1x1e6c`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}]]);function s(e){return Math.round(Math.min(240,88+Math.max(0,e)/59*152))}var c=e(n(),1),l,u;function d(e){return l===e}function f(){u?.()}function p(e,t){u?.(),l=e,u=()=>{e.pause(),e.currentTime=0,l=void 0,u=void 0,t()},e.play().catch(()=>u?.())}function m(e){let t=r(i),[n,a]=(0,c.useState)(!1),[o,s]=(0,c.useState)(!1),[l,u]=(0,c.useState)(!1),m=(0,c.useRef)(),h=(0,c.useRef)(!1);return(0,c.useEffect)(()=>(h.current=!1,()=>{h.current=!0;let e=m.current;e&&d(e)&&f(),m.current=void 0}),[e.id]),{failed:l,loading:o,playing:n,togglePlay:async()=>{let n=m.current;if(n&&d(n)){f();return}if(!o)try{if(u(!1),!e.s3Key)throw Error(`Audio is missing.`);s(!0);let n=await t.getFileUrl(e.s3Key,{role:`thumbnail`});if(!n)throw Error(`Failed to load audio.`);if(h.current)return;let r=m.current;r||(r=new Audio,m.current=r),r.src!==n&&(r.src=n),r.onended=()=>f(),r.onerror=()=>{u(!0),f()},a(!0),p(r,()=>{h.current||a(!1)})}catch{h.current||u(!0)}finally{h.current||s(!1)}}}}export{a as i,s as n,o as r,m as t};
//# sourceMappingURL=useAttachmentAudioPlayback-BkZ44Dh-.js.map