1import{r as u,j as e}from"./vendor-react-DJzUMfd1.js";import{c as $,n as q,D as X,p as i,m as Y,T as c,e as Z,C as O,f as R,B as G,Q as ee,R as re,u as te,V as ne,x as ae,r as M,q as z}from"./index-C0esqoXR.js";import{c as oe,f as se,u as V,s as N,a as ie,b as ce,d as le,e as de}from"./assignmentService-tzBLKRhC.js";import{g as H}from"./gameTypes-f5wEe58l.js";import{s as xe}from"./soundEffects-BNObq7V4.js";import{E as fe}from"./EmojiEvents-C3dbMUOl.js";import{L as he}from"./LinearProgress-CFq27fme.js";import{D as pe}from"./Divider-DGtAGn-z.js";import{T as ue}from"./Timer-4ebcaaX7.js";import{C as U}from"./Container-BqzqHWDq.js";import{A as J}from"./ArrowBack-DnBkz0iJ.js";import"./vendor-3d-B-0V4uEN.js";import"./vendor-firebase-NOrVjYbK.js";import"./vendor-katex-DqEyuLHo.js";import"./joinCodeService-Duqlw8dB.js";import"./useShuffleQuestions-CMMUsmAD.js";import"./FormControlLabel-UfST9rc_.js";import"./Checkbox-hNFsBxwF.js";import"./Cancel-HgNyvqSD.js";import"./HelpOutline-BjEUExVZ.js";import"./useThemeProps-Cu1lPegC.js";function ye({open:r,onClose:x,studentName:B,score:g,maxScore:f,duration:T,gameType:v,gameResult:l,submitting:w}){var A,W,m,p,d,n,t;const{t:o}=$("assignment"),k=q(),h=(s,j)=>{const S=s/j*100;return S>=90?{label:o("result.excellent"),color:"#4caf50",emoji:"ð"}:S>=80?{label:o("result.good"),color:"#8bc34a",emoji:"ð"}:S>=70?{label:o("result.fair"),color:"#ffeb3b",emoji:"ð"}:S>=50?{label:o("result.passed"),color:"#ff9800",emoji:"â
"}:{label:o("result.tryHarder"),color:"#f44336",emoji:"ðª"}},_=s=>{if(s<60)return o("result.duration.seconds",{count:s});const j=Math.floor(s/60),S=s%60;return S===0?o("result.duration.minutes",{count:j}):o("result.duration.mins_secs",{mins:j,secs:S})},I=v==="tug_of_war",a=I?l:null,D=a==null?void 0:a.winner,y=I?D==="draw"?{label:o("result.draw"),color:"#ff9800",emoji:"ð¤"}:{label:o("result.winner",{name:D==="team1"?(A=a==null?void 0:a.team1)==null?void 0:A.name:(W=a==null?void 0:a.team2)==null?void 0:W.name}),color:"#4caf50",emoji:"ð"}:null,b=v==="turn_based_game",C=b?{label:o("result.winner",{name:(l==null?void 0:l.winnerName)||"Player"}),color:"#4caf50",emoji:"ð"}:null,E=f>0?Math.round(g/f*100):0,P=I?y:b?C:h(g,f);u.useEffect(()=>{r&&xe.playCongratulations()},[r]);const F=()=>{k("/join")};return e.jsxs(X,{open:r,onClose:w?void 0:x,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:3,overflow:"hidden"}},children:[e.jsxs(i,{sx:{background:`linear-gradient(135deg, ${P.color} 0%, ${P.color}dd 100%)`,color:"white",py:4,textAlign:"center"},children:[e.jsx(Y.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",duration:.5},children:e.jsx(c,{variant:"h1",sx:{fontSize:"4rem",mb:1},children:P.emoji})}),e.jsx(c,{variant:"h4",fontWeight:"bold",children:P.label}),e.jsx(c,{variant:"body1",sx:{opacity:.9,mt:1},children:B})]}),e.jsxs(Z,{sx:{py:4},children:[e.jsx(i,{sx:{textAlign:"center",mb:4},children:I?e.jsx(i,{children:e.jsxs(i,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:2,mb:1},children:[e.jsxs(i,{sx:{textAlign:"center"},children:[e.jsxs(c,{variant:"body2",sx:{color:"#2563eb",fontWeight:"bold"},children:["ðµ ",(m=a==null?void 0:a.team1)==null?void 0:m.name]}),e.jsx(c,{variant:"h3",fontWeight:"bold",sx:{color:"#2563eb"},children:((p=a==null?void 0:a.team1)==null?void 0:p.score)??0})]}),e.jsx(c,{variant:"h4",color:"text.secondary",children:"â"}),e.jsxs(i,{sx:{textAlign:"center"},children:[e.jsxs(c,{variant:"body2",sx:{color:"#dc2626",fontWeight:"bold"},children:["ð´ ",(d=a==null?void 0:a.team2)==null?void 0:d.name]}),e.jsx(c,{variant:"h3",fontWeight:"bold",sx:{color:"#dc2626"},children:((n=a==null?void 0:a.team2)==null?void 0:n.score)??0})]})]})}):b?e.jsxs(i,{children:[e.jsxs(c,{variant:"h5",fontWeight:"bold",sx:{color:"#11998e",mb:2},children:["ð ",l==null?void 0:l.winnerName]}),e.jsx(i,{sx:{display:"flex",flexWrap:"wrap",gap:1,justifyContent:"center"},children:(t=l==null?void 0:l.players)==null?void 0:t.map((s,j)=>e.jsxs(i,{sx:{px:2,py:.75,borderRadius:2,bgcolor:j===(l==null?void 0:l.winnerIdx)?"#e8f5e9":"#f5f5f5",border:j===(l==null?void 0:l.winnerId
1x)?"2px solid #4caf50":"1px solid #e0e0e0",fontWeight:j===(l==null?void 0:l.winnerIdx)?"bold":"normal",fontSize:"0.9rem"},children:[j===(l==null?void 0:l.winnerIdx)?"ð ":"",s.name]},j))})]}):e.jsxs(e.Fragment,{children:[e.jsxs(i,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1,mb:2},children:[e.jsx(fe,{sx:{color:"#ffc107",fontSize:32}}),e.jsxs(c,{variant:"h3",fontWeight:"bold",children:[g," / ",f]})]}),e.jsxs(i,{sx:{px:4},children:[e.jsx(he,{variant:"determinate",value:E,sx:{height:12,borderRadius:6,bgcolor:"#e0e0e0","& .MuiLinearProgress-bar":{bgcolor:P.color,borderRadius:6}}}),e.jsx(c,{variant:"body2",color:"text.secondary",sx:{mt:1},children:o("result.percentageComplete",{percentage:E})})]})]})}),e.jsx(pe,{sx:{my:3}}),e.jsxs(i,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[e.jsx(ue,{color:"action"}),e.jsx(c,{variant:"body1",color:"text.secondary",children:e.jsx("span",{dangerouslySetInnerHTML:{__html:o("result.timeTaken",{duration:_(T)})}})})]}),w&&e.jsxs(i,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1,mt:3},children:[e.jsx(O,{size:20}),e.jsx(c,{variant:"body2",color:"text.secondary",children:o("result.saving")})]})]}),e.jsx(R,{sx:{p:3,pt:0,justifyContent:"center"},children:e.jsx(G,{variant:"contained",startIcon:e.jsx(ee,{}),onClick:F,disabled:w,sx:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)","&:hover":{background:"linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%)"}},children:o("result.goHome")})})]})}function K({assignment:r,studentName:x,onBack:B,onComplete:g}){const{t:f}=$("assignment"),{toast:T}=re(),[v]=u.useState(()=>(le(),Date.now())),[l,w]=u.useState(!1),[o,k]=u.useState(null),[h,_]=u.useState(!1),I=u.useRef(null),a=u.useRef(null),D=u.useRef(!1),y=H(r.gameType),b=u.useCallback(async p=>{if(I.current)return I.current;if(a.current){const n=await a.current;if(n)return n}const d=oe({assignmentId:r.id,studentName:x,...p}).then(n=>(I.current=n,a.current=null,n)).catch(n=>{throw a.current=null,n});return a.current=d,await d},[r.id,x]);u.useEffect(()=>{if(r.gameType!=="interactive_video")return;const p=se(r.id).then(d=>d?(I.current=d,a.current=null,d):(a.current=null,null)).catch(d=>(console.error(d),a.current=null,null));a.current=p},[]);const C=u.useCallback(async p=>{var j;if(D.current)return;D.current=!0;const d=Math.floor((Date.now()-v)/1e3),{score:n,maxScore:t}=y.getScoreFromResult(p),s={score:n,maxScore:t,duration:d,gameResult:p};k(s),w(!0),_(!0);try{const S=y.submissionStrategy||"default",Q=((j=r.gameSnapshot)==null?void 0:j.allowRetry)===!0;if(S==="video"){const L=await b({score:n,maxScore:t,gameData:p,duration:d});await V(L,{score:n,maxScore:t,gameData:p,duration:d}),T.success(f("player.scoreUpdated")),g==null||g(s)}else if(S==="upsert"||Q)await(r.gameType==="knowledge_train"?N:ie)({assignmentId:r.id,studentName:x,score:n,maxScore:t,gameData:p,duration:d}),T.success(f("player.scoreUpdated")),g==null||g(s);else{const L=y.getEffectiveStudentName?y.getEffectiveStudentName(x,p):x==="_no_name_"?"":x;await ce({assignmentId:r.id,studentName:L,score:n,maxScore:t,gameData:p,duration:d}),T.success(f("player.resultSaved")),g==null||g(s)}}catch(S){console.error("Error submitting result:",S),T.error(f("player.saveFailed"))}finally{_(!1)}},[r.id,r.gameType,r.gameSnapshot,r.expiresAt,x,v,y,T,g,b]),E=u.useCallback(async p=>{if(r.gameType!=="interactive_video")return;const{score:d,maxScore:n}
1=y.getScoreFromResult(p),t=Math.floor((Date.now()-v)/1e3);try{const s=await b({score:d,maxScore:n,gameData:p.gameData??p,duration:t});await V(s,{score:d,maxScore:n,gameData:p.gameData??p,duration:t})}catch(s){console.error("Error saving progress:",s)}},[r.id,r.gameType,x,v,y,b]),P=u.useCallback(async p=>{const{score:d,maxScore:n}=y.getScoreFromResult(p),t=Math.floor((Date.now()-v)/1e3);try{await N({assignmentId:r.id,studentName:x,score:d,maxScore:n,gameData:p,duration:t})}catch(s){console.error("Error saving progress:",s)}},[r.id,x,v,y]),F={onBack:B,onComplete:C,onProgressSave:r.gameType==="interactive_video"?E:r.gameType==="knowledge_train"?P:void 0,toast:T},A=y==null?void 0:y.mapSnapshotToProps(r.gameSnapshot,F),W=()=>e.jsxs(i,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",gap:2},children:[e.jsx(O,{size:60}),e.jsx(c,{variant:"h6",color:"text.secondary",children:f("player.loading")})]});if(!y)return e.jsx(i,{sx:{p:4,textAlign:"center"},children:e.jsx(c,{variant:"h6",color:"error",children:f("player.unsupported",{type:r.gameType})})});const m=y.getPlayerComponent?y.getPlayerComponent(r.gameSnapshot):y.PlayerComponent;return m?e.jsxs(e.Fragment,{children:[e.jsx(u.Suspense,{fallback:e.jsx(W,{}),children:e.jsx(m,{...A})}),e.jsx(ye,{open:l&&!y.hideResultModal,onClose:()=>{w(!1)},studentName:x==="_no_name_"?"":x,score:(o==null?void 0:o.score)||0,maxScore:(o==null?void 0:o.maxScore)||10,duration:(o==null?void 0:o.duration)||0,gameType:r.gameType,gameResult:o==null?void 0:o.gameResult,submitting:h})]}):e.jsxs(i,{sx:{p:4,textAlign:"center"},children:[e.jsx(c,{variant:"h6",color:"warning.main",children:f("player.notIntegrated",{label:f(`gameTypes.${r.gameType}.label`,{defaultValue:y.label})})}),e.jsx(c,{variant:"body2",color:"text.secondary",sx:{mt:1},children:f("player.tryAnother")})]})}function Me(){var d;const{t:r}=$("assignment"),{assignmentId:x}=te(),B=ne(),g=q(),f=(d=B.state)==null?void 0:d.studentName,[T]=ae(),v=T.get("code"),[l,w]=u.useState(!0),[o,k]=u.useState(""),[h,_]=u.useState(null),[I,a]=u.useState(!1),[D,y]=u.useState(!1),[b,C]=u.useState(null),E=n=>`played_assignment_${n}`,P=n=>{try{const t=localStorage.getItem(E(n));if(t)return JSON.parse(t)}catch(t){console.error("Error reading localStorage:",t)}return null},F=(n,t)=>{try{localStorage.setItem(E(n),JSON.stringify({playedAt:new Date().toISOString(),studentName:f,score:t==null?void 0:t.score,maxScore:t==null?void 0:t.maxScore}))}catch(s){console.error("Error writing localStorage:",s)}};u.useEffect(()=>{f||(v?g(`/join?code=${v}`,{replace:!0}):g("/join",{replace:!0}))},[f,g,v]),u.useEffect(()=>{var n;if(x&&h){const t=((n=h.gameSnapshot)==null?void 0:n.allowRetry)===!0,s=H(h.gameType);if(s!=null&&s.allowUnlimitedRetry||t){const j=P(x);j&&C(j)}else{const j=P(x);j&&(y(!0),C(j))}}},[x,h]),u.useEffect(()=>{async function n(){if(!x){k(r("player.invalidId")),w(!1);return}try{const t=await de(x);if(!t){k(r("player.notFound")),w(!1);return}const s=H(t.gameType);if(!s){k(r("player.unsupportedType",{type:t.gameType})),w(!1);return}if(s.redirectRoute){g(s.redirectRoute(x),{replace:!0,state:{studentName:f,assignment:t}});return}_(t)}catch(t){console.error("Error loading assignment:",t),k(r("player.loadError"))}finally{w(!1)}}f&&n()},[x,f]);const A=()=>{g("/join")},W=n=>{var t;a(!0),(t=H(h==null?void 0:h.gameType))!=null&&t.skipLocalStorageMark||F(x,n)};if(l)return e.jsx(i,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"},children:e.jsxs(M,{sx:{p:4,textAlign:"center",borderRadius:3},children:[e.jsx(O,{size:60,sx:{mb:2}}),e.jsx(c,{variant:"h6",children:r("player.loadingTitle")})]})});if(o)return e.jsx(i,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",p:2},children:e.jsx(U,{maxWidth:"sm",children:e.jsxs(M,{sx:{p:4,textAlign:"center",borderRadius:3},children:[e.jsx(z,{severity:"error",sx:{mb:3},children:o}),e.jsx(G,{variant:"contained",startIcon:e.jsx(J,{}),onClick:A,children:r("player.goBack")})]})})});
1if(D&&b){const t=new Date(b.playedAt).toLocaleString("vi-VN",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"});return e.jsx(i,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",p:2},children:e.jsx(U,{maxWidth:"sm",children:e.jsxs(M,{sx:{p:4,textAlign:"center",borderRadius:3},children:[e.jsx(i,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:"#ff9800",display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:2,fontSize:"2.5rem"},children:"â ï¸"}),e.jsx(c,{variant:"h5",fontWeight:"bold",gutterBottom:!0,children:r("player.alreadyPlayedTitle")}),e.jsx(c,{variant:"body1",color:"text.secondary",sx:{mb:3},children:r("player.onceOnly")}),e.jsxs(i,{sx:{p:2,mb:3,bgcolor:"#f5f5f5",borderRadius:2},children:[e.jsx(c,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:r("player.previousResult")}),b.score!==void 0&&e.jsxs(c,{variant:"h4",fontWeight:"bold",color:"primary",children:[b.score,"/",b.maxScore||100]}),e.jsxs(c,{variant:"caption",color:"text.secondary",children:[r("player.playedAtLabel")," ",t]}),b.studentName&&e.jsxs(c,{variant:"body2",sx:{mt:1},children:[r("player.nameLabel")," ",e.jsx("strong",{children:b.studentName})]})]}),e.jsx(z,{severity:"info",sx:{mb:3,textAlign:"left"},children:r("player.contactTeacher")}),e.jsx(G,{variant:"contained",startIcon:e.jsx(J,{}),onClick:A,sx:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"},children:r("player.goBack")})]})})})}const m=H(h==null?void 0:h.gameType);return(m==null?void 0:m.fullscreen)===!0?e.jsx(i,{sx:{width:"100vw",height:"100vh",overflow:"hidden",bgcolor:"#f5f5f5"},children:h&&e.jsx(K,{assignment:h,studentName:f,onBack:A,onComplete:W})}):e.jsxs(i,{sx:{minHeight:"100vh",bgcolor:"#f5f5f5"},children:[e.jsxs(M,{elevation:2,sx:{py:1.5,px:3,display:"flex",alignItems:"center",justifyContent:"space-between",borderRadius:0},children:[e.jsx(i,{sx:{display:"flex",alignItems:"center",gap:2},children:e.jsxs(i,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(i,{sx:{width:32,height:32,borderRadius:1,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:`${m==null?void 0:m.color}20`,fontSize:"1.2rem"},children:(m==null?void 0:m.icon)||"ð®"}),e.jsx(c,{variant:"subtitle1",fontWeight:"bold",noWrap:!0,children:(h==null?void 0:h.title)||r("player.defaultTitle")})]})}),e.jsxs(i,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(c,{variant:"body2",color:"text.secondary",children:r("player.studentPrefix")}),e.jsx(c,{variant:"body2",fontWeight:"bold",children:f})]})]}),(m==null?void 0:m.instruction)&&e.jsx(z,{severity:"info",icon:e.jsx("span",{style:{fontSize:"1.5rem"},children:m.icon}),sx:{mx:2,mt:2,borderRadius:2,bgcolor:`${m.color}15`,border:`2px solid ${m.color}40`,"& .MuiAlert-message":{fontSize:"0.95rem",lineHeight:1.6}},children:e.jsx(c,{variant:"body2",sx:{fontWeight:500},children:r(`gameTypes.${h==null?void 0:h.gameType}.instruction`,{defaultValue:m.instruction})})}),e.jsx(i,{sx:{py:2},children:h&&e.jsx(K,{assignment:h,studentName:f,onBack:A,onComplete:W})})]})}export{Me 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.