import{r as d,bT as M,e as k,j as t,d as x,c0 as j,D as z,a1 as B,a3 as H,aB as F,aC as O,A as _}from"./main-D6SjkSWq.js";import{a as G,t as Q}from"./share-media-button-DKcCMMvL.js";import{b as J,u as y}from"./use-player-store-_08VVZOs.js";import{a as K,u as L}from"./comment-bar-new-comment-form-DwRWesDV.js";import{$ as U}from"./useInteractOutside-B51FER0Z.js";import{u as R}from"./use-slider-CDgGIHk-.js";import{W as C,a as I}from"./generate-waveform-data-BFwf5N3g.js";import{F as T}from"./formatted-duration-DCG54VKZ.js";function X(s,i){var m;const e=J(),n=y(o=>o.cuedMedia),r=y(o=>o.mediaDuration),c=(n==null?void 0:n.id)===s.id&&r?r:(s.duration||0)/1e3,[u,f]=d.useState(s.id===((m=e.getState().cuedMedia)==null?void 0:m.id)?e.getCurrentTime():0);return d.useEffect(()=>e.subscribe({progress:({currentTime:o})=>{var a;f(s.id===((a=e.getState().cuedMedia)==null?void 0:a.id)?o:0)}}),[e,s]),{duration:c,minValue:0,maxValue:c,value:u,onPointerDown:()=>{var o;e.setIsSeeking(!0),e.pause(),((o=e.getState().cuedMedia)==null?void 0:o.id)!==s.id&&M.flushSync(async()=>{if(i!=null&&i.length){const a=i==null?void 0:i.findIndex(h=>h.id===s.id);e.overrideQueue(await G(i),a)}else e.cue(await Q(s))})},onChange:o=>{e.getState().emit("progress",{currentTime:o}),e.seek(o)},onChangeEnd:()=>{e.setIsSeeking(!1),e.play()}}}function Y({comments:s,track:i}){const{user:e,hasPermission:n}=k(),{newCommentInputRef:r,newCommentPositionRef:c,markerIsVisible:u,setMarkerIsVisible:f,...m}=d.useContext(K),o=m.disableCommenting||!n("comments.create"),{domProps:a,groupId:h,trackRef:p,getThumbPercent:b}=R({onChange:()=>{f(!0),c.current=b(0)*100},onChangeEnd:()=>{var l;(l=r.current)==null||l.focus()}});return U({ref:p,onInteractOutside:l=>{var v;(v=r.current)!=null&&v.contains(l.target)||f(!1)}}),t.jsxs("div",{className:x("absolute left-0 top-48 isolate h-26 w-full",!o&&"cursor-pointer"),ref:p,...o?{}:a,id:h,children:[u?t.jsx("div",{className:"absolute left-0 top-0 z-20 h-26 w-26 -translate-x-1/2 cursor-move overflow-hidden shadow-md",style:{left:`${b(0)*100}%`},children:t.jsx(j,{src:e==null?void 0:e.image,label:e==null?void 0:e.name,circle:!1,size:"w-full h-full"})}):null,s.map(l=>l.user?t.jsxs(z,{type:"popover",triggerOnHover:!0,children:[t.jsx("div",{style:{left:`${Math.min(99,l.position||0)}%`},className:x("absolute top-0 -translate-x-1/2 cursor-pointer transition-opacity duration-300 ease-in-out",u?"opacity-40":"opacity-100"),children:t.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded bg-fg-base/60 bg-cover shadow",style:{backgroundImage:`url(${l.user.image})`},children:l.user.image?null:t.jsx(j,{label:l.user.name,circle:!1,size:"w-full h-full"})})}),t.jsx(Z,{comment:l})]},l.id):null)]})}function Z({comment:s}){return t.jsx(B,{size:"w-auto",children:t.jsx(H,{padding:"p-8",children:t.jsxs("div",{className:"flex items-center gap-10",children:[s.user&&t.jsx("div",{className:"text-primary",children:s.user.name}),t.jsx("div",{children:s.content})]})})})}function S(s,i,e){const n=i.getContext("2d");n&&(n.clearRect(0,0,i.width,i.height),n.fillStyle=e,n.globalAlpha=.5,s.forEach(r=>{const c=.55*r[3];n.fillRect(r[0],r[1]+r[3]+1,r[2],c)}),n.fillStyle=e,n.globalAlpha=1,s.forEach(r=>{n.fillRect(r[0],r[1],r[2],r[3])}))}const E="text-[11px] absolute bottom-32 p-3 rounded text-white font-semibold z-30 pointer-events-none bg-black/80";function ie({track:s,queue:i,className:e}){const n=d.useRef(null),r=d.useRef(null),c=d.useRef(null),[u,f]=d.useState(!1),[m,o]=d.useState(!1),{data:a}=L(s.id,{enabled:u}),h=F();d.useEffect(()=>{const g=new IntersectionObserver(D=>{D.forEach(w=>{w.isIntersecting&&w.target===n.current&&(f(!0),g.disconnect())})},{root:document.body});return n.current&&g.observe(n.current),()=>g.disconnect()},[]),d.useEffect(()=>{r.current&&(a!=null&&a.waveData)&&c.current&&(S(a.waveData,r.current,"#666"),S(a.waveData,c.current,O(h.selectedTheme.values["--be-primary"])),o(!0))},[a,h.selectedTheme]);const{value:p,onChange:b,onChangeEnd:l,duration:v,...N}=X(s,i),{domProps:P,groupId:V,thumbIds:A,trackRef:W,getThumbPercent:$}=R({...N,value:[p],onChange:([g])=>b(g),onChangeEnd:()=>l()});return t.jsx(_,{mode:"wait",children:t.jsxs("section",{className:"relative max-w-full",children:[t.jsxs("div",{id:V,role:"group",ref:n,className:x("relative isolate h-70 cursor-pointer overflow-hidden transition-opacity duration-200 ease-in",m?"opacity-100":"opacity-0",e),children:[t.jsx("output",{className:x(E,"left-0"),htmlFor:A[0],"aria-live":"off",children:p?t.jsx(T,{seconds:p}):"0:00"}),t.jsxs("div",{...P,ref:W,children:[t.jsx("canvas",{ref:r,width:C,height:I+25}),t.jsx("div",{className:"absolute left-0 top-0 z-20 w-0 overflow-hidden",style:{width:`${$(0)*100}%`},children:t.jsx("canvas",{ref:c,width:C,height:I+25})})]},"wave"),t.jsx("div",{className:x(E,"right-0"),children:t.jsx(T,{seconds:v})})]}),(a==null?void 0:a.comments)&&t.jsx(Y,{comments:a.comments,track:s})]})})}export{ie as W,X as u};
