1import{c as ft,r as a,j as e,a as W,U as rt,W as qt,b as gs}from"./index-ulJQSrBi.js";import{B as _,D as bs,m as ws,n as js,o as ys,p as vs,a9 as _e,aZ as _t,av as ne,aj as Te,al as me,s as ce,a4 as Se,C as Ns,X as Ut,a_ as Le,a8 as Ce,V as Ie,aR as ot,w as Bt,J as Kt,K as Ht,ak as qe,v as ke,U as Ue,x as zt,y as ct,z as lt,E as Nt,G as dt,I as St,N as ut,O as Ae,Q as De,b2 as Ss,h as ks,R as Ve,t as kt,W as Cs,L as Ts,a0 as Es,Y as Ms,bL as Ye,aA as Ct,q as Ls,ad as Oe,l as As}from"./main-PG-dEEgK.js";import{disableSessionReplay as Ds,enableSessionReplay as Is}from"./posthog-DX5zcSJa.js";import{O as Ps,d as pt,C as $s,z as $e,t as mt,T as Pe,a as se,i as Qe,B as Xe,V as gt,f as Ze,b as ze,R as Os,A as Rs,S as Tt,c as Re,W as Fs}from"./components-CwZ8kStA-krSeJG8a.js";import{b as Qt,c as Wt,u as Et,a as Vs}from"./stableQueryData-BbGl7JVl.js";import{A as Jt,a as Gt}from"./avatar-CifY7QVQ.js";import{A as qs}from"./LazyModals-Dz9X83dO.js";import{D as _s,a as Us,b as Bs,e as Ks,d as et,c as Fe,C as Hs,K as zs,L as Qs}from"./dropdown-menu-BvujFdpV.js";import{M as Yt,V as Ws,a as Js,b as Gs}from"./MuxPlayer-BdC75QY5.js";import{C as Ys}from"./circle-help-DUYv4_GA.js";import{B as Xs}from"./book-open-CMY6u06D.js";import{E as tt}from"./external-link-CDDJqvif.js";import{M as Zs}from"./mail-BNoLaWzs.js";import{M as bt}from"./message-square-pFjsRKO5.js";import{P as ea}from"./pencil-mEigEtBZ.js";import{C as Xt}from"./clock-B_03dIHR.js";import{M as ht}from"./message-circle-Du2tsWr5.js";import{U as ta}from"./user-DnoBQ_N9.js";import{A as Mt,a as Lt,b as At,c as Dt,d as It,e as Pt,f as $t,g as Ot}from"./alert-dialog-BIpN1Zkd.js";import{P as sa,a as aa,b as na}from"./popover-DIb35DQD.js";import{M as Zt}from"./mic-4DoBgp1T.js";import{M as es}from"./mic-off-CpkTq2Je.js";import{P as ia}from"./phone-off-uIpEVwB8.js";import{S as We,a as Je,b as wt,c as jt,d as ts}from"./sheet-Alx_nX1I.js";import{S as Ge}from"./scroll-area-MMb6Sg8j.js";import{S as ra}from"./signal-CNpkUf_L.js";import{C as ss}from"./chevron-up-Dp50VgDC.js";import{T as oa}from"./textarea-D_pQ9hwB.js";import{S as as}from"./separator-C8B_YAXL.js";import{C as Rt}from"./circle-check-J-igccrv.js";import{S as ns}from"./send-uqi13TZD.js";import{T as ca}from"./trash-2-ZUj-hLLC.js";import{A as la}from"./activity-CImCEgrW.js";import{u as da}from"./useFeatureAccess-B_F7QKzK.js";import{d as ua,f as ma}from"./formatDistanceToNow-SJewVC13.js";import{V as ha}from"./volume-2-DqnFQvuu.js";import{i as Ft,u as xa}from"./useBrandedRedirect-DXlbEjjs.js";import"./module-DtYSpWMY.js";import"./index-I50MGp6k.js";import"./index-BiuIwfKB.js";import"./useOrgQuery-ChPr6fxi.js";import"./index-DDJOdvVc.js";import"./pause-WYhbreAT.js";import"./index-BdQq_4o_.js";import"./constructNow-dF40L9rq.js";import"./en-US-B0J26mvj.js";import"./endOfMonth-9KAgwlSt.js";import"./endOfDay-nzL9IhLD.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const st=ft("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);/** 7 * @license lucide-react v0.453.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const fa=ft("MessageCircleOff",[["path",{d:"M20.5 14.9A9 9 0 0 0 9.1 3.5",key:"1iebmn"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5.6 5.6C3 8.3 2.2 12.5 4 16l-2 6 6-2c3.4 1.8 7.6 1.1 10.3-1.7",key:"1ov8ce"}]]);/** 12 * @license lucide-react v0.453.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const is=ft("MonitorUp",[["path",{d:"m9 10 3-3 3 3",key:"11gsxs"}],["path",{d:"M12 13V7",key:"h0r20n"}],["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}]]),at=4/3;function pa(t){return t<=1?960:t<=2?720:t<=4?600:480}function ga(t){return t<769?140:180}function ba(t){return t<769?4:8}function wa(t,r,c){const x=ba(t),v=pa(c),f=ga(t);
16if(c<=0)return{cols:1,rows:1,tileWidth:0,tileHeight:0,gap:x,containerWidth:t,containerHeight:r};let d={cols:1,rows:c,tileWidth:f,tileHeight:f/at,gap:x,containerWidth:t,containerHeight:r},s=0;for(let o=1;o<=c;o++){const u=Math.ceil(c/o),g=t-x*(o-1),i=r-x*(u-1);if(g<=0||i<=0)continue;const p=g/o,m=i/u;let N=Math.min(p,m*at,v);if(N=Math.floor(N),N<f)continue;const E=Math.floor(N/at),h=N*E;h>s&&(s=h,d={cols:o,rows:u,tileWidth:N,tileHeight:E,gap:x,containerWidth:t,containerHeight:r})}return d}function ja(t,r){const[c,x]=a.useState({cols:1,rows:1,tileWidth:0,tileHeight:0,gap:8,containerWidth:0,containerHeight:0}),v=a.useCallback(()=>{const f=t.current;if(!f)return;const d=f.getBoundingClientRect(),s=wa(d.width,d.height,r);x(s)},[t,r]);return a.useEffect(()=>{const f=t.current;if(!f)return;v();const d=new ResizeObserver(()=>{v()});return d.observe(f),()=>{d.disconnect()}},[t,v]),c}const q=(...t)=>{};function ya(){const[t,r]=a.useState(!1),c=x=>{window.open(x,"_blank","noopener,noreferrer")};return e.jsxs(e.Fragment,{children:[e.jsxs(_s,{children:[e.jsx(Us,{asChild:!0,children:e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8 rounded-full border border-white/10 bg-white/10 text-white shadow-none hover:bg-white/20 hover:text-white","data-testid":"button-help-menu",children:e.jsx(Ys,{className:"w-4 h-4"})})}),e.jsxs(Bs,{align:"end",className:"w-56 rounded-2xl border border-white/10 bg-slate-950/95 text-white shadow-[0_18px_70px_rgba(0,0,0,0.42)] backdrop-blur-xl",children:[e.jsx(Ks,{children:"Help & Resources"}),e.jsx(et,{}),e.jsxs(Fe,{onClick:()=>r(!0),"data-testid":"menu-item-promo-video",children:[e.jsx(Hs,{className:"w-4 h-4 mr-2"}),"Promo Video"]}),e.jsx(et,{}),e.jsxs(Fe,{onClick:()=>c("/docs"),"data-testid":"menu-item-docs",children:[e.jsx(Xs,{className:"w-4 h-4 mr-2"}),"Documentation",e.jsx(tt,{className:"w-3 h-3 ml-auto"})]}),e.jsxs(Fe,{onClick:()=>c("/help"),"data-testid":"menu-item-support",children:[e.jsx(Zs,{className:"w-4 h-4 mr-2"}),"Support Center",e.jsx(tt,{className:"w-3 h-3 ml-auto"})]}),e.jsxs(Fe,{onClick:()=>c("/contact"),"data-testid":"menu-item-contact",children:[e.jsx(bt,{className:"w-4 h-4 mr-2"}),"Contact Us",e.jsx(tt,{className:"w-3 h-3 ml-auto"})]}),e.jsx(et,{}),e.jsxs(Fe,{onClick:()=>{alert(`Keyboard Shortcuts: 17 18â/Ctrl + M - Mute/Unmute 19â/Ctrl + E - Camera On/Off 20â/Ctrl + D - Share Screen`)},"data-testid":"menu-item-shortcuts",children:[e.jsx(zs,{className:"w-4 h-4 mr-2"}),"Keyboard Shortcuts"]})]})]}),e.jsx(bs,{open:t,onOpenChange:r,children:e.jsxs(ws,{className:"sm:max-w-4xl p-0 overflow-hidden","data-testid":"modal-promo-video",children:[e.jsxs(js,{className:"sr-only",children:[e.jsx(ys,{children:"How It Works"}),e.jsx(vs,{children:"Watch our promotional video to learn more about hq0"})]}),e.jsx("div",{className:"w-full aspect-video bg-black",children:e.jsx(Yt,{playbackId:"P9Y00dwtv9EQOsZ01qK001O4QG4eXPQh3KqQSYfQWvfpVY",title:"hq0 - White-Label Video Meeting Platform",className:"w-full h-full"})})]})})]})}function va({meeting:t,organization:r,theme:c,customDomain:x,sessionStartedAt:v,isPreviewMode:f=!1,isHost:d=!1,onHoverChange:s,onToggleParticipants:o,qaOpen:u=!1,onQAToggle:g,chatOpen:i=!1,onChatToggle:p,isChatEnabled:m=!0,onChatEnabledChange:N,onMeetingUpdate:E}){var le;const h=f?null:Ps(),A=f?[]:pt(),[O,H]=a.useState(0),[F,Q]=a.useState(!1),R=a.useRef(!1),[n,S]=a.useState(!1),[w,C]=a.useState(!1),[L,M]=a.useState(t.title||""),[V,I]=a.useState(t.title||""),j=a.useRef(null),{toast:P}=_e(),U=_t();ne(()=>{I(t.title||"")},[t.title]);const K=Te({mutationFn:async T=>await me("PATCH",`/api/v1/meetings/${t.id}`,{title:T}),onSuccess:T=>{var Y;const y=((Y=T.data)==null?void 0:Y.title)||L;I(y),P({title:"Meeting name updated",description:"The meeting name has been saved."}),U.invalidateQueries({queryKey:["/api/v1/meetings",t.id]}),E&&T.data&&E(T.data),C(!1)},onError:T=>{P({title:"Failed to update",description:T.message||"Could not update meeting name.",variant:"destructive"})}}),$=()=>{d&&(M(V||t.roomName),C(!0),setTimeout(()=>{var T;return(T=j.current)==null?void 0:T.focus()},0))},B=()=>{const T=L.trim();if(!T){P({title:"Invalid name",description:"Meeting name cannot be empty.",variant:"destructive"});return}K.mutate(T)},X=()=>{C(!1),M(t.title||"")},de=T=>
20{T.key==="Enter"?B():T.key==="Escape"&&X()},{data:Z}=ce({queryKey:["/api/atomic-features/branding/config/public",r.id],queryFn:async()=>{try{const T=await fetch(`/api/atomic-features/branding/config/public/${r.id}`);return T.ok?T.json():null}catch{return null}},enabled:!!r.id,staleTime:5*60*1e3}),{data:ee}=ce({queryKey:["/api/atomic-features/active",r.id],queryFn:async()=>{try{const T=await fetch(`/api/atomic-features/active?organizationId=${r.id}`);return T.ok?T.json():{activeFeatures:[]}}catch{return{activeFeatures:[]}}},enabled:!!r.id,staleTime:5*60*1e3}),G=((le=ee==null?void 0:ee.activeFeatures)==null?void 0:le.some(T=>T.featureId==="remove-in-meeting-branding"&&T.enabled))||r.hideBranding||!1;ne(()=>{const T=v?new Date(v).getTime():NaN,y=Number.isFinite(T)?T:Date.now(),Y=()=>{const ye=Math.floor((Date.now()-y)/1e3);H(Math.max(0,ye))};Y();const oe=setInterval(Y,1e3);return()=>{clearInterval(oe)}},[v,t.id]);const he=T=>{const y=Math.floor(T/3600),Y=Math.floor(T%3600/60),oe=T%60;return y>0?`${y}:${Y.toString().padStart(2,"0")}:${oe.toString().padStart(2,"0")}`:`${Y}:${oe.toString().padStart(2,"0")}`},J=()=>!h||h===$s.Connected?e.jsx(qt,{className:"h-4 w-4 text-green-500"}):e.jsx(gs,{className:"h-4 w-4 text-yellow-500"}),ue=x?`${x}/${t.roomName}`:t.roomName,xe=()=>{R.current||(R.current=!0,s==null||s(!0))},fe=()=>{R.current&&(R.current=!1,s==null||s(!1))};return e.jsxs("div",{className:W("meeting-top-bar absolute top-4 left-4 right-4 flex items-center justify-between gap-4","z-10 transition-all duration-300 ease-in-out"),onMouseEnter:xe,onMouseLeave:fe,onFocus:xe,onBlur:fe,"data-testid":"container-meeting-top-bar",children:[e.jsxs("div",{className:"flex max-w-[70vw] items-center gap-3 rounded-full border border-white/10 bg-black/50 px-4 py-2.5 text-white shadow-[0_16px_60px_rgba(0,0,0,0.36)] backdrop-blur-xl",children:[Z!=null&&Z.logoUrl&&!n?e.jsx("img",{src:Z.logoUrl,alt:Z.companyName||r.name,className:"h-6 max-w-[100px] object-contain","data-testid":"img-organization-logo",onError:()=>S(!0)}):e.jsx(Jt,{className:"h-6 w-6","data-testid":"avatar-organization",children:e.jsx(Gt,{className:"bg-white/20 text-white text-xs font-semibold",children:r.name.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[w?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Se,{ref:j,value:L,onChange:T=>M(T.target.value),onKeyDown:de,className:"h-8 w-[180px] rounded-full border border-white/20 bg-white/10 px-3 py-1 text-sm font-semibold text-white placeholder:text-white/40 sm:w-[280px]",placeholder:"Meeting name",disabled:K.isPending,"data-testid":"input-meeting-title"}),e.jsx(_,{size:"icon",variant:"ghost",onClick:B,disabled:K.isPending,className:"h-8 w-8 rounded-full bg-teal-300 text-slate-950 hover:bg-teal-200","data-testid":"button-save-title",children:e.jsx(Ns,{className:"h-3.5 w-3.5"})}),e.jsx(_,{size:"icon",variant:"ghost",onClick:X,disabled:K.isPending,className:"h-8 w-8 rounded-full bg-white/10 text-white hover:bg-white/20","data-testid":"button-cancel-title",children:e.jsx(Ut,{className:"h-3.5 w-3.5"})})]}):e.jsxs("div",{className:W("flex items-center gap-1.5 group",d&&"cursor-pointer"),onClick:d?$:void 0,"data-testid":"container-meeting-title",children:[e.jsx("span",{className:"truncate max-w-[200px] font-semibold text-white sm:max-w-[400px]","data-testid":"text-meeting-code",children:V||ue}),d&&e.jsx(ea,{className:"h-3.5 w-3.5 text-white/60 opacity-0 transition-opacity group-hover:opacity-100","data-testid":"icon-edit-title"})]}),t.isAiConversation&&e.jsx("span",{className:"hidden text-xs font-medium text-white/60 sm:inline",children:"AI Employee"})]}),!G&&e.jsx("div",{className:"hidden sm:block w-px h-5 bg-white/20 mx-1"}),!G&&e.jsxs("button",{onClick:()=>Q(!0),className:"hidden cursor-pointer items-center gap-1.5 rounded-full border border-white/10 bg-white/10 px-2.5 py-1 text-[11px] font-semibold text-white/70 transition-colors hover:bg-white/20 sm:flex","data-testid":"button-powered-by",children:[e.jsx("span",{className:"hidden sm:inline",children:"Powered by"}),e.jsx("span",{className:"font-black",children:"hq0"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-white/10 bg-black/50 px-3 py-2 text-white shadow-[0_16px_60px_rgba(0,0,0,0.36)] backdrop-blur-xl",children:[e.jsxs("div",{className:"hidden items-center gap-1.5 rounded-full bg-white/10 px-2.5 py-1.5 font-mono text-xs font-semibold text-white sm:flex",children:[J(),e.jsx(Xt,{className:"h-3.5 w-3.5"}),e.jsx("span",{"data-testid":"text-duration",children:he(O)})]}),o?e.jsxs(_,{variant:"outline",size:"sm",onClick:o,className:W("flex h-auto cursor-pointer items-center gap-1.5 rounded-full border border-white/10 bg-white/10 px-2.5 py-1.5 text-xs font-semibold text-white shadow-none hover:bg-white/20 hover:text-white"),"data-testid":"button-toggle-participants","aria-label":"Toggle participant list",children:[e.jsx(rt,{className:"h-3.5 w-3.5"}),e.jsx("span",{"data-testid":"text-participant-count",children:A.length})]}):e.jsxs("div",{className:"flex items-center gap-1.5 rounded-full bg-white/10 px-2.5 py-1.5 text-xs font-semibold text-white","data-testid":"container-participant-count",children:[e.jsx(rt,{className:"h-3.5 w-3.5"}),e.jsx("span",{"data-testid":"text-participant-count",children:A.length})]}),p&&e.jsx(_,{variant:"outline",size:"sm",onClick:p,className:W("h-auto rounded-full border border-white/10 px-2.5 py-1.5 text-white shadow-none hover:text-white",i?"bg-white text-slate-950 hover:bg-white/90":"bg-white/10 hover:bg-white/20"),"data-testid":"button-chat-toggle","aria-label":"Toggle Chat",title:i?"Hide Chat":"Show Chat",children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),d&&N&&e.jsx(_,{variant:"outline",size:"sm",onClick:()=>N(!m),className:W("h-auto rounded-full border border-white/10 px-2.5 py-1.5 text-white shadow-none hover:text-white",m?"bg-white/10 hover:bg-white/20":"bg-red-500 hover:bg-red-500/90"),"data-testid":"button-chat-enable-toggle","aria-label":m?"Disable Chat":"Enable Chat",title:m?"Disable Chat for All":"Enable Chat for All",children:m?e.jsx(ht,{className:"h-3.5 w-3.5"}):e.jsx(fa,{className:"h-3.5 w-3.5"})}),g&&e.jsx(_,{variant:"outline",size:"sm",onClick:g,className:W("h-auto rounded-full border border-white/10 px-2.5 py-1.5 text-white shadow-none hover:text-white",u?"bg-white text-slate-950 hover:bg-white/90":"bg-white/10 hover:bg-white/20"),"data-testid":"button-qa-toggle","aria-label":"Toggle Q&A",title:u?"Hide Q&A":"Show Q&A",children:e.jsx(bt,{className:"h-3.5 w-3.5"})}),e.jsx(ya,{})]}),e.jsx(qs,{open:F,onOpenChange:Q,meetingId:t.id,organizationId:r.id})]})}const xt=a.memo(va,(t,r)=>
20t.meeting.id===r.meeting.id&&t.meeting.roomName===r.meeting.roomName&&t.meeting.title===r.meeting.title&&t.meeting.isAiConversation===r.meeting.isAiConversation&&t.organization.id===r.organization.id&&t.organization.name===r.organization.name&&t.organization.hideBranding===r.organization.hideBranding&&t.customDomain===r.customDomain&&t.sessionStartedAt===r.sessionStartedAt&&t.isPreviewMode===r.isPreviewMode&&t.isHost===r.isHost&&t.qaOpen===r.qaOpen&&t.chatOpen===r.chatOpen&&t.isChatEnabled===r.isChatEnabled);function Na(t=3e3){const r=a.useRef(null),c=a.useRef(null),x=a.useRef(!1);a.useEffect(()=>{const f=r.current;if(!f){console.warn("[useControlBarVisibility] Container ref is null - controls visibility won't work"),setTimeout(()=>{const i=r.current;i&&(console.log("[useControlBarVisibility] Container found on retry:",i),i.classList.add("controls-visible"))},500);return}console.log("[useControlBarVisibility] Initialized with container:",f);const d=()=>{console.log("[useControlBarVisibility] Showing controls"),f.classList.add("controls-visible"),c.current&&clearTimeout(c.current),x.current||(c.current=setTimeout(()=>{console.log("[useControlBarVisibility] Hiding controls after timeout"),f.classList.remove("controls-visible")},t))};let s=0;const o=i=>{const p=Date.now();p-s>100&&(s=p,console.log("[useControlBarVisibility] Mouse moved at",i.clientX,i.clientY),d())},u=()=>{d()},g=()=>{d()};return window.addEventListener("mousemove",o),window.addEventListener("keydown",u),window.addEventListener("touchstart",g),console.log("[useControlBarVisibility] Showing controls initially"),f.classList.add("controls-visible"),c.current=setTimeout(()=>{x.current||(console.log("[useControlBarVisibility] Initial hide after",t+2e3,"ms"),f.classList.remove("controls-visible"))},t+2e3),()=>{try{window.removeEventListener("mousemove",o),window.removeEventListener("keydown",u),window.removeEventListener("touchstart",g)}catch{}c.current&&clearTimeout(c.current)}},[t]);const v=a.useCallback(f=>{x.current=f;const d=r.current;d&&(f?(d.classList.add("controls-visible"),c.current&&(clearTimeout(c.current),c.current=null)):c.current=setTimeout(()=>{d.classList.remove("controls-visible")},t))},[t]);return{containerRef:r,setIsHoveringControls:v}}
20function Sa(){const t=$e(),r=mt([{source:Pe.Source.Camera,withPlaceholder:!1}]),[c,x]=a.useState({connection:{quality:se.Excellent,packetLoss:0,jitter:0,bandwidth:0,rtt:0},videoTracks:[],browser:{fps:60,memory:0,cpuUsage:0},analytics:{posthogEventsPerSecond:0,totalNetworkCalls:0}}),v=a.useRef({frames:0,lastTime:performance.now()}),f=a.useRef(),d=a.useCallback(()=>{v.current.frames++;const s=performance.now(),o=s-v.current.lastTime;if(o>=1e3){const u=Math.round(v.current.frames*1e3/o);x(g=>({...g,browser:{...g.browser,fps:u}})),v.current.frames=0,v.current.lastTime=s}f.current=requestAnimationFrame(d)},[]);return a.useEffect(()=>{if(!t)return;const s=(o,u)=>{u.isLocal&&(console.log(`[Performance] Connection quality changed: ${o}`),x(g=>({...g,connection:{...g.connection,quality:o}})))};return t.on("connectionQualityChanged",s),()=>{t.off("connectionQualityChanged",s)}},[t]),a.useEffect(()=>{if(!t)return;const s=async()=>{const u=[];for(const g of r){const{participant:i,publication:p}=g;if(!(!p||!p.track))try{const m=p.track.mediaStreamTrack;let N=0,E={width:0,height:0},h=0,A="none";if(m){const O=m.getSettings();E={width:O.width||0,height:O.height||0},h=O.frameRate||0}p&&p.track&&(N=0),u.push({participantId:i.identity,participantName:i.name||i.identity,bitrate:N,resolution:E,framerate:h,qualityLimitation:A}),console.log(`[Performance] Video track - ${i.name}: ${E.width}x${E.height} @ ${h}fps, ${N}kbps, limitation: ${A}`)}catch(m){console.error(`[Performance] Error getting stats for ${i.identity}:`,m)}}x(g=>({...g,videoTracks:u}))},o=setInterval(s,2e3);return s(),()=>clearInterval(o)},[t,r]),Le(()=>{const s=()=>
20{if("memory"in performance&&performance.memory){const u=performance.memory,g=Math.round(u.usedJSHeapSize/1048576);x(i=>({...i,browser:{...i.browser,memory:g}}))}},o=setInterval(s,2e3);return s(),()=>clearInterval(o)}),Le(()=>{const s={count:0,lastTime:Date.now()},o={count:0};try{const u=new PerformanceObserver(i=>{for(const p of i.getEntries())if(p.entryType==="resource"){const m=p;o.count++,(m.name.includes("posthog")||m.name.includes("e.hq0.com"))&&(s.count++,console.log(`[Performance] PostHog request detected: ${m.name}`))}});u.observe({entryTypes:["resource"]});const g=setInterval(()=>{const i=Date.now(),p=(i-s.lastTime)/1e3,m=p>0?Math.round(s.count/p*10)/10:0;x(N=>({...N,analytics:{posthogEventsPerSecond:m,totalNetworkCalls:o.count}})),s.count=0,s.lastTime=i},1e3);return()=>{u.disconnect(),clearInterval(g)}}catch(u){console.warn("[Performance] PerformanceObserver not supported:",u)}}),a.useEffect(()=>(f.current=requestAnimationFrame(d),()=>{f.current&&cancelAnimationFrame(f.current)}),[d]),c}function ka(){const t=$e(
20),r=a.useRef(new Map),c=a.useRef(new Map);a.useEffect(()=>{if(!t)return;console.log("[VideoBlackoutDetector] ð Starting video blackout monitoring");const x=s=>{const o=s.id||Math.random().toString(36);if(c.current.has(o))return;console.log("[VideoBlackoutDetector] ð¹ New video element detected:",{id:o,src:s.src||s.srcObject?"MediaStream":"none",readyState:s.readyState,networkState:s.networkState,videoWidth:s.videoWidth,videoHeight:s.videoHeight}),c.current.set(o,s);const u=()=>{console.log("[VideoBlackoutDetector] â
Video loaded:",{id:o,width:s.videoWidth,height:s.videoHeight,readyState:s.readyState})},g=A=>{console.error("[VideoBlackoutDetector] â Video error:",{id:o,error:A.message||"Unknown error",readyState:s.readyState,networkState:s.networkState})},i=()=>{console.warn("[VideoBlackoutDetector] â ï¸ Video stalled:",{id:o,readyState:s.readyState,networkState:s.networkState,currentTime:s.currentTime})},p=()=>{console.warn("[VideoBlackoutDetector] â¸ï¸ Video suspended:",{id:o,readyState:s.readyState,networkState:s.networkState})},m=()=>{console.warn("[VideoBlackoutDetector] â³ Video waiting:",{id:o,readyState:s.readyState,networkState:s.networkState,currentTime:s.currentTime})},N=()=>{console.warn("[VideoBlackoutDetector] ð« Video emptied (source removed):",{id:o,timestamp:new Date().toISOString()})},E=()=>{console.log("[VideoBlackoutDetector] ð Video resized:",{id:o,width:s.videoWidth,height:s.videoHeight})};s.addEventListener("loadeddata",u),s.addEventListener("error",g),s.addEventListener("stalled",i),s.addEventListener("suspend",p),s.addEventListener("waiting",m),s.addEventListener("emptied",N),s.addEventListener("resize",E);const h=()=>{s.removeEventListener("loadeddata",u),s.removeEventListener("error",g),s.removeEventListener("stalled",i),s.removeEventListener("suspend",p),s.removeEventListener("waiting",m),s.removeEventListener("emptied",N),s.removeEventListener("resize",E)};s.__cleanup=h},v=document.querySelectorAll("video");console.log(`[VideoBlackoutDetector] ð¬ Found ${v.length} existing video elements`),v.forEach(s=>{x(s)});const f=new MutationObserver(s=>{s.forEach(o=>{o.addedNodes.forEach(u=>{u instanceof HTMLVideoElement&&x(u)}),o.removedNodes.forEach(u=>{if(u instanceof HTMLVideoElement){const g=u;console.log("[VideoBlackoutDetector] ðï¸ Video element removed"),g.__cleanup&&g.__cleanup()}})})});f.observe(document.body,{childList:!0,subtree:!0});const d=setInterval(()=>{c.current.forEach((s,o)=>{if(!document.body.contains(s)){c.current.delete(o),r.current.delete(o);return}if(s.readyState===0||s.videoWidth===0||s.videoHeight===0||s.paused||!s.srcObject)if(!r.current.has(o))r.current.set(o,{start:Date.now(),logged:!1});else{const g=r.current.get(o),i=Date.now()-g.start;i>100&&!g.logged&&(console.error("[VideoBlackoutDetector] â« VIDEO BLACKOUT DETECTED:",{trackId:o,duration:`${i}ms`,timestamp:new Date().toISOString(),videoElement:{readyState:s.readyState,networkState:s.networkState,paused:s.paused,ended:s.ended,seeking:s.seeking,videoWidth:s.videoWidth,videoHeight:s.videoHeight,currentTime:s.currentTime,srcObject:s.srcObject?"present":"missing"},readyStateText:Ca(s.readyState),networkStateText:Ta(s.networkState)}),g.logged=!0)}else{const g=r.current.get(o);if(g){const i=Date.now()-g.start;console.log("[VideoBlackoutDetector] â
Video recovered from blackout:",{trackId:o,blackoutDuration:`${i}ms`,timestamp:new Date().toISOString()}),r.current.delete(o)}}})},500);return()=>{f.disconnect(),clearInterval(d),console.log("[VideoBlackoutDetector] ð Stopped video blackout monitoring")}},[t])}function Ca(t){return["HAVE_NOTHING (0)","HAVE_METADATA (1)","HAVE_CURRENT_DATA (2)","HAVE_FUTURE_DATA (3)","HAVE_ENOUGH_DATA (4)"][t]||`Unknown (${t})`}function Ta(t){return["NETWORK_EMPTY (0)","NETWORK_IDLE (1)","NETWORK_LOADING (2)","NETWORK_NO_SOURCE (3)"][t]||`Unknown (${t})`}const rs=a.createContext(null);function os(){const t=a.useContext(rs);if(!t)throw new Error("useMeetingRoomContext must be used within a MeetingRoomProvider");return t}const Ea=a.memo(function({value:r,children:c}){return e.jsx(rs.Provider,{value:r,children:c})}),nt=t=>t.startsWith("EG_")||t.toLowerCase().includes("subtitle")||t.toLowerCase().startsWith("stt-"),it=t=>t.toLowerCase().includes("subtitle")||t==="Live Subtitles",Ma=a.memo(function({maxTiles:r}){const c=pt(),{localParticipant:x}=Qe(),v=a.useRef(new Map),f=a.useRef(null),d=mt([{source:Pe.Source.Camera,withPlaceholder:!1}],{onlySubscribed:!1}),s=mt([{source:Pe.Source.ScreenShare,withPlaceholder:!1}],{onlySubscribed:!1}),o=a.useMemo(()=>c.filter(n=>!nt(n.identity)&&!it(n.name||"")),[c]),u=a.useMemo(()=>d.filter(n=>!nt(n.participant.identity)&&!it(n.participant.name||"")),[d]),g=a.useMemo(()=>s.filter(n=>!nt(n.participant.identity)&&!it(n.participant.name||"")),[s]),i=g.length>0;ne(()=>{const n=new Set(u.map(w=>w.participant.identity)),S=new Set(v.current.keys());u.forEach(w=>{var V,I,j,P,U,K,$,B,X,de,Z;const C=w.participant.identity,L=(V=w.publication)==null?void 0:V.track,M=w.participant;if(!S.has(C))q("[VideoGrid] NEW VIDEO TRACK:",{participant:M.name||C,identity:C,trackSid:(I=w.publication)==null?void 0:I.trackSid,isLocal:M.identity===x.identity,isMuted:(j=w.publication)==null?void 0:j.isMuted,isEnabled:(P=w.publication)==null?void 0:P.isEnabled,isSubscribed:(U=w.publication)==null?void 0:U.isSubscribed,source:w.source,mediaStreamTrack:L!=null&&L.mediaStreamTrack?"present":"missing"});else{const ee=v.current.get(C),G={isMuted:(K=w.publication)==null?void 0:K.isMuted,isEnabled:($=w.publication)==null?void 0:$.isEnabled,isSubscribed:(B=w.publication)==null?void 0:B.isSubscribed};JSON.stringify(ee)!==JSON.stringify(G)&&q("[VideoGrid] VIDEO TRACK STATE CHANGED:",{participant:M.name||C,identity:C,previous:ee,current:G,timestamp:new Date().toISOString()})}v.current.set(C,{isMuted:(X=w.publication)==null?void 0:X.isMuted,isEnabled:(de=w.publication)==null?void 0:de.isEnabled,isSubscribed:(Z=w.publication)==null?void 0:Z.isSubscribed})}
20),S.forEach(w=>{n.has(w)||(q("[VideoGrid] VIDEO TRACK REMOVED:",{identity:w,timestamp:new Date().toISOString()}),v.current.delete(w))})},[u,x.identity]);const p=a.useMemo(()=>{const n=new Set(u.map(L=>L.participant.identity)),S=o.filter(L=>!n.has(L.identity));let w=[...u],C=S;if(r){const L=[...w].sort((I,j)=>{var K,$;const P=I.participant.isSpeaking?1:0,U=j.participant.isSpeaking?1:0;return U!==P?U-P:(((K=I.participant.joinedAt)==null?void 0:K.getTime())||0)-((($=j.participant.joinedAt)==null?void 0:$.getTime())||0)}),M=[...C].sort((I,j)=>{var K,$;const P=I.isSpeaking?1:0,U=j.isSpeaking?1:0;return U!==P?U-P:(((K=I.joinedAt)==null?void 0:K.getTime())||0)-((($=j.joinedAt)==null?void 0:$.getTime())||0)});if(L.length+M.length>r){const I=Math.min(L.length,r);w=L.slice(0,I);const j=r-I;C=M.slice(0,j)}else w=L,C=M}return{withCamera:w,withoutCamera:C,total:w.length+C.length}},[u,o,r]),m=ja(f,i?0:p.total);if(i){const n=g[0],S=n.participant.identity===x.identity;return e.jsxs("div",{className:"grid h-full w-full grid-cols-1 lg:grid-cols-[1fr_300px]","data-testid":"container-video-grid-screenshare",children:[e.jsx("div",{className:"relative w-full h-full overflow-hidden bg-black screen-share-tile",children:S?e.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 bg-[linear-gradient(135deg,#10141d_0%,#1a2230_100%)] text-white","data-testid":"container-local-screenshare-placeholder",children:[e.jsx("div",{className:"flex h-24 w-24 items-center justify-center rounded-full border border-white/10 bg-white/10 shadow-[0_16px_50px_rgba(0,0,0,0.28)]",children:e.jsx(is,{className:"w-12 h-12 text-teal-300"})}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h3",{className:"text-xl font-semibold text-white","data-testid":"text-presenting-title",children:"You are presenting"}),e.jsx("p",{className:"text-sm text-white/60","data-testid":"text-presenting-subtitle",children:"Other participants can see your screen"})]})]}):e.jsx(Xe,{trackRef:n,"data-testid":`participant-tile-${n.participant.identity}`})}),e.jsx("div",{className:"flex lg:flex-col overflow-y-auto bg-black",children:u.map(w=>e.jsx("div",{className:"relative aspect-video overflow-hidden bg-black flex-shrink-0 camera-tile",children:e.jsx(Xe,{trackRef:w,"data-testid":`participant-tile-${w.participant.identity}`})},w.participant.identity))})]})}const N=n=>{var S,w;return((S=n.metadata)==null?void 0:S.includes('"kind":"agent"'))||n.kind==="agent"||((w=n.identity)==null?void 0:w.startsWith("agent-"))},{cols:E,rows:h,tileWidth:A,tileHeight:O,gap:H}=m,F=A>0?{display:"grid",gridTemplateColumns:`repeat(${E}, ${A}px)`,gridTemplateRows:`repeat(${h}, ${O}px)`,gap:`${H}px`,justifyContent:"center",alignContent:"center",width:"100%",height:"100%"}:{display:"grid",gridTemplateColumns:"1fr",width:"100%",height:"100%"},Q=A>0?{width:`${A}px`,height:`${O}px`}:{},R=(n,S,w)=>{const C=N(n),L=n.name||n.identity,M=n.isCameraEnabled&&S,V=L.split(" ").map(I=>I[0]).join("").toUpperCase().slice(0,2);return e.jsxs("div",{className:W("relative overflow-hidden camera-tile","rounded-2xl border shadow-[0_18px_70px_rgba(0,0,0,0.3)] transition-all",M?"bg-black":"flex flex-col items-center justify-center gap-4 bg-[linear-gradient(135deg,#10141d_0%,#1a2230_100%)] text-white",n.isSpeaking?"border-teal-300/80 ring-4 ring-teal-300/20":"border-white/10"),style:Q,"data-testid":`participant-tile-${n.identity}`,children:[M?e.jsx(Xe,{trackRef:S}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:W("w-20 h-20 sm:w-24 sm:h-24 rounded-full border border-white/10 bg-white/10 flex items-center justify-center shadow-[0_16px_50px_rgba(0,0,0,0.28)]",n.isSpeaking&&"ring-4 ring-teal-300/30"),children:C?e.jsx(ta,{className:"w-10 h-10 sm:w-12 sm:h-12 text-white/70"}):e.jsx("span",{className:"text-2xl sm:text-3xl font-semibold text-white",children:V})}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-black/30 px-3 py-1.5 text-white/70 backdrop-blur-md",children:[e.jsx(gt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Camera off"})]}),n.isSpeaking&&e.jsxs("div",{className:"absolute top-3 right-3 flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-teal-300 rounded-full animate-pulse"}),e.jsx("div",{className:"w-2 h-2 bg-teal-300 rounded-full animate-pulse delay-75"}),e.jsx("div",{className:"w-2 h-2 bg-teal-300 rounded-full animate-pulse delay-150"})]})]}),e.jsxs("div",{className:"absolute bottom-3 left-3 flex items-center gap-2",children:[e.jsxs("div",{className:"rounded-full border border-white/10 bg-black/50 px-3 py-1.5 text-sm font-medium text-white shadow-[0_10px_30px_rgba(0,0,0,0.3)] backdrop-blur-md",children:[L,w&&" (You)"]}),C&&e.jsx(Ce,{variant:"secondary",className:"rounded-full border-white/10 bg-white/10 text-white",children:"AI Employee"})]})]},n.identity)};return e.jsxs("div",{ref:f,style:F,className:"bg-[#090b10]","data-testid":"container-video-grid",children:[p.withCamera.map(n=>{const S=n.participant.identity===x.identity;return R(n.participant,n,S)}),p.withoutCamera.map(n=>R(n,null,!1))]})}),La=a.memo(function({onLeave:r,theme:c,meeting:x,isHost:v=!1,onHoverChange:f,isWebinar:d=!1,handRaised:s=!1,onHandRaise:o,raisedHandsCount:u=0,raisedHandsList:g=[]}){var K,$;
20const[i,p]=a.useState(!1),[m,N]=a.useState(!1),{localParticipant:E}=Qe(),h=$e(),{toast:A}=_e(),O=a.useRef(!1),H=()=>{p(!0)},F=async()=>{p(!1);try{h&&await h.disconnect()}catch(B){console.log("[Leave Meeting] Error disconnecting from room:",B)}finally{r()}},Q=()=>{N(!0)},R=Te({mutationFn:async()=>{if(!x)throw new Error("Meeting not found");return await me("DELETE",`/api/meetings/${x.slug}/end`,void 0)},onSuccess:()=>{A({title:"Meeting Ended",description:"The meeting has been ended for all participants."}),N(!1),setTimeout(()=>r(),500)},onError:B=>{A({title:"Error",description:B.message||"Failed to end meeting. Please try again.",variant:"destructive"}),N(!1)}}),n=(E==null?void 0:E.isMicrophoneEnabled)??!1,S=(E==null?void 0:E.isCameraEnabled)??!1,w=(E==null?void 0:E.isScreenShareEnabled)??!1,C=($=(K=c==null?void 0:c.colors)==null?void 0:K.light)!=null&&$.card?{backgroundColor:`hsl(${c.colors.light.card} / 0.58)`}:{},L="inline-flex h-11 w-11 items-center justify-center rounded-full border border-white/10 bg-white/10 text-white shadow-none backdrop-blur transition-colors hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",M="bg-white text-slate-950 hover:bg-white/90",V="bg-red-500 text-white hover:bg-red-500/90",I="bg-teal-300 text-slate-950 hover:bg-teal-200",j="border-red-400/40 bg-red-500 text-white hover:bg-red-500/90",P=()=>{O.current||(O.current=!0,f==null||f(!0))},U=()=>{O.current&&(O.current=!1,f==null||f(!1))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:W("meeting-control-bar z-10 flex w-max items-center justify-center gap-2 rounded-full border border-white/10 bg-black/50 px-3 py-2 shadow-[0_18px_70px_rgba(0,0,0,0.42)] backdrop-blur-xl","transition-all duration-300 ease-in-out"),style:C,"data-testid":"container-control-bar",onMouseEnter:P,onMouseLeave:U,onFocus:P,onBlur:U,children:[e.jsx(Ze,{source:Pe.Source.Microphone,showIcon:!1,"data-testid":"button-toggle-mic",className:W(L,n?M:V),title:n?"Mute":"Unmute","aria-label":n?"Mute microphone":"Unmute microphone","aria-pressed":n,children:n?e.jsx(Zt,{className:"h-5 w-5","aria-hidden":"true"}):e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(Ze,{source:Pe.Source.Camera,showIcon:!1,"data-testid":"button-toggle-camera",className:W(L,S?M:V),title:S?"Stop Video":"Start Video","aria-label":S?"Stop video":"Start video","aria-pressed":S,children:S?e.jsx(Ie,{className:"h-5 w-5","aria-hidden":"true"}):e.jsx(gt,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(Ze,{source:Pe.Source.ScreenShare,captureOptions:{audio:!0,selfBrowserSurface:"include"},showIcon:!1,"data-testid":"button-toggle-screenshare",className:W(L,w?I:"bg-white/10 text-white hover:bg-white/20"),title:w?"Stop sharing screen":"Share screen","aria-label":w?"Stop sharing screen":"Share screen","aria-pressed":w,children:e.jsx(is,{className:"h-5 w-5","aria-hidden":"true"})}),d&&!v&&o&&e.jsx(_,{variant:"outline",size:"icon",className:W(L,s?I:"bg-white/10 text-white hover:bg-white/20"),onClick:o,title:s?"Lower Hand":"Raise Hand","aria-label":s?"Lower hand":"Raise hand","aria-pressed":s,"data-testid":"button-raise-hand",children:e.jsx(st,{className:"h-5 w-5","aria-hidden":"true"})}),d&&v&&u>0&&e.jsxs(sa,{children:[e.jsx(aa,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-10 rounded-full border border-white/10 bg-teal-300 px-3 text-slate-950 shadow-none hover:bg-teal-200",title:`${u} hand${u>1?"s":""} raised`,"data-testid":"button-raised-hands-count",children:[e.jsx(st,{className:"h-5 w-5 mr-1"}),e.jsx("span",{className:"text-sm font-bold",children:u})]})}),e.jsx(na,{className:"w-64 rounded-2xl border border-white/10 bg-slate-950/95 p-3 text-white shadow-[0_18px_70px_rgba(0,0,0,0.42)] backdrop-blur-xl","data-testid":"popover-raised-hands-list",side:"top",align:"center",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-bold text-sm uppercase tracking-wide","data-testid":"text-raised-hands-title",children:"Raised Hands"}),e.jsx("div",{className:"space-y-1",children:g.map((B,X)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm py-1 font-medium","data-testid":`item-raised-hand-${X}`,children:[e.jsx(st,{className:"h-4 w-4 text-accent"}),e.jsx("span",{children:B.participantName})]},B.participantId))})]})})]}),v&&x&&e.jsx(_,{variant:"outline",size:"icon",className:W(L,j),onClick:Q,title:"End Meeting for All","aria-label":"End meeting for all participants","data-testid":"button-end-meeting",disabled:R.isPending,children:e.jsx(Qs,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(_,{variant:"outline",size:"icon",className:W(L,j),onClick:H,title:"Leave Meeting","aria-label":"Leave meeting","data-testid":"button-leave-meeting",children:e.jsx(ia,{className:"h-5 w-5","aria-hidden":"true"})})]}),e.jsx(Mt,{open:i,onOpenChange:p,children:e.jsxs(Lt,{"data-testid":"dialog-leave-confirmation",children:[e.jsxs(At,{children:[e.jsx(Dt,{children:"Leave Meeting?"}),e.jsx(It,{children:"Are you sure you want to leave this meeting? You can rejoin at any time."})]}),e.jsxs(Pt,{children:[e.jsx($t,{"data-testid":"button-cancel-leave",children:"Cancel"}),e.jsx(Ot,{onClick:F,"data-testid":"button-confirm-leave",children:"Leave Meeting"})]})]})}),e.jsx(Mt,{open:m,onOpenChange:N,children:e.jsxs(Lt,{"data-testid":"dialog-end-meeting-confirmation",children:[e.jsxs(At,{children:[e.jsx(Dt,{children:"End Meeting for Everyone?"}),e.jsx(It,{children:"This will end the meeting for all participants and they will be disconnected immediately. This action cannot be undone."})]}),e.jsxs(Pt,{children:[e.jsx($t,{"data-testid":"button-cancel-end-meeting",children:"Cancel"}),e.jsx(Ot,{onClick:()=>R.mutate(),"data-testid":"button-confirm-end-meeting",className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"End Meeting"})]})]})})]})});function Aa({open:t,onOpenChange:r}){const c=pt(),{localParticipant:x}=Qe(),v=d=>{switch(d){case se.Excellent:return"text-green-500";case se.Good:return"text-green-400";case se.Poor:return"text-yellow-500";case se.Lost:return"text-red-500";default:return"text-muted-foreground"}},f=d=>{switch(d){case se.Excellent:return"Excellent";case se.Good:return"Good";case se.Poor:return"Poor";case se.Lost:return"Lost";default:return"Unknown"}};return e.jsx(We,{open:t,onOpenChange:r,children:e.jsxs(Je,{side:"right",className:"w-[300px] sm:w-[400px]","data-testid":"sheet-participant-list",children:[e.jsx(wt,{children:e.jsxs(jt,{"data-testid":"text-participants-header",children:["Participants (",c.length,")"]})}),e.jsx(Ge,{className:"h-[calc(100vh-100px)] mt-6",children:e.jsx("div",{className:"space-y-2",children:c.map(d=>{const s=d.identity===(x==null?void 0:x.identity),o=d.isMicrophoneEnabled,u=d.isCameraEnabled,g=d.name||d.identity,i=g.split(" ").map(p=>p[0]).join("").toUpperCase().slice(0,2);return e.jsxs("div",{className:"flex items-center gap-3 p-3 border-2 border-foreground bg-card hover:bg-accent/20 transition-colors","data-testid":`participant-${d.identity}`,children:[e.jsx(Jt,{className:"h-10 w-10",children:e.jsx(Gt,{className:"bg-primary text-primary-foreground text-xs",children:i})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium truncate","data-testid":`text-participant-name-${d.identity}`,children:g}),s&&e.jsx(Ce,{variant:"secondary",className:"text-xs","data-testid":"badge-you",children:"You"})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx(ra,{className:`h-3 w-3 ${v(d.connectionQuality)}`}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f(d.connectionQuality)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o?e.jsx(Zt,{className:"h-4 w-4 text-green-500","data-testid":`icon-m
20ic-on-${d.identity}`}):e.jsx(es,{className:"h-4 w-4 text-muted-foreground","data-testid":`icon-mic-off-${d.identity}`}),u?e.jsx(Ie,{className:"h-4 w-4 text-green-500","data-testid":`icon-camera-on-${d.identity}`}):e.jsx(gt,{className:"h-4 w-4 text-muted-foreground","data-testid":`icon-camera-off-${d.identity}`})]})]},d.identity)})})})]})})}const Da=a.memo(function({roomName:r,enabled:c,onClose:x,onTranscript:v}){const[f,d]=a.useState([]),[s,o]=a.useState("en-US"),[u,g]=a.useState(null),[i,p]=a.useState("idle"),[m,N]=a.useState(!1),[E,h]=a.useState(!1),A=$e();ne(()=>{!c||m||O()},[c]),ne(()=>{if(!c||!A)return;const F=(R,n,S,w)=>{const C=Date.now();d(L=>{const M={text:R,isFinal:n,timestamp:C,segmentId:S||`${C}`,participantIdentity:w},V=L.filter(I=>I.isFinal).slice(-5);return n?[...V,M]:[...V,M]}),n&&v&&R.trim()&&v({speaker:w||"Unknown",text:R.trim(),timestamp:C})},Q=(R,n,S,w)=>{if(w==="lk.transcription")try{const L=new TextDecoder().decode(R),M=JSON.parse(L);q(`[LiveSubtitles] ð DATA: Received transcription from ${M.participantIdentity}`),q(`[LiveSubtitles] Text: "${M.text}" (final: ${M.isFinal})`),h(!0),F(M.text,M.isFinal,M.segmentId,M.participantIdentity)}catch(C){console.error("[LiveSubtitles] â Error parsing transcription data:",C)}};return A.on(ze.DataReceived,Q),()=>{A.off(ze.DataReceived,Q)}},[c,A,v]);const O=async()=>{try{q(`[LiveSubtitles] ð Enabling live subtitles for room: ${r}`),q(`[LiveSubtitles] Language: ${s}`),g(null),p("spawning");const F=await fetch(`/api/meetings/${r}/subtitles`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({language:s})});if(!F.ok){const R=await F.json().catch(()=>({error:`HTTP ${F.status}: ${F.statusText}`}));throw console.error(`[LiveSubtitles] â HTTP error ${F.status}:`,R),new Error(R.error||`HTTP ${F.status}: ${F.statusText}`)}const Q=await F.json();q("[LiveSubtitles] â
Subtitles enabled:",Q),N(!0),p("ready")}catch(F){console.error("[LiveSubtitles] â Error enabling subtitles:",F),F instanceof TypeError&&F.message.includes("fetch")?g(`Network error: ${F.message}. Check CORS, mixed content (https/http), or connection.`):g(F.message||"Failed to enable live subtitles"),p("error")}};if(ne(()=>{!c||!m||(N(!1),d([]),h(!1),O())},[s]),!c)return null;const H=f.length>0?f[f.length-1]:null;return e.jsxs("div",{className:"flex-shrink-0 flex justify-center max-w-4xl mx-auto w-full px-4 z-30 pointer-events-none","data-testid":"container-live-subtitles",children:[u&&e.jsx("div",{className:"mb-2 px-4 py-2 bg-destructive text-destructive-foreground text-sm font-bold border-2 border-foreground shadow-[2px_2px_0px_0px_hsl(var(--foreground))] pointer-events-auto","data-testid":"subtitle-error",children:u}),!E&&!H&&!u&&i!=="idle"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-2 bg-card text-foreground text-sm font-bold border-2 border-foreground shadow-[2px_2px_0px_0px_hsl(var(--foreground))]",children:[e.jsx("div",{className:`w-2 h-2 ${i==="ready"?"bg-green-500 animate-pulse":i==="spawning"?"bg-accent animate-pulse":"bg-destructive"}`,"data-testid":"status-indicator"}),e.jsxs("p",{"data-testid":"status-message",children:[i==="spawning"&&"Starting transcription...",i==="ready"&&"Ready - speak to see captions",i==="error"&&"Connection error"]})]}),H&&e.jsx("div",{className:"flex justify-center animate-fade-in","data-testid":"subtitle-caption",children:e.jsx("div",{className:W("px-4 py-2 bg-card text-foreground text-lg font-bold border-2 border-foreground shadow-[2px_2px_0px_0px_hsl(var(--foreground))] max-w-full text-center",!H.isFinal&&"opacity-70"),"data-testid":H.isFinal?"subtitle-final":"subtitle-interim",children:H.text})})]})});function Ia({open:t,onOpenChange:r,transcripts:c}){const x=a.useRef(null),[v,f]=a.useState(!1),[d,s]=a.useState(!0);ne(()=>{if(d&&x.current&&t){const i=x.current.querySelector("[data-radix-scroll-area-viewport]");i&&(i.scrollTop=i.scrollHeight)}},[c,d,t]);const o=i=>{const p=i.target,m=Math.abs(p.scrollHeight-p.scrollTop-p.clientHeight)<50;s(m)},u=i=>new Date(i).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),g=i=>i.split(" ").map(p=>p[0]).join("").toUpperCase().slice(0,2);return e.jsx(We,{open:t,onOpenChange:r,children:e.jsxs(Je,{side:"bottom",className:W("h-auto p-0 border-t border-border bg-card/95 backdrop-blur-sm transition-all duration-300",v?"max-h-[70vh]":"max-h-[40vh]"),"data-testid":"sheet-transcript",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{className:"flex justify-center pt-3 pb-2 cursor-pointer hover-elevate active-elevate-2",onClick:()=>f(!v),"data-testid":"handle-transcript-drag",children:e.jsx("div",{className:"w-12 h-1 rounded-full bg-muted-foreground
20/30"})}),e.jsxs("div",{className:"flex items-center justify-between px-4 pb-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold","data-testid":"text-transcript-title",children:"Transcript"}),c.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground","data-testid":"text-transcript-count",children:[c.length," ",c.length===1?"entry":"entries"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:e.jsx(_,{size:"icon",variant:"ghost",onClick:()=>f(!v),className:"h-8 w-8","data-testid":"button-transcript-expand","aria-label":v?"Collapse":"Expand",children:v?e.jsx(ot,{className:"h-4 w-4"}):e.jsx(ss,{className:"h-4 w-4"})})})]})]}),e.jsx(Ge,{className:W("transition-all duration-300",v?"h-[calc(70vh-80px)]":"h-[calc(40vh-80px)]"),ref:x,onScrollCapture:o,"data-testid":"scroll-area-transcript",children:e.jsxs("div",{className:"p-4 space-y-3",children:[c.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"text-transcript-empty",children:"No transcript yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Transcripts will appear here as people speak"})]}):c.map(i=>e.jsxs("div",{className:"flex gap-3 text-sm group","data-testid":`transcript-entry-${i.id}`,children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:"h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"text-xs font-semibold text-primary",children:g(i.speaker)})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-foreground","data-testid":`text-speaker-${i.id}`,children:i.speaker}),e.jsx("span",{className:"text-xs text-muted-foreground","data-testid":`text-timestamp-${i.id}`,children:u(i.timestamp)})]}),e.jsx("p",{className:"text-foreground/90 leading-relaxed","data-testid":`text-content-${i.id}`,children:i.text})]})]},i.id)),!d&&c.length>0&&e.jsx("div",{className:"sticky bottom-0 left-0 right-0 flex justify-center pt-2",children:e.jsxs(_,{size:"sm",variant:"secondary",onClick:()=>{var p;s(!0);const i=(p=x.current)==null?void 0:p.querySelector("[data-radix-scroll-area-viewport]");i&&(i.scrollTop=i.scrollHeight)},className:"shadow-lg","data-testid":"button-scroll-to-bottom",children:[e.jsx(ot,{className:"h-4 w-4 mr-1"}),"Jump to latest"]})})]})})]})})}const Pa=Ht({participantName:ut().min(1,"Name is required"),question:ut().min(1,"Question is required").max(500,"Question too long")});function $a({webinarId:t,isHost:r,open:c,onOpenChange:x}){const{toast:v}=_e(),[f,d]=a.useState("");Le(()=>{const h=localStorage.getItem("webinar_participant_name");h&&d(h)});const s=Qt(),{data:o=[],isLoading:u}=ce({queryKey:["/api/webinars",t,"questions"],enabled:c,refetchInterval:1e4,select:s}),g=Wt(o),i=Bt({resolver:Kt(Pa),defaultValues:{participantName:f,question:""}});ne(()=>{f&&i.setValue("participantName",f)},[f,i]);const p=Te({mutationFn:async h=>(localStorage.setItem("webinar_participant_name",h.participantName),d(h.participantName),me("POST",`/api/webinars/${t}/questions`,{participantName:h.participantName,question:h.question})),onSuccess:()=>{v({title:"Question Submitted",description:"Your question has been submitted successfully."}),i.reset({participantName:f,question:""}),qe.invalidateQueries({queryKey:["/api/webinars",t,"questions"]})},onError:h=>{v({title:"Error",description:h.message||"Failed to submit question. Please try again.",variant:"destructive"})}}),m=Te({mutationFn:async h=>me("PATCH",`/api/webinars/${t}/questions/${h}`,{isAnswered:!0}),onSuccess:()=>{v({title:"Question Marked",description:"Question marked as answered."}),qe.invalidateQueries({queryKey:["/api/webinars",t,"questions"]})},onError:h=>{v({title:"Error",description:h.message||"Failed to mark question as answered.",variant:"destructive"})}}),N=h=>{p.mutate(h)},E=[...g].sort((h,A)=>h.isAnswered===A.isAnswered?new Date(A.askedAt).getTime()-new Date(h.askedAt).getTime():h.isAnswered?1:-1);return e.jsx(We,{open:c,onOpenChange:x,children:e.jsxs(Je,{side:"right",className:"w-full sm:max-w-md p-0 flex flex-col","data-testid":"sheet-qa-panel",children:[e.jsxs(wt,{className:"px-6 py-4 border-b",children:[e.jsxs(jt,{className:"flex items-center gap-2","data-testid":"text-qa-title",children:[e.jsx(bt,{className:"w-5 h-5"}),"Q&A"]}),e.jsx(ts,{"data-testid":"text-qa-description",children:"Ask questions and get answers from the host"})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx(Ge,{className:"flex-1 px-6 py-4","data-testid":"scroll-questions",children:u?e.jsx("div",{className:"text-center py-8 text-muted-foreground","data-testid":"text-loading",children:"Loading questions..."}):E.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground","data-testid":"text-no-questions",children:"No questions yet. Be the first to ask!"}):e.jsx("div",{className:"space-y-4","data-testid":"container-questions",children:E.map(h=>e.jsx(ke,{className:h.isAnswered?"opacity-60":"","data-testid":`card-question-${h.id}`,children:e.jsxs(Ue,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground","data-testid":`text-participant-${h.id}`,children:h.participantName}),e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":`text-time-${h.id}`,children:new Date(h.askedAt).toLocaleTimeString()})]}),h.isAnswered&&e.jsxs(Ce,{variant:"secondary",className:"flex items-center gap-1 shrink-0","data-testid":`badge-answered-${h.id}`,children:[e.jsx(Rt,{className:"w-3 h-3"}),"Answered"]})]}),e.jsx("p",{className:"text-sm text-foreground","data-testid":`text-question-${h.id}`,children:h.question}),h.answer&&e.jsxs("div",{className:"mt-2 pl-3 border-l-2 border-primary/20",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Host's Answer:"}),e.jsx("p",{className:"text-sm text-foreground","data-testid":`text-answer-${h.id}`,children:h.answer})]}),r&&!h.isAnswered&&e.jsx("div",{className:"pt-2",children:e.jsxs(_,{size:"sm",variant:"outline",onClick:()=>m.mutate(h.id),disabled:m.isPending,"data-testid":`button-mark-answered-${h.id}`,children:[e.jsx(Rt,{className:"w-3 h-3 mr-1"}),"Mark as Answered"]})})]})},h.id))})}),e.jsx(as,{}),e.jsx("div",{className:"px-6 py-4 bg-muted/20","data-testid":"container-submit-form",children:e.jsx(zt,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(N),className:"space-y-3",children:[e.jsx(ct,{control:i.control,name:"participantName",render:({field:h})=>e.jsxs(lt,{children:[e.jsx(Nt,{children:"Your Name"}),e.jsx(dt,{children:e.jsx(Se,{...h,placeholder:"Enter your name","data-testid":"input-participant-name"})}),e.jsx(St,{})]})}),e.jsx(ct,{control:i.control,name:"question",render:({field:h})=>e.jsxs(lt,{children:[e.jsx(Nt,{children:"Your Question"}),e.jsx(dt,{children:e.jsx(oa,{...h,placeholder:"Type your question here...",rows:3,"data-testid":"input-question"})}),e.jsx(St,{})]})}),e.jsxs(_,{type:"submit",className:"w-full",disabled:p.isPending,"data-testid":"button-submit-question",children:[e.jsx(ns,{className:"w-4 h-4 mr-2"}),p.isPending?"Submitting...":"Submit Question"]})]})})})]})]})})}const Oa=Ht({content:ut().min(1,"Message is required").max(1e3,"Message too long")}),Vt="meeting.chat",Ra=a.memo(function({meetingId:r,participantIdentity:c,participantName:x,isHost:v,open:f,onOpenChange:d}){const{toast:s}=_e(),o=$e(),u=a.useRef(null),{realtimeChatMessages:g,setRealtimeChatMessages:i}=os(),[p,m]=a.useState(!0),{data:N=[],isLoading:E}=ce({queryKey:["/api/meetings",r,"chat"],queryFn:async()=>{const n=await fetch(`/api/meetings/${r}/chat`,{credentials:"include",headers:{Accept:"application/json"}});if(!n.ok)throw new Error(`Failed to fetch chat history: ${n.status}`);return n.json()},enabled:!!r}),h=Bt({resolver:Kt(Oa),defaultValues:{content:""}});ne(()=>{if(!o)return;const n=(S,w,C,L)=>{if(L===Vt)try{const V=new TextDecoder().decode(S),I=JSON.parse(V);if(I.senderIdentity===c)return;i(j=>j.some(P=>P.id===I.id)?j:[...j,I])}catch(M){console.error("[MeetingChat] Error parsing chat message:",M)}};return o.on(ze.DataReceived,n),()=>{o.off(ze.DataReceived,n)}},[o,c,i]),ne(()=>{if(p&&u.current){const n=u.current.querySelector("[data-radix-scroll-area-viewport]");n&&(n.scrollTop=n.scrollHeight)}},[N,g,p]);const A=n=>{const S=n.target,C=S.scrollHeight-S.scrollTop-S.clientHeight<50;m(C)},O=Te({mutationFn:async n=>{const S=`local-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,w=new Date().toISOString(),C={id:S,senderIdentity:c,senderName:x,content:n.content,createdAt:w,isLocal:!0};if(i(M=>[...M,C]),o&&o.localParticipant)try{const V=new TextEncoder().encode(JSON.stringify(C));await o.localParticipant.publishData(V,{reliable:!0,topic:Vt})}catch(M){console.error("[MeetingChat] Error broadcasting message:",M)}const L=await me("POST",`/api/meetings/${r}/chat`,{senderIdentity:c,senderName:x,content:n.content,messageType:"message"});return{tempId:S,savedMessage:L}},onSuccess:({tempId:n,savedMessage:S}
20)=>{i(w=>w.map(C=>C.id===n?{...C,id:S.id,isLocal:!1}:C)),h.reset({content:""})},onError:n=>{s({title:"Error",description:n.message||"Failed to send message. Please try again.",variant:"destructive"})}}),H=Te({mutationFn:async n=>me("DELETE",`/api/meetings/${r}/chat/${n}`),onSuccess:()=>{qe.invalidateQueries({queryKey:["/api/meetings",r,"chat"]}),s({title:"Message Deleted",description:"The message has been removed."})},onError:n=>{s({title:"Error",description:n.message||"Failed to delete message.",variant:"destructive"})}}),F=n=>{O.mutate(n)},Q=[...N.map(n=>{var S,w;return{id:n.id,senderIdentity:n.senderIdentity,senderName:n.senderName,content:n.content,createdAt:((w=(S=n.createdAt)==null?void 0:S.toISOString)==null?void 0:w.call(S))||String(n.createdAt)}}),...g.filter(n=>!N.some(S=>S.id===n.id))].sort((n,S)=>new Date(n.createdAt).getTime()-new Date(S.createdAt).getTime()),R=n=>{try{return new Date(n).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}};return e.jsx(We,{open:f,onOpenChange:d,children:e.jsxs(Je,{side:"right",className:"w-full sm:max-w-md p-0 flex flex-col","data-testid":"sheet-chat-panel",children:[e.jsxs(wt,{className:"px-6 py-4 border-b",children:[e.jsxs(jt,{className:"flex items-center gap-2","data-testid":"text-chat-title",children:[e.jsx(ht,{className:"w-5 h-5"}),"Chat"]}),e.jsx(ts,{"data-testid":"text-chat-description",children:"Send messages to other participants"})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx(Ge,{ref:u,className:"flex-1 px-4 py-4",onScrollCapture:A,"data-testid":"scroll-messages",children:E&&N.length===0&&g.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground","data-testid":"text-loading",children:"Loading messages..."}):Q.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground","data-testid":"text-no-messages",children:"No messages yet. Start the conversation!"}):e.jsx("div",{className:"space-y-3","data-testid":"container-messages",children:Q.map(n=>{const S=n.senderIdentity===c;return e.jsxs("div",{className:W("flex flex-col",S?"items-end":"items-start"),"data-testid":`message-${n.id}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground","data-testid":`text-sender-${n.id}`,children:S?"You":n.senderName}),e.jsx("span",{className:"text-xs text-muted-foreground","data-testid":`text-time-${n.id}`,children:R(n.createdAt)}),v&&e.jsx(_,{size:"icon",variant:"ghost",className:"h-5 w-5",onClick:()=>H.mutate(n.id),disabled:H.isPending||n.id.startsWith("local-"),"data-testid":`button-delete-${n.id}`,title:"Delete message",children:e.jsx(ca,{className:"w-3 h-3 text-muted-foreground"})})]}),e.jsx("div",{className:W("px-3 py-2 rounded-lg max-w-[85%] break-words",S?"bg-primary text-primary-foreground":"bg-muted"),"data-testid":`text-content-${n.id}`,children:n.content})]},n.id)})})}),e.jsx(as,{}),e.jsx("div",{className:"px-4 py-3 bg-muted/20","data-testid":"container-send-form",children:e.jsx(zt,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(F),className:"flex gap-2",children:[e.jsx(ct,{control:h.control,name:"content",render:({field:n})=>e.jsx(lt,{className:"flex-1",children:e.jsx(dt,{children:e.jsx(Se,{placeholder:"Type a message...",autoComplete:"off",...n,"data-testid":"input-message"})})})}),e.jsx(_,{type:"submit",size:"icon",disabled:O.isPending||!h.watch("content"),"data-testid":"button-send",children:e.jsx(ns,{className:"w-4 h-4"})})]})})})]})]})})});function Fa({stats:t}){const[r,c]=a.useState(!1),[x,v]=a.useState(!0);if(ne(()=>{const m=N=>{N.ctrlKey&&N.shiftKey&&N.key==="D"&&(N.preventDefault(),c(E=>!E))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[r]),!r)return null;const f=m=>{switch(m){case se.Excellent:return"bg-green-500";case se.Good:return"bg-green-400";case se.Poor:return"bg-yellow-500";case se.Lost:return"bg-red-500";default:return"bg-gray-500"}},d=m=>{switch(m){case se.Excellent:return"Excellent";case se.Good:return"Good";case se.Poor:return"Poor";case se.Lost:return"Lost";default:return"Unknown"}},s=(m,N)=>m<=N.good?"text-green-500":m<=N.warning?"text-yellow-500":"text-red-500",o=m=>s(m,{good:1,warning:5}),u=m=>s(m,{good:30,warning:100}),g=m=>s(m,{good:100,warning:300}),i=m=>m>=55?"text-green-500":m>=30?"text-yellow-500":"text-red-500",p=m=>m<=200?"text-green-500":m<=500?"text-yellow-500":"text-red-500";return e.jsx("div",{className:"fixed bottom-4 right-4 z-50 w-96 max-h-[80vh] overflow-hidden shadow-2xl","data-testid":"panel-performance-debug",children:e.jsxs(ke,{className:"bg-background/95 backdrop-blur-md border-2 border-primary/20",children:[e.jsxs(Ae,{className:"pb-3 space-y-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(la,{className:"w-5 h-5 text-primary","data-testid":"icon-activity"}),e.jsx(De,{className:"text-lg","data-testid":"text-panel-title",children:"Performance Monitor"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(_,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>v(!x),"data-testid":"button-toggle-expand",children:x?e.jsx(ot,{className:"h-4 w-4"}):e.jsx(ss,{className:"h-4 w-4"})}),e.jsx(_,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>c(!1),"data-testid":"button-close-panel",children:e.jsx(Ut,{className:"h-4 w-4"})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"text-keyboard-hint",children:"Press Ctrl+Shift+D to toggle"})]}),x&&e.jsxs(Ue,{className:"space-y-4 max-h-[calc(80vh-80px)] overflow-y-auto","data-testid":"container-stats",children:[e.jsxs("div",{className:"space-y-2","data-testid":"section-connection",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qt,{className:"w-4 h-4 text-primary","data-testid":"icon-connection"}),e.jsx("h3",{className:"font-semibold text-sm","data-testid":"text-connection-title",children:"Connection Quality"})]}),e.jsxs("div",{className:"pl-6 space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status:"}),e.jsx(Ce,{className:W("text-white",f(t.connection.quality)),"data-testid":"badge-connection-quality",children:d(t.connection.quality)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Packet Loss:"}),e.jsxs("span",{className:o(t.connection.packetLoss),"data-testid":"text-packet-loss",children:[t.connection.packetLoss.toFixed(2),"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Jitter:"}),e.jsxs("span",{className:u(t.connection.jitter),"data-testid":"text-jitter",children:[t.connection.jitter,"ms"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"RTT:"}),e.jsxs("span",{className:g(t.connection.rtt),"data-testid":"text-rtt",children:[t.connection.rtt,"ms"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Bandwidth:"}),e.jsxs("span",{className:"text-foreground","data-testid":"text-bandwidth",children:[t.connection.bandwidth.toFixed(2)," Mbps"]})]})]})]}
20),e.jsxs("div",{className:"space-y-2","data-testid":"section-video",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"w-4 h-4 text-primary","data-testid":"icon-video"}),e.jsxs("h3",{className:"font-semibold text-sm","data-testid":"text-video-title",children:["Video Tracks (",t.videoTracks.length,")"]})]}),e.jsx("div",{className:"pl-6 space-y-3",children:t.videoTracks.length===0?e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"text-no-video-tracks",children:"No video tracks detected"}):t.videoTracks.map((m,N)=>e.jsxs("div",{className:"space-y-1 text-xs border-l-2 border-primary/20 pl-2","data-testid":`video-track-${N}`,children:[e.jsx("div",{className:"font-medium text-foreground","data-testid":`text-participant-name-${N}`,children:m.participantName}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Resolution:"}),e.jsxs("span",{className:"text-foreground","data-testid":`text-resolution-${N}`,children:[m.resolution.width,"x",m.resolution.height]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"FPS:"}),e.jsx("span",{className:i(m.framerate),"data-testid":`text-fps-${N}`,children:m.framerate})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Bitrate:"}),e.jsxs("span",{className:"text-foreground","data-testid":`text-bitrate-${N}`,children:[m.bitrate," kbps"]})]}),m.qualityLimitation!=="none"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Limitation:"}),e.jsx(Ce,{variant:"outline",className:"text-xs","data-testid":`badge-limitation-${N}`,children:m.qualityLimitation})]})]},m.participantId))})]}),e.jsxs("div",{className:"space-y-2","data-testid":"section-browser",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ss,{className:"w-4 h-4 text-primary","data-testid":"icon-browser"}),e.jsx("h3",{className:"font-semibold text-sm","data-testid":"text-browser-title",children:"Browser Performance"})]}),e.jsxs("div",{className:"pl-6 space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Render FPS:"}),e.jsx("span",{className:i(t.browser.fps),"data-testid":"text-render-fps",children:t.browser.fps})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Memory:"}),e.jsxs("span",{className:p(t.browser.memory),"data-testid":"text-memory",children:[t.browser.memory," MB"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"CPU Usage:"}),e.jsx("span",{className:"text-muted-foreground text-xs","data-testid":"text-cpu",children:"Not available in browser"})]})]})]}),e.jsxs("div",{className:"space-y-2","data-testid":"section-analytics",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ks,{className:"w-4 h-4 text-primary","data-testid":"icon-analytics"}),e.jsx("h3",{className:"font-semibold text-sm","data-testid":"text-analytics-title",children:"Analytics Activity"})]}),e.jsxs("div",{className:"pl-6 space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"PostHog:"}),e.jsxs("span",{className:"text-foreground","data-testid":"text-posthog-rate",children:[t.analytics.posthogEventsPerSecond.toFixed(1)," req/s"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total Network:"}),e.jsxs("span",{className:"text-foreground","data-testid":"text-total-network",children:[t.analytics.totalNetworkCalls," requests"]})]})]})]})]})]})})}const Va=a.memo(function(){const{meeting:r,organization:c,theme:x,customDomain:v,sessionStartedAt:f,isH
20ost:d,isPreviewMode:s,webinar:o,isChatEnabled:u,hasChatPowerup:g,agentSpawning:i,agentError:p,subtitlesEnabled:m,transcriptOpen:N,transcripts:E,showParticipantList:h,showQAPanel:A,showChatPanel:O,handleToggleParticipants:H,handleToggleSubtitles:F,handleNewTranscript:Q,handleToggleQA:R,handleToggleChat:n,handleChatEnabledChange:S,handleLeaveClick:w,setShowParticipantList:C,setTranscriptOpen:L,setShowQAPanel:M,setShowChatPanel:V,toast:I}=os(),j=$e(),{localParticipant:P}=Qe(),[U,K]=a.useState(!1),{containerRef:$,setIsHoveringControls:B}=Na(5e3),X=Sa();ka(),ne(()=>{if(!j)return;q("[LiveKit] Room connected:",{roomName:j.name,state:j.state,participants:j.remoteParticipants.size,localParticipant:P.identity});const J=l=>{q("[LiveKit] Connection state changed:",{state:l,timestamp:new Date().toISOString()})},ue=(l,k)=>{q("[LiveKit] Connection quality changed:",{participant:k.name||k.identity,quality:l,isLocal:k.isLocal,timestamp:new Date().toISOString()})},xe=l=>{q("[LiveKit] Participant connected:",{name:l.name,identity:l.identity,sid:l.sid,timestamp:new Date().toISOString()})},fe=l=>{q("[LiveKit] Participant disconnected:",{name:l.name,identity:l.identity,sid:l.sid,timestamp:new Date().toISOString()})},le=(l,k)=>{q("[LiveKit] Track published:",{participant:k.name||k.identity,trackSid:l.trackSid,trackName:l.trackName,source:l.source,kind:l.kind,isMuted:l.isMuted,isEnabled:l.isEnabled,timestamp:new Date().toISOString()})},T=(l,k)=>{q("[LiveKit] Track unpublished:",{participant:k.name||k.identity,trackSid:l.trackSid,trackName:l.trackName,source:l.source,timestamp:new Date().toISOString()})},y=(l,k,z)=>{q("[LiveKit] Track subscribed:",{participant:z.name||z.identity,trackSid:k.trackSid,source:k.source,kind:l.kind,mediaStreamTrack:l.mediaStreamTrack?"present":"missing",timestamp:new Date().toISOString()})},Y=(l,k,z)=>{q("[LiveKit] Track unsubscribed:",{participant:z.name||z.identity,trackSid:k.trackSid,source:k.source,timestamp:new Date().toISOString()})},oe=(l,k)=>{q("[LiveKit] Track muted:",{participant:k.name||k.identity,trackSid:l.trackSid,source:l.source,timestamp:new Date().toISOString()})},ye=(l,k)=>{q("[LiveKit] Track unmuted:",{participant:k.name||k.identity,trackSid:l.trackSid,source:l.source,timestamp:new Date().toISOString()})},Ee=(l,k)=>{q("[LiveKit] Local track published:",{trackSid:l.trackSid,source:l.source,kind:l.kind,timestamp:new Date().toISOString()})},Me=(l,k)=>{q("[LiveKit] Local track unpublished:",{trackSid:l.trackSid,source:l.source,timestamp:new Date().toISOString()})},pe=(l,k,z)=>{q("[LiveKit] Data received:",{participant:(k==null?void 0:k.name)||(k==null?void 0:k.identity),kind:z,payloadSize:l.length,timestamp:new Date().toISOString()})},ve=l=>{q("[LiveKit] Disconnected from room:",{reason:l,timestamp:new Date().toISOString()})},ie=()=>{console.warn("[LiveKit] Reconnecting to room...",{timestamp:new Date().toISOString()})},Ne=()=>{q("[LiveKit] Reconnected to room",{timestamp:new Date().toISOString()})};return j.on("connectionStateChanged",J),j.on("connectionQualityChanged",ue),j.on("participantConnected",xe),j.on("participantDisconnected",fe),j.on("trackPublished",le),j.on("trackUnpublished",T),j.on("trackSubscribed",y),j.on("trackUnsubscribed",Y),j.on("trackMuted",oe),j.on("trackUnmuted",ye),j.on("localTrackPublished",Ee),j.on("localTrackUnpublished",Me),j.on("dataReceived",pe),j.on("disconnected",ve),j.on("reconnecting",ie),j.on("reconnected",Ne),()=>{j.off("connectionStateChanged",J),j.off("connectionQualityChanged",ue),j.off("participantConnected",xe),j.off("participantDisconnected",fe),j.off("trackPublished",le),j.off("trackUnpublished",T),j.off("trackSubscribed",y),j.off("trackUnsubscribed",Y),j.off("trackMuted",oe),j.off("trackUnmuted",ye),j.off("localTrackPublished",Ee),j.off("localTrackUnpublished",Me),j.off("dataReceived",pe),j.off("disconnected",ve),j.off("reconnecting",ie),j.off("reconnected",Ne)}},[j,P.identity]);const de=Qt(),{data:Z=[]}=ce({queryKey:["/api/webinars",o==null?void 0:o.id,"raised-hands"],enabled:!!o&&d&&!s,refetchInterval:3e3,retry:1,select:de,notifyOnChangeProps:["data"]}),ee=Wt(Z),G=a.useCallback(async()=>
20{if(!o||!P)return;const J=!U;K(J);try{await fetch(`/api/webinars/${o.id}/raise-hand`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({participantId:P.identity,participantName:P.name||"Guest",raised:J})}),q(`[RaiseHand] API call: ${P.identity} - ${J?"raised":"lowered"}`),I(J?{title:"Hand Raised",description:"The host has been notified."}:{title:"Hand Lowered",description:"Your hand has been lowered."})}catch(ue){console.error("[RaiseHand] API error:",ue),K(!J),I({title:"Error",description:"Failed to update hand status. Please try again.",variant:"destructive"})}},[o,P,U,I]);ne(()=>{if(!(!o||!P))return()=>{U&&fetch(`/api/webinars/${o.id}/raise-hand`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({participantId:P.identity,participantName:P.name||"Guest",raised:!1})}).catch(J=>console.error("[RaiseHand] Cleanup error:",J))}},[o,P,U]);const he=ee.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:$,className:"absolute inset-0 flex flex-col cursor-default","data-testid":"container-video-panel",children:[e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ma,{})}),i&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 backdrop-blur-sm z-10","data-testid":"overlay-agent-spawning",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-agent-spawning-title",children:"AI Agent is joining the room..."}),e.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"text-agent-spawning-subtitle",children:"Please wait a moment"})]})}),p&&!i&&e.jsx("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 z-10","data-testid":"banner-agent-error",children:e.jsx("div",{className:"bg-destructive text-destructive-foreground px-4 py-2 rounded-md shadow-lg",children:e.jsx("p",{className:"text-sm","data-testid":"text-agent-error",children:p})})}),e.jsx(xt,{meeting:r,organization:c,theme:x,customDomain:v,sessionStartedAt:f,isPreviewMode:!1,isHost:d,onHoverChange:B,onToggleParticipants:H,qaOpen:A,onQAToggle:o?R:void 0,chatOpen:O,onChatToggle:u?n:void 0,isChatEnabled:u,onChatEnabledChange:d&&g?S:void 0}),e.jsx("div",{className:"meeting-control-bar-container absolute bottom-6 left-1/2 -translate-x-1/2 z-10 flex items-center justify-center",children:e.jsx(La,{onLeave:w,theme:x,meeting:r,isHost:d,onHoverChange:B,isWebinar:!!o,handRaised:U,onHandRaise:G,raisedHandsCount:he,raisedHandsList:ee})})]}),e.jsx(Da,{roomName:r.roomName,enabled:m,onClose:F,onTranscript:Q})]}),e.jsx(Aa,{open:h,onOpenChange:C}),e.jsx(Ia,{open:N,onOpenChange:L,transcripts:E}),o&&e.jsx($a,{webinarId:o.id,isHost:d,open:A,onOpenChange:M}),e.jsx(Ra,{meetingId:r.id,participantIdentity:P.identity,participantName:P.name||"Guest",isHost:d,open:u&&O,onOpenChange:V}),e.jsx(Fa,{stats:X}),e.jsx(Os,{})]})});function qa({meeting:t,organization:r,theme:c,token:x,serverUrl:v,sessionStartedAt:f,customDomain:d,isPreviewMode:s=!1,isHost:o=!1,onDisconnected:u}){const{toast:g}=_e(),i=a.useRef(g);i.current=g;const p=_t(),[m,N]=a.useState(!1),[E,h]=a.useState(!1),[A,O]=a.useState(!1),[H,F]=a.useState([]),[Q,R]=a.useState(typeof window<"u"?window.innerWidth:1024),[n,S]=a.useState(!1),[w,C]=a.useState(null),[L,M]=a.useState(!1),[V,I]=a.useState(!1),[j,P]=a.useState([]);Le(()=>(Ds(),()=>{Is()}));const{hasAccess:U}=da("meeting-chat"),K=Et(),{data:$,refetch:B}=ce({queryKey:[`/api/webinars/by-meeting-id/${t.id}`,t.id],enabled:!s,retry:1,select:K,notifyOnChangeProps:["data"]}),X=Et(),{data:de,isLoading:Z}=ce({queryKey:[`/api/v1/meetings/${t.id}/chat-settings`,t.id],enabled:!s,retry:1,refetchInterval:1e4,select:X,notifyOnChangeProps:["data"]}),ee=Vs(de),G=s||Z?!0:(ee==null?void 0:ee.chatEnabled)??!0;Te({mutationFn:async l=>(await me("PATCH",`/api/v1/meetings/${t.id}/chat-settings`,{chatEnabled:l})).json(),onSuccess:()=>{p.invalidateQueries({queryKey:[`/api/v1/meetings/${t.id}/chat-settings`,t.id]}),g({title:G?"Chat Disabled":"Chat Enabled",description:G?"Chat has been disabled for all participants.":"Chat has been enabled for all participants."})},onError:()=>
20{g({title:"Failed to update chat settings",description:"Please try again.",variant:"destructive"})}});const he=a.useCallback(async l=>{await me("PATCH",`/api/v1/meetings/${t.id}/chat-settings`,{chatEnabled:l}),p.invalidateQueries({queryKey:[`/api/v1/meetings/${t.id}/chat-settings`,t.id]}),i.current({title:l?"Chat Enabled":"Chat Disabled",description:l?"Chat has been enabled for all participants.":"Chat has been disabled for all participants."})},[t.id,p]);ne(()=>{!G&&V&&(I(!1),i.current({title:"Chat Disabled",description:"The host has disabled chat for this meeting."}))},[G,V]),Le(()=>{const l=()=>R(window.innerWidth);return window.addEventListener("resize",l),()=>{window.removeEventListener("resize",l)}}),ne(()=>{if(!t.isAiConversation||s)return;const k=setTimeout(async()=>{try{S(!0),C(null),q("[Meeting] Ensuring AI agent is spawned...");const z=await fetch(`/api/meetings/${t.roomName}/ensure-agent`,{method:"POST",credentials:"include"});if(z.ok){const ae=await z.json();ae.spawned?(q(`[Meeting] AI agent spawned: ${ae.agentName}`),i.current({title:"AI Agent Joined",description:`${ae.agentName} is now in the room and ready to chat!`})):q(`[Meeting] Agent not spawned: ${ae.reason}`)}else{const ae=await z.json().catch(()=>({error:"Unknown error"}));console.error("[Meeting] Failed to ensure agent:",ae),C(ae.error||"Failed to spawn AI agent"),i.current({title:"AI Agent Error",description:ae.error||"Failed to spawn AI agent. Please try refreshing the page.",variant:"destructive"})}}catch(z){console.error("[Meeting] Error ensuring agent:",z),C("Network error while spawning AI agent"),i.current({title:"Connection Error",description:"Could not connect to AI agent service. Please check your connection.",variant:"destructive"})}finally{S(!1)}},2e3);return()=>clearTimeout(k)},[t.roomName,t.isAiConversation,s]);const{data:J,isLoading:ue,error:xe}=ce({queryKey:["/api/ai-employees/public",t.aiEmployeeId],queryFn:async()=>{const l=await fetch(`/api/ai-employees/public/${t.aiEmployeeId}`);if(!l.ok)throw console.error(`Failed to fetch AI employee: ${l.status} ${l.statusText}`),new Error("Failed to fetch AI employee");return l.json()},enabled:!!t.aiEmployeeId,retry:2}),fe=a.useCallback(()=>{u&&u()},[u]),le=a.useCallback(()=>{u&&u()},[u]),T=a.useCallback(()=>{N(l=>!l)},[]),y=a.useCallback(()=>{h(l=>!l)},[]),Y=a.useCallback(()=>{O(l=>!l)},[]),oe=a.useCallback(l=>{const k={id:`${l.speaker}-${l.timestamp}`,speaker:l.speaker,text:l.text,timestamp:l.timestamp};F(z=>[...z,k])},[]);ne(()=>{if(!$||!$.waitingRoomEnabled||s)return;const l=setInterval(()=>{B()},5e3);return()=>clearInterval(l)},[$,s,B]);const ye=a.useMemo(()=>!(!$||!$.waitingRoomEnabled||$.status==="live"||$.actualStartTime),[$]),Ee=a.useCallback(async()=>{if($)try{if(!(await fetch(`/api/webinars/${$.id}/start`,{method:"PATCH",credentials:"include"})).ok)throw new Error("Failed to start webinar");await B(),i.current({title:"Webinar Started",description:"The waiting room has been bypassed. All participants can now join."})}catch(l){console.error("Error starting webinar:",l),i.current({title:"Error",description:"Failed to start webinar. Please try again.",variant:"destructive"})}},[$,B]),Me=a.useCallback(()=>{M(l=>!l)},[]),pe=a.useCallback(()=>{I(l=>!l)},[]),ve=a.useMemo(()=>({meeting:t,organization:r,theme:c,customDomain:d,sessionStartedAt:f,isHost:o,isPreviewMode:s,webinar:$,isChatEnabled:G,hasChatPowerup:U,agentSpawning:n,agentError:w,subtitlesEnabled:E,transcriptOpen:A,transcripts:H,showParticipantList:m,showQAPanel:L,showChatPanel:V,realtimeChatMessages:j,setRealtimeChatMessages:P,handleToggleParticipants:T,handleToggleSubtitles:y,handleToggleTranscript:Y,handleNewTranscript:oe,handleToggleQA:Me,handleToggleChat:pe,handleChatEnabledChange:he,handleLeaveClick:fe,setShowParticipantList:N,setTranscriptOpen:O,setShowQAPanel:M,setShowChatPanel:I,toast:i.current}),[t,r,c,d,f,o,s,$,G,U,n,w,E,A,H,m,L,V,j,P,T,y,Y,oe,Me,pe,he,fe]),ie=()=>{if(!(c!=null&&c.colors))return{};const l={},k=c.colors;return k.light&&Object.entries(k.light).forEach(([z,ae])=>{ae&&(l[`--${z}`]=ae)}),l},Ne=a.useMemo(()=>({adaptiveStream:!0,dynacast:!0,videoCaptureDefaults:{resolution:Re.h720.resolution},publishDefaults:{videoEncoding:Re.h720.encoding,videoSimulcastLayers:[Re.h180,Re.h360],screenShareEncoding:Tt.h1080fps30.encoding,screenShareSimulcastLayers:[Tt.h720fps15],audioPreset:Rs.musicHighQuality,simulcast:!0}}),[]);if(!s&&ye){const l=new Date,k=new Date($.scheduledStartTime),z=ua(k,l),ae=ma(k,{addSuffix:!0});return e.jsxs("div",{className:"flex flex-col h-screen w-screen bg-background",style:ie(),"data-testid":"container-waiting-room",children:[e.jsx(xt,{meeting:t,organization:r,theme:c,customDomain:d,isPreviewMode:!0}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:e.jsxs(ke,{className:"w-full max-w-2xl","data-testid":"card-waiting-room",children:[e.jsxs(Ae,{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 mx-auto rounded-full bg-primary/10 flex items-center justify-center mb-4",children:e.jsx(Xt,{className:"w-10 h-10 text-primary","data-testid":"icon-clock"})}),e.jsx(De,{className:"text-3xl","data-testid":"text-webinar-title",children:$.title}),e.jsx(Ve,{className:"text-lg mt-2","data-testid":"text-webinar-description",children:$.description||"Webinar has not started yet"})]}),e.jsxs(Ue,{className:"space-y-6",children:[e.jsxs("div",{className:"text-center p-6 bg-muted/50 rounded-lg","data-testid":"container-countdown",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2","data-testid":"text-starts-label",children:"Scheduled to start"}),e.jsx("p",{className:"text-2xl font-semibold text-foreground","data-testid":"text-countdown",children:ae}),z>60&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2","data-testid":"text-scheduled-time",children:new Date($.scheduledStartTime).toLocaleStr
20ing()})]}),e.jsx("div",{className:"text-center","data-testid":"container-host-info",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Hosted by ",e.jsx("span",{className:"font-medium text-foreground",children:r.name})]})}),o&&e.jsxs("div",{className:"pt-4 border-t","data-testid":"container-host-controls",children:[e.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"As the host, you can start the webinar early"}),e.jsx(_,{onClick:Ee,className:"w-full",size:"lg","data-testid":"button-start-now",children:"Start Webinar Now"})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground","data-testid":"text-auto-refresh",children:"This page will automatically update when the webinar starts"})]})]})})]})}return s?e.jsxs("div",{className:"flex flex-col h-screen w-screen bg-background",style:ie(),"data-testid":"container-branded-meeting-room",children:[e.jsx(xt,{meeting:t,organization:r,theme:c,customDomain:d,isPreviewMode:!0}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center space-y-4 p-8 max-w-lg",children:[e.jsx("div",{className:"w-20 h-20 mx-auto rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"text-4xl text-primary",children:r.name.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold text-foreground",children:t.title||"Video Conference"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Hosted by ",r.name]}),t.isAiConversation&&e.jsxs("div",{className:"mt-4 p-4 bg-accent/10 border border-accent/20 rounded-lg","data-testid":"container-ai-conversation-info",children:[e.jsx("p",{className:"text-sm text-foreground font-medium mb-1","data-testid":"text-ai-conversation-title",children:ue?"Loading AI employee details...":xe?"You're about to talk with an AI Employee":J?`You're about to talk with ${J.name}`:"You're about to talk with an AI Employee"}),e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"text-ai-conversation-tip",children:ue?"Please wait...":xe?"Speak naturally - the AI is listening and will respond in real-time":J?`Speak naturally - ${J.name} is listening and will respond in real-time`:"Speak naturally - the AI is listening and will respond in real-time"})]})]})]})})]}):e.jsx("div",{className:"relative h-screen w-screen bg-black overflow-hidden",style:ie(),"data-testid":"container-branded-meeting-room",children:e.jsx(Fs,{token:x,serverUrl:v,connect:!0,video:{resolution:Re.h720.resolution},audio:!0,options:Ne,onDisconnected:le,"data-lk-theme":"default",style:{height:"100%",width:"100%"},children:e.jsx(Ea,{value:ve,children:e.jsx(Va,{})})})})}function _a({meeting:t,organization:r,theme:c,activeRecording:x,onBack:v}){const[f,d]=a.useState(!1),[s,o]=a.useState(!1),[u,g]=a.useState(0),i=(x==null?void 0:x.muxPlaybackId)||(x==null?void 0:x.muxAssetId),p=(x==null?void 0:x.status)==="recording"||(x==null?void 0:x.status)==="active",m=()=>{document.fullscreenElement?(document.exitFullscreen(),o(!1)):(document.documentElement.requestFullscreen(),o(!0))};Le(()=>{const E=()=>{o(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",E),()=>document.removeEventListener("fullscreenchange",E)});const N=()=>{if(!(c!=null&&c.colors))return{};const E={},h=c.colors;return h.light&&Object.entries(h.light).forEach(([A,O])=>{O&&(E[`--${A}`]=O)}),E};return i?e.jsxs("div",{className:"flex flex-col h-screen w-screen bg-background",style:N(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[v&&e.jsxs(_,{variant:"ghost",size:"sm",onClick:v,children:[e.jsx(kt,{className:"h-4 w-4 mr-2"}),"Back"]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:t.title||"Untitled Meeting"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.name})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[u," viewers"]})]}),p&&e.jsxs(Ce,{variant:"outline",className:"text-red-600 border-red-600",children:[e.jsx("div",{className:"h-2 w-2 bg-red-500 rounded-full animate-pulse mr-2"}),"LIVE"]})]})]}),e.jsxs("div",{className:"flex-1 relative bg-black",children:[e.jsx(Yt,{playbackId:i,isLive:p,title:t.title||"Meeting Livestream",className:"w-full h-full"}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 p-4 bg-gradient-to-t from-black/70 to-transparent",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(_,{size:"sm",variant:"ghost",className:"text-white hover:bg-white/20",onClick:()=>d(!f),children:f?e.jsx(Ws,{className:"h-4 w-4"}):e.jsx(ha,{className:"h-4 w-4"})})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(_,{size:"sm",variant:"ghost",className:"text-white hover:bg-white/20",onClick:m,children:s?e.jsx(Js,{className:"h-4 w-4"}):e.jsx(Gs,{className:"h-4 w-4"})})})]})})]}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Live Stream"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["You're watching in viewer mode â¢",p?" Stream is live":" Stream ended"]})]}),!p&&e.jsx(Ce,{variant:"secondary",children:"Stream Ended"})]})})]}):e.jsxs("div",{className:"flex flex-col h-screen w-screen bg-background",style:N(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[v&&e.jsxs(_,{variant:"ghost",size:"sm",onClick:v,children:[e.jsx(kt,{className:"h-4 w-4 mr-2"}),"Back to Recordings"]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:t.title||"Untitled Meeting"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.name})]})]}),e.jsxs(Ce,{variant:"outline",className:"text-red-600 border-red-600",children:[e.jsx("div",{className:"h-2 w-2 bg-red-500 rounded-full animate-pulse mr-2"}),"LIVE"]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-black",children:e.jsx(ke,{className:"max-w-md",children:e.jsxs(Ue,{className:"py-8 text-center",children:[e.jsx(Cs,{className:"h-12 w-12 text-yellow-500 mx-auto mb-4"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Live Stream Not Available"}),e.jsx("p",{className:"text-muted-foreground",children:"The live stream for this meeting is not available yet. Please wait for the host to start streaming."}),e.jsxs(_,{className:"mt-4",onClick:()=>window.location.reload(),children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),"Refresh"]})]})})})]})}function Rn(){const{slug:t}=Es(),{user:r,isLoading:c,currentOrg:x,currentRole:v}
20=Ms(),[f,d]=a.useState(!1),[s,o]=a.useState(void 0),[u,g]=a.useState(""),[i,p]=a.useState(""),[m,N]=a.useState(""),[E,h]=a.useState(null),[A,O]=a.useState(!1),[H,F]=a.useState(!1),Q=a.useRef(!1),R=a.useRef(null),[n,S]=a.useState(null),[w,C]=a.useState(!1),[L,M]=a.useState(!1),V=new URLSearchParams(window.location.search),I=V.get("mode")==="viewer",j=V.get("handoff"),P=a.useRef(j),[U,K]=a.useState("email"),[$,B]=a.useState(""),[X,de]=a.useState(""),[Z,ee]=a.useState(""),[G,he]=a.useState(""),[J,ue]=a.useState(!1),[xe,fe]=a.useState(!1),[le,T]=a.useState(!1);a.useEffect(()=>{if(!j||!t||L)return;(async()=>{C(!0);try{const D=await me("POST","/api/meetings/verify-handoff",{handoffToken:j,meetingSlug:t});D.verified&&D.user&&(console.log("[Handoff] Verified host handoff for user:",D.user.email),S(D.user))}catch(D){console.warn("[Handoff] Failed to verify handoff token:",D)}finally{C(!1),M(!0);const D=new URL(window.location.href);D.searchParams.delete("handoff"),window.history.replaceState({},"",D.toString())}})()},[j,t,L]);const{data:y,isLoading:Y,isError:oe,error:ye,isSuccess:Ee,refetch:Me}=ce({queryKey:[`/api/meetings/slug/${t}`],enabled:!!t,retry:(b,D)=>Ft(D)?!1:b<2}),pe=oe&&Ft(ye),ve=oe&&!pe,{data:ie,isLoading:Ne}=ce({queryKey:["/api/organizations/public",y==null?void 0:y.organizationId],queryFn:async()=>{const b=await fetch(`/api/organizations/public/${y.organizationId}`);if(!b.ok)throw new Error("Failed to fetch organization");return b.json()},enabled:!!(y!=null&&y.organizationId)}),{data:l}=ce({queryKey:["/api/theme/public",y==null?void 0:y.organizationId],queryFn:async()=>{const b=await fetch(`/api/theme/public/${y.organizationId}`);return b.ok?b.json():null},enabled:!!(y!=null&&y.organizationId)}),{customDomain:k,customDomainLoading:z,resolveRedirectUrl:ae}=xa({organizationId:y==null?void 0:y.organizationId}),{data:ge}=ce({queryKey:["/api/atomic-features/branding/config/public",y==null?void 0:y.organizationId],queryFn:async()=>{try{const b=await fetch(`/api/atomic-features/branding/config/public/${y.organizationId}`);return b.ok?b.json():null}catch{return null}},enabled:!!(y!=null&&y.organizationId),staleTime:5*60*1e3}),{data:cs,isLoading:ls}=ce({queryKey:[`/api/recordings/meeting/${y==null?void 0:y.id}/active`],enabled:!!(y!=null&&y.id)&&I}),ds=Y||Ne||c||w||I&&ls,be=r||n,Be=Te({mutationFn:async b=>{const D={...b,...P.current?{handoffToken:P.current}:{}};return await me("POST",`/api/meetings/${t}/token`,D)},onSuccess:b=>{g(b.token),p(b.roomName),N(b.serverUrl),h(b.sessionStartedAt||null),O(!0),Ye(!0)},onError:b=>{var re;console.error("Failed to generate meeting token:",b),b.name==="AbortError"||b.code===20||((re=b.message)==null?void 0:re.toLowerCase().includes("aborted"))||alert(`Failed to join meeting: ${b.message||"Unknown error"}`)}}),us=async b=>{try{return await me("POST",`/api/meetings/${t}/email-lookup`,{email:b})}catch(D){return console.error("Email lookup failed:",D),null}};Le(()=>{const b=localStorage.getItem("hq0_guest_info");if(b)try{const D=JSON.parse(b);D.email&&(de(D.email),D.name&&B(D.name),D.companies&&ee(D.companies),D.mobile&&he(D.mobile))}catch(D){console.error("Failed to parse saved guest info:",D)}}),a.useEffect(()=>()=>{A&&Ye(!1)},[A]);const ms=()=>{if(!be)return;const b=be.name||be.email.split("@")[0],D=`${be.id}-${Date.now()}`;Be.mutate({participantName:b,participantIdentity:D,participantEmail:be.email})},we=a.useRef(!1),yt=async()=>{var re,te,He;if(we.current)return;const b=X.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(b)){alert("Please enter a valid email address");return}T(!0),we.current=!0;try{const je=await us(b);if(je){if(je.authPolicy&&je.authPolicy!=="none"){o(je.authPolicy),T(!1),we.current=!1;return}B(((re=je.profile)==null?void 0:re.name)??""),ee(((te=je.profile)==null?void 0:te.company)??""),he(((He=je.profile)==null?void 0:He.mobile)??"")}ue(!0),K("details")}catch(je){console.error("[Meeting] Email lookup error:",je)}finally{T(!1),we.current=!1}},Ke=async()=>{if(we.current)return;const b=X.trim(),D=$.trim();if(!D){alert("Please enter your name");return}T(!0),we.current=!0;try{const te=await(await fetch("/api/auth/meeting-guest-session",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:b,name:D,meetingSlug:t,company:Z.trim()||void 0,mobile:G.trim()||void 0})})).json();if(te.success)console.log("[Meeting] Session created for guest:",b),qe.invali
20dateQueries({queryKey:["/api/auth/session"]});else if(te.requires_auth){console.log("[Meeting] Auth required:",te.message,"policy:",te.auth_policy),te.auth_policy?o(te.auth_policy):d(!0),T(!1),we.current=!1;return}else{console.warn("[Meeting] Failed to create guest session:",te.error),alert(te.error||"Failed to join meeting. Please try again."),T(!1),we.current=!1;return}localStorage.setItem("hq0_guest_info",JSON.stringify({email:b,name:D,companies:Z.trim(),mobile:G.trim()}));const He=`guest-${b}-${Date.now()}`;Be.mutate({participantName:D,participantIdentity:He,participantEmail:b,participantCompanies:Z.trim()||void 0})}catch(re){console.error("[Meeting] Error during guest join:",re),alert("Something went wrong. Please try again.")}finally{T(!1),we.current=!1}};a.useEffect(()=>{y&&y.status==="active"&&!A&&!u&&be&&!w&&!H&&!Q.current&&ms()},[y,be,A,u,w,H]),a.useEffect(()=>{s&&d(!0)},[s]);const hs=()=>{d(!1)};if(a.useEffect(()=>{if(R.current||Y||ve)return;const b=()=>{const re=ae();R.current=setTimeout(()=>{window.location.href=re},2e3)},D=()=>{R.current&&(clearTimeout(R.current),R.current=null)};if(pe||Ee&&!y)return b(),D;if(y&&y.status!=="active")return Ne||z?void 0:(b(),D)},[y,Y,pe,ve,Ee,k,z,Ne,ae]),ds)return e.jsx("div",{className:"flex items-center justify-center min-h-screen bg-background",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Ie,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground animate-pulse"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading meeting..."})]})});if(ve)return e.jsx("div",{className:"flex items-center justify-center min-h-screen bg-background",children:e.jsxs(ke,{className:"max-w-md w-full",children:[e.jsxs(Ae,{children:[e.jsx(De,{children:"Couldn't load this meeting"}),e.jsx(Ve,{children:"We hit a temporary error reaching the meeting service. Your meeting hasn't gone anywhere â try again."})]}),e.jsx(Ct,{children:e.jsx(_,{onClick:()=>Me(),className:"w-full","data-testid":"button-retry-load-meeting",children:"Retry"})})]})});if(!y)return e.jsx("div",{className:"flex items-center justify-center min-h-screen bg-background",children:e.jsx(ke,{className:"max-w-md w-full",children:e.jsxs(Ae,{children:[e.jsx(De,{children:"Meeting Not Found"}),e.jsx(Ve,{children:"Redirecting you to the homepage..."})]})})});if(y.status!=="active")return e.jsx("div",{className:"flex items-center justify-center min-h-screen bg-background",children:e.jsx(ke,{className:"max-w-md w-full",children:e.jsxs(Ae,{children:[e.jsx(De,{children:"Meeting Ended"}),e.jsx(Ve,{children:"This meeting has ended. Redirecting you to the homepage..."})]})})});const xs=!A,vt=!be&&!A&&!w,fs=be&&!A&&!vt,ps=(y==null?void 0:y.isHost)||!1;return I?e.jsx(_a,{meeting:y,organization:ie,theme:l,activeRecording:cs,onBack:()=>window.history.back()}):e.jsxs("div",{className:"relative h-screen w-full",children:[e.jsx(Ls,{organizationId:ie==null?void 0:ie.id,customDomain:k==null?void 0:k.domain}),e.jsx(qa,{meeting:y,organization:ie,theme:l,token:u,serverUrl:m,sessionStartedAt:E,customDomain:k==null?void 0:k.domain,isPreviewMode:xs,isHost:ps,onDisconnected:()=>{if(Q.current)return;Q.current=!0,F(!0),O(!1),g(""),N(""),Ye(!1);let b=window.location.origin;try{const re=["/api/custom-domains/organization",y==null?void 0:y.organizationId],te=qe.getQueryData(re);te!=null&&te.domain&&te.status==="active"&&(b=`https://${te.domain}`)}catch(re){console.log("[Leave Meeting] Redirect lookup error:",re)}const D=b.endsWith("/")?b:`${b}/`;window.location.replace(D)}}),vt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm flex items-center justify-center z-40"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-50",children:e.jsxs(ke,{className:"max-w-md w-full mx-4",children:[e.jsxs(Ae,{className:"text-center",children:[ge!=null&&ge.logoUrl&&!xe?e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("img",{src:ge.logoUrl,alt:ge.companyName||(ie==null?void 0:ie.name)||"Organization",className:"h-12 max-w-[200px] object-contain","data-testid":"img-lobby-logo",onError:()=>fe(!0)})}):e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("div",{className:"h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Ie,{className:"h-6 w-6 text-primary"})})}),(ge==null?void 0:ge.companyName)&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2","data-testid":"text-company-name",children:ge.companyName}),e.jsx(De,{"data-testid":"text-join-meeting",children:"Join Meeting"}),e.jsx(Ve,{"data-testid":"text-meeting-title",children:y.title||"Video Conference"})]}),e.jsx(Ue,{className:"space-y-4",children:U==="email"?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Oe,{htmlFor:"guest-email",children:["Email ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(Se,{id:"guest-email","data-testid":"input-guest-email",type:"email",placeholder:"[email protected]",value:X,onChange:b=>de(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),yt())},autoFocus:!0})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"guest-email",children:"Email"}),e.jsx(Se,{id:"guest-email","data-testid":"input-guest-email-locked",type:"email",value:X,disabled:J,className:"bg-muted text-muted-foreground cursor-not-allowed"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Oe,{htmlFor:"guest-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(Se,{id:"guest-name","data-testid":"input-guest-name",placeholder:"Your name",value:$,onChange:b=>B(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Ke()},autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Oe,{htmlFor:"guest-companies",children:["Company ",e.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),e.jsx(Se,{id:"guest-companies","data-testid":"input-guest-companies",placeholder:"Tesla, SpaceX",value:Z,onChange:b=>ee(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Ke()}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Oe,{htmlFor:"guest-mobile",children:["Mobile Number ",e.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),e.jsx(Se,{id:"guest-mobile","data-testid":"input-guest-mobile",type:"tel",placeholder:"+1 (555) 123-4567",value:G,onChange:b=>he(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Ke()}})]})]})}),e.jsx(Ct,{children:U==="email"?e.jsx(_,{"data-testid":"button-email-continue",onClick:yt,disabled:le,className:"w-full",children:le?"Checking...":"Continue"}):e.jsx(_,{"data-testid":"button-guest-join",onClick:Ke,disabled:le||Be.isPending,className:"w-full",children:le||Be.isPending?"Joining...":"Join Meeting"})})]})}),e.jsx(As,{open:f,onOpenChange:b=>{d(b),b||o(void 0)},onSuccess:hs,defaultEmail:X,defaultAuthPolicy:s})]}),fs&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 backdrop-blur-sm z-40",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Ie,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground animate-pulse"}),e.jsx("p",{className:"text-muted-foreground",children:"Joining meeting..."})]})})]})}export{Rn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.