1import{u as Z,r as i,j as e}from"./QueryClientProvider-C1unof7P.js";import{c as le,u as ce,L as Q}from"./index-BoetV10O.js";import{bl as de,bm as U,bn as me,bo as ue,bp as B,bq as pe,br as xe,bs as fe,bt as he,bu as ge,bv as je,a0 as ye}from"./api-D_7mmoRr.js";import{L as _}from"./loader-circle-0h6imjBX.js";import{B as H}from"./badge-Cd_Q2Cq_.js";import{B as j}from"./button-SBb9uHiR.js";import{C as D,a as W}from"./card-C8Jj20ZQ.js";import{P as be}from"./progress-DOy4dGDf.js";import{R as ve,a as Ne}from"./radio-group-Dku7-jfK.js";import{L as Le}from"./label-CfOBxChx.js";import{S as Se,a as we,b as Ce,c as ke,d as Ie}from"./select-CleQDElR.js";import{u as Re}from"./language-switcher-G6Qj2Bh4.js";import{C as O}from"./chevron-left-C5FwQG2p.js";import{A as Pe}from"./award-WgiOdHC9.js";import{C as T}from"./circle-check-Dk-4HkaE.js";import{C as qe}from"./circle-question-mark-9xBaHpMA.js";import{C as Me}from"./circle-play-Cl0AIvCg.js";import{F as ee}from"./file-text-CG-n5alf.js";import{L as X}from"./lock-B6s-LRZe.js";import{C as J}from"./index-GvPTnkCo.js";import{G as Ee}from"./globe-Dn4cxam-.js";import{c as ze}from"./x-DiJda-Uu.js";import{C as Y}from"./circle-x-C0UmEj6p.js";import"./index-DIvvuVIC.js";import"./HydrationBoundary-COF4dBti.js";import"./queryClient-Dr4kDVsr.js";import"./index-C2MTTiXP.js";import"./Combination-BUjfZZ_Z.js";const Ge=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]],Ae=ze("volume-2",Ge);function Fe({lessonId:o,launchUrl:f,version:d,onProgress:t}){const N=Z(),{data:l,isLoading:k}=de(o,{query:{queryKey:U(o),refetchOnWindowFocus:!1}}),$=me(),[I,R]=i.useState(!1),m=i.useRef({}),x=i.useRef(!1),h=i.useRef(null),S=i.useRef(!1),u=i.useRef(t);return u.current=t,i.useEffect(()=>{if(k||l===void 0)return;m.current=Object.fromEntries(Object.entries(l?.cmi??{}).map(([g,w])=>[g,String(w)])),S.current=l?.completed??!1;const P=()=>{x.current&&(x.current=!1,$.mutate({lessonId:o,data:{cmi:m.current}},{onSuccess:g=>{g.completed&&!S.current&&(S.current=!0,u.current(!0))}}))},c=()=>{x.current=!0,h.current&&clearTimeout(h.current),h.current=setTimeout(P,1500)},L=()=>{h.current&&clearTimeout(h.current),P()},q=g=>m.current[String(g)]??"",z=(g,w)=>(m.current[String(g)]=String(w),c(),"true"),G={LMSInitialize:()=>"true",LMSFinish:()=>(L(),"true"),LMSGetValue:q,LMSSetValue:z,LMSCommit:()=>(L(),"true"),LMSGetLastError:()=>"0",LMSGetErrorString:()=>"",LMSGetDiagnostic:()=>""},M={Initialize:()=>"true",Terminate:()=>(L(),"true"),GetValue:q,SetValue:z,Commit:()=>(L(),"true"),GetLastError:()=>"0",GetErrorString:()=>"",GetDiagnostic:()=>""};return window.API=G,window.API_1484_11=M,R(!0),()=>{L(),delete window.API,delete window.API_1484_11,N.invalidateQueries({queryKey:U(o)})}},[o,k]),k||!I?e.jsx("div",{className:"flex h-64 items-center justify-center rounded-md border",children:e.jsx(_,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("iframe",{src:f,title:"Course content",className:"h-[70vh] w-full rounded-md border bg-white","data-testid":"iframe-scorm"},o),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Interactive content (SCORM ",d??"1.2",") â your progress is saved automatically."]})]})}const Te={text:ee,video:Me,quiz:qe};function $e({url:o,title:f}){if(!/^https:\/\//i.test(o))return null;const d=/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]{6,})/.exec(o),t=/vimeo\.com\/(\d+)/.exec(o),N=d?`https://www.youtube-nocookie.com/embed/${d[1]}`:t?`https://player.vimeo.com/video/${t[1]}`:null;return N?e.jsx("div",{className:"aspect-video w-full",children:e.jsx("iframe",{src:N,className:"w-full h-full rounded border border-border",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,title:f})}):e.jsx("video",{src:o,controls:!0,className:"w-full rounded border border-border"})}
1function xt(){const{courseId:o=""}=le(),f=Number(o),{toast:d}=ce(),{t}=Re("client"),N=Z(),{data:l,isLoading:k,error:$}=ue(f,{query:{queryKey:B(f),enabled:Number.isInteger(f)&&f>0}}),I=pe(),R=xe(),[m,x]=i.useState(null),[h,S]=i.useState({}),[u,P]=i.useState(null),[c,L]=i.useState("en"),[q,z]=i.useState({}),[G,M]=i.useState(null),{data:g}=fe({query:{queryKey:he(),staleTime:1/0}}),w=ge(),V=je(),y=i.useMemo(()=>l?l.modules.flatMap(s=>s.lessons):[],[l]);i.useEffect(()=>{if(!l||m!==null)return;const s=y.find(n=>n.unlocked&&!n.completed)??y[0];s&&x(s.id)},[l,y,m]);const r=y.find(s=>s.id===m),E=y.findIndex(s=>s.id===m),C=E>0?y[E-1]:void 0,b=E>=0&&E<y.length-1?y[E+1]:void 0,te=r?`${r.id}:${c}`:"",A=c!=="en"?q[te]:void 0;i.useEffect(()=>{if(!r||r.type!=="text"||c==="en")return;const s=`${r.id}:${c}`;q[s]||w.mutate({lessonId:r.id,data:{language:c}},{onSuccess:n=>z(a=>({...a,[s]:n})),onError:n=>F(n,t("learn.translateFailed"))})},[r?.id,r?.type,c]),i.useEffect(()=>{M(null)},[m,c]);const se=()=>{r&&V.mutate({lessonId:r.id,data:{language:c}},{onSuccess:s=>{s.audioUrl?M(s.audioUrl):s.audioBase64&&M(`data:audio/mpeg;base64,${s.audioBase64}`)},onError:s=>F(s,t("learn.narrationFailed"))})},re=A?.title,ae=A?.contentHtml,K=()=>{N.invalidateQueries({queryKey:B(f)}),N.invalidateQueries({queryKey:ye()})},F=(s,n)=>{const a=s?.response?.data?.error??n;d({title:a,variant:"destructive"})},ne=s=>{I.mutate({lessonId:s.id},{onSuccess:n=>{K(),n.status==="completed"&&d({title:t("learn.courseCompleted"),description:n.certificateSerial?t("learn.certificateIssued",{serial:n.certificateSerial}):void 0})},onError:n=>F(n,t("learn.saveFailed"))})},ie=s=>{const n=s.quiz.map(a=>({questionId:a.questionId,optionId:h[a.questionId]??0}));if(n.some(a=>!a.optionId)){d({title:t("learn.answerAll"),variant:"destructive"});return}R.mutate({lessonId:s.id,data:{answers:n}},{onSuccess:a=>{P(a),K(),a.courseCompleted?d({title:t("learn.courseCompleted"),description:a.certificateSerial?t("learn.certificateIssued",{serial:a.certificateSerial}):void 0}):a.passed&&d({title:t("learn.passedWith",{score:a.scorePercent})})},onError:a=>F(a,t("learn.submitFailed"))})};if(k)return e.jsx("p",{className:"text-muted-foreground py-12 text-center",children:t("learn.loading")});if($||!l)return e.jsxs("div",{className:"text-center py-16 space-y-3","data-testid":"text-not-enrolled",children:[e.jsx("p",{className:"text-muted-foreground",children:t("learn.notEnrolled")}),e.jsx(j,{asChild:!0,variant:"outline",children:e.jsx(Q,{href:"/my-learning",children:t("courseDetail.redeemCode")})}),e.jsx(j,{asChild:!0,variant:"outline",children:e.jsx(Q,{href:"/courses",children:t("myLearning.browseCourses")})})]});const{enrolment:v}=l;return e.jsxs("div",{className:"space-y-6","data-testid":"page-learn",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(Q,{href:"/my-learning",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-primary",children:[e.jsx(O,{className:"w-4 h-4"})," ",t("nav.myLearning")]}),e.jsx("h1",{className:"text-2xl font-display font-bold mt-1",children:v.courseTitle})]}
1),v.status==="completed"&&e.jsxs(H,{className:"bg-msl-signal text-msl-ink hover:bg-msl-signal",children:[e.jsx(Pe,{className:"w-3.5 h-3.5 mr-1"})," ",t("myLearning.statusCompleted")]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(be,{value:v.progressPercent}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("myLearning.lessonsProgress",{completed:v.completedLessons,total:v.totalLessons,percent:v.progressPercent}),v.certificateSerial&&e.jsxs(e.Fragment,{children:[" · ",t("learn.certificate")," ",e.jsx("span",{className:"font-mono",children:v.certificateSerial})]})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-[300px_1fr] gap-6 items-start",children:[e.jsx(D,{className:"lg:sticky lg:top-4",children:e.jsx(W,{className:"p-4 space-y-4",children:l.modules.map((s,n)=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-display uppercase tracking-wider text-muted-foreground mb-2",children:t("courseDetail.moduleN",{number:n+1,title:s.title})}),e.jsx("ul",{className:"space-y-1",children:s.lessons.map(a=>{const p=a.completed?T:a.unlocked?Te[a.type]??ee:X;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!a.unlocked,onClick:()=>{x(a.id),S({}),P(null)},"data-testid":`button-lesson-${a.id}`,className:`w-full text-left flex items-center gap-2 rounded px-2 py-1.5 text-sm transition-colors ${a.id===m?"bg-primary/10 text-primary font-medium":a.unlocked?"hover:bg-muted text-foreground":"text-muted-foreground cursor-not-allowed"}`,children:[e.jsx(p,{className:`w-4 h-4 shrink-0 ${a.completed?"text-msl-signal":""}`}),e.jsx("span",{className:"truncate",children:a.title})]})},a.id)})})]},s.id))})}),e.jsx(D,{children:e.jsx(W,{className:"p-6 space-y-6",children:r?r.unlocked?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("h2",{className:"text-xl font-display font-bold","data-testid":"text-lesson-title",children:re??r.title}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.completed&&e.jsxs(H,{variant:"secondary",className:"shrink-0",children:[e.jsx(T,{className:"w-3.5 h-3.5 mr-1"})," ",t("learn.done")]}),e.jsxs(j,{variant:"outline",size:"sm",disabled:!C,onClick:()=>C&&x(C.id),"data-testid":"button-prev-lesson-top",children:[e.jsx(O,{className:"w-4 h-4 mr-1"})," ",t("learn.back")]}),e.jsxs(j,{variant:"outline",size:"sm",disabled:!b||!b.unlocked,onClick:()=>b&&x(b.id),"data-testid":"button-next-lesson-top",children:[t("learn.next")," ",e.jsx(J,{className:"w-4 h-4 ml-1"})]})]})]}),r.type==="text"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ee,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs(Se,{value:c,onValueChange:L,children:[e.jsx(we,{className:"w-[190px] h-8 text-sm","data-testid":"select-lesson-language",children:e.jsx(Ce,{placeholder:t("learn.language")})}),e.jsx(ke,{children:(g?.languages??[{code:"en",label:t("learn.englishOriginal")}]).map(s=>e.jsx(Ie,{value:s.code,children:s.label},s.code))})]}),e.jsx(j,{variant:"outline",size:"sm",onClick:se,disabled:V.isPending||c!=="en"&&!A,"data-testid":"button-listen-lesson",children:V.isPending?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"w-4 h-4 mr-1.5 animate-spin"})," ",t("learn.preparingAudio")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-4 h-4 mr-1.5"})," ",t("learn.listen")]})}),w.isPending&&c!=="en"&&!A&&e.jsxs("span",{className:"text-xs text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(_,{className:"w-3.5 h-3.5 animate-spin"})," ",t("learn.translating")]})]}),G&&e.jsx("audio",{src:G,controls:!0,autoPlay:!0,className:"w-full","data-testid":"audio-lesson-narration"}),r.type==="video"&&r.videoUrl&&e.jsx($e,{url:r.videoUrl,title:t("learn.lessonVideo")}),r.type==="scorm"&&r.scormLaunchUrl&&e.jsx(Fe,{lessonId:r.id,launchUrl:r.scormLaunchUrl,version:r.scormVersion,onProgress:s=>{s&&(d({title:t("learn.lessonCompleted")}),K())}}),r.contentHtml&&e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",dangerouslySetInnerHTML:{__html:ae??r.contentHtml}}),r.type!=="quiz"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.type!=="scorm"&&!r.completed&&e.jsx(j,{onClick:()=>ne(r),disabled:I.isPending,"data-testid":"button-complete-lesson",children:I.isPending?t("learn.saving"):t("learn.markComplete")}
1),e.jsxs(j,{variant:"outline",disabled:!C,onClick:()=>C&&x(C.id),"data-testid":"button-prev-lesson-bottom",children:[e.jsx(O,{className:"w-4 h-4 mr-1"})," ",t("learn.back")]}),e.jsxs(j,{variant:"outline",disabled:!b||!b.unlocked,onClick:()=>b&&x(b.id),"data-testid":"button-next-lesson-bottom",children:[t("learn.next")," ",e.jsx(J,{className:"w-4 h-4 ml-1"})]})]}),r.type==="quiz"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm text-muted-foreground",children:[e.jsx("span",{children:t("courseDetail.passmark",{percent:l.passmark})}),e.jsxs("span",{children:["· ",t("learn.attemptsRemaining",{count:r.attemptsRemaining})]}),r.bestScorePercent!==null&&e.jsxs("span",{children:["· ",t("learn.bestScore",{percent:r.bestScorePercent})]})]}),r.passed?e.jsxs("p",{className:"flex items-center gap-2 text-msl-signal font-medium",children:[e.jsx(T,{className:"w-5 h-5"})," ",t("learn.quizPassed")]}):r.attemptsRemaining===0?e.jsxs("p",{className:"flex items-center gap-2 text-destructive font-medium","data-testid":"text-no-attempts",children:[e.jsx(Y,{className:"w-5 h-5"})," ",t("learn.noAttempts")]}):e.jsxs(e.Fragment,{children:[r.quiz.map((s,n)=>{const a=u?.feedback.find(p=>p.questionId===s.questionId);return e.jsxs("div",{className:"space-y-3","data-testid":`quiz-question-${s.questionId}`,children:[e.jsxs("p",{className:"font-medium flex items-start gap-2",children:[e.jsxs("span",{children:[n+1,". ",s.prompt]}),a&&(a.correct?e.jsx(T,{className:"w-4 h-4 text-msl-signal shrink-0 mt-1"}):e.jsx(Y,{className:"w-4 h-4 text-destructive shrink-0 mt-1"}))]}),e.jsx(ve,{value:h[s.questionId]?String(h[s.questionId]):"",onValueChange:p=>S(oe=>({...oe,[s.questionId]:Number(p)})),children:s.options.map(p=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ne,{value:String(p.optionId),id:`opt-${p.optionId}`}),e.jsx(Le,{htmlFor:`opt-${p.optionId}`,className:"font-normal cursor-pointer",children:p.label})]},p.optionId))})]},s.questionId)}),u&&!u.passed&&e.jsxs("p",{className:"text-sm text-destructive",children:[t("learn.quizFailedScore",{score:u.scorePercent,passmark:u.passmark}),u.attemptsRemaining>0?` ${u.attemptsRemaining===1?t("learn.attemptsLeftOne"):t("learn.attemptsLeftOther",{count:u.attemptsRemaining})}`:""]}),e.jsx(j,{onClick:()=>ie(r),disabled:R.isPending,"data-testid":"button-submit-quiz",children:R.isPending?t("learn.grading"):t("learn.submitAnswers")})]})]})]}):e.jsxs("p",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(X,{className:"w-4 h-4"})," ",t("learn.locked")]}):e.jsx("p",{className:"text-muted-foreground",children:t("learn.selectLesson")})})})]})]})}export{xt 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.