var w=(i,p,d)=>new Promise((h,c)=>{var _=s=>{try{m(d.next(s))}catch(r){c(r)}},o=s=>{try{m(d.throw(s))}catch(r){c(r)}},m=s=>s.done?h(s.value):Promise.resolve(s.value).then(_,o);m((d=d.apply(i,p)).next())});import{aT as k,r as f,j as n}from"./react-vendor-xYZnmIII.js";import{u as R}from"./use-auth-l-ShkEGs.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";const W=({live_class:i,watchHistory:p,zoom_sdk_client_id:d})=>{const{props:h}=k(),{auth:c,translate:_}=h,{frontend:o}=_,{isAdmin:m}=R(),[s,r]=f.useState(!0),[x,a]=f.useState(null),[M,b]=f.useState(!1),y=f.useRef(!1),Z=m?"/dashboard/courses":`/play-course/${i.course.slug}/${p.id}/${p.current_watching_id}`,l=(()=>{if(!i.additional_info)return null;try{return typeof i.additional_info=="object"?i.additional_info:typeof i.additional_info=="string"?JSON.parse(i.additional_info):null}catch(t){return null}})(),v=()=>w(null,null,function*(){if(window.ZoomMtg)return b(!0),Promise.resolve();const t=["https://source.zoom.us/4.0.0/lib/vendor/react.min.js","https://source.zoom.us/4.0.0/lib/vendor/react-dom.min.js","https://source.zoom.us/4.0.0/lib/vendor/redux.min.js","https://source.zoom.us/4.0.0/lib/vendor/redux-thunk.min.js","https://source.zoom.us/4.0.0/zoom-meeting-4.0.0.min.js"];for(const e of t)yield new Promise((u,j)=>{const g=document.createElement("script");g.src=e,g.async=!1,g.onload=()=>{u()},g.onerror=()=>{j(new Error(`Failed to load script: ${e}`))},document.head.appendChild(g),setTimeout(()=>j(new Error(`Script load timeout: ${e}`)),1e4)});b(!0)}),z=()=>w(null,null,function*(){try{r(!0);const t=yield fetch(route("live-class.signature",i.id),{method:"GET",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}});if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const e=yield t.json();if(e.error)throw new Error(e.error);return e}catch(t){return a(t instanceof Error?t.message:o.failed_to_get_meeting_configuration),null}}),E=t=>w(null,null,function*(){try{if(!window.ZoomMtg)throw new Error(o.zoom_sdk_not_loaded);window.ZoomMtg.checkSystemRequirements();const e=document.getElementById("app")||document.body;e.innerHTML="",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.height="100vh",document.body.style.width="100vw",window.ZoomMtg.preLoadWasm(),window.ZoomMtg.prepareWebSDK(),window.ZoomMtg.i18n.load("en-US"),window.ZoomMtg.i18n.onLoad(()=>{window.ZoomMtg.init({leaveUrl:window.location.origin+Z,disableCORP:!window.crossOriginIsolated,success:()=>{N(t)},error:u=>{a(o.failed_to_initialize_meeting+": "+(u.message||u)),r(!1)}})}),S()}catch(e){a(e instanceof Error?e.message:o.failed_to_initialize_meeting),r(!1)}}),N=t=>{window.ZoomMtg.join({meetingNumber:t.meetingNumber,userName:c.user.name,signature:t.signature,userEmail:c.user.email||"",passWord:t.password,success:e=>{r(!1),window.ZoomMtg.getCurrentUser({success:u=>{}}),window.ZoomMtg.getAttendeeslist({})},error:e=>{a(o.failed_to_join_meeting+": "+(e.message||e)),r(!1)}})},S=()=>{window.ZoomMtg.inMeetingServiceListener("onUserJoin",t=>{}),window.ZoomMtg.inMeetingServiceListener("onUserLeave",t=>{}),window.ZoomMtg.inMeetingServiceListener("onUserIsInWaitingRoom",t=>{}),window.ZoomMtg.inMeetingServiceListener("onMeetingStatus",t=>{})},L=()=>{if(window.ZoomMtg)try{window.ZoomMtg.leave()}catch(t){}};return f.useEffect(()=>y.current?void 0:(y.current=!0,w(null,null,function*(){if(!d){a(o.zoom_sdk_not_configured),r(!1);return}if(!l){a(o.meeting_information_not_found),r(!1);return}try{yield v();const e=yield z();if(!e)return;yield E(e)}catch(e){a(e instanceof Error?e.message:o.failed_to_initialize_meeting),r(!1)}}),L),[]),s?n.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-900",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2 border-white"}),n.jsx("h1",{className:"text-xl font-semibold text-white",children:i.class_topic}),n.jsx("p",{className:"text-gray-300",children:M?o.joining_meeting:o.loading_zoom_sdk})]})}):x?n.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-100",children:n.jsxs("div",{className:"max-w-md rounded-lg bg-white p-8 text-center shadow-lg",children:[n.jsx("h1",{className:"mb-4 text-2xl font-bold text-red-600",children:o.unable_to_join_meeting}),n.jsx("p",{className:"text-muted-foreground mb-4",children:x}),(l==null?void 0:l.join_url)&&n.jsxs("div",{className:"mt-4",children:[n.jsx("p",{className:"mb-2 text-sm text-gray-500",children:o.you_can_join_directly}),n.jsx("a",{href:l.join_url,target:"_blank",rel:"noopener noreferrer",className:"inline-block rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700",children:o.open_in_zoom_app})]}),n.jsx("button",{onClick:()=>window.location.reload(),className:"mt-4 rounded bg-gray-600 px-4 py-2 text-white hover:bg-gray-700",children:o.try_again})]})}):null};export{W as default};
