1"use strict";(self.webpackChunkschool_crm_desktop=self.webpackChunkschool_crm_desktop||[]).push([[943],{1087(e,t,s){s.d(t,{A:()=>u});var n=s(5043),r=s(3862),a=s(1238),l=s(579);const o=["LISTENING","READING","WRITING","SPEAKING"],i={LISTENING:{emoji:"\ud83c\udfa7",label:"Listening",color:"#3b82f6",bg:"#eff6ff",border:"#bfdbfe"},READING:{emoji:"\ud83d\udcd6",label:"Reading",color:"#8b5cf6",bg:"#f5f3ff",border:"#ddd6fe"},WRITING:{emoji:"\u270d\ufe0f",label:"Writing",color:"#059669",bg:"#ecfdf5",border:"#a7f3d0"},SPEAKING:{emoji:"\ud83d\udde3\ufe0f",label:"Speaking",color:"#d97706",bg:"#fffbeb",border:"#fde68a"}};function d(e){return null==e?"#d1d5db":e>=7?"#16a34a":e>=5.5?"#d97706":e>=4?"#ea580c":"#dc2626"}function c(e){let{t:t}=e;return"up"===t?(0,l.jsx)("span",{style:{color:"#16a34a",fontWeight:700,fontSize:"1rem"},children:"\u2191"}):"down"===t?(0,l.jsx)("span",{style:{color:"#dc2626",fontWeight:700,fontSize:"1rem"},children:"\u2193"}):(0,l.jsx)("span",{style:{color:"#9ca3af",fontSize:"0.9rem"},children:"\u2192"})}function x(e){let{band:t}=e;return null==t?(0,l.jsx)("span",{style:{color:"#d1d5db",fontSize:"0.75rem"},children:"\u2014"}):(0,l.jsx)("span",{style:{fontWeight:700,fontSize:"0.9rem",color:d(t)},children:t})}function u(e){let{groupId:t,month:s,readOnly:u}=e;const[m,p]=(0,n.useState)(null),[h,g]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{t&&s?(g(!0),(0,r.n)("/grades/matrix?groupId=".concat(t,"&month=").concat(s)).then(e=>e.json()).then(e=>{e.success&&p(e.data)}).finally(()=>g(!1))):p(null)},[t,s]),!t)return null;if(h)return(0,l.jsx)("p",{className:"text-center text-gray-400 py-10",children:"Loading matrix\u2026"});if(!m||!m.students.length)return(0,l.jsx)("p",{className:"text-center text-gray-400 py-10",children:"No grade data for this period."});const{students:f,skills:b}=m,y=o.map(e=>{var t;return{skill:e,sessions:(null===(t=b[e])||void 0===t?void 0:t.sessions)||[]}}).filter(e=>e.sessions.length>0);if(!y.length)return(0,l.jsx)("p",{className:"text-center text-gray-400 py-10",children:"No sessions recorded this month."});return(0,l.jsxs)("div",{children:[!u&&(0,l.jsx)("div",{className:"flex justify-end mb-3",children:(0,l.jsx)("button",{onClick:()=>{const e=a.Wp.book_new(),t=["Student"],n=[""],r=[{wch:26}];for(const{skill:s,sessions:a}of y){const{emoji:e,label:l}=i[s];t.push("".concat(e," ").concat(l));for(let s=1;s<a.length+2;s++)t.push("");a.forEach(e=>{n.push(e.date.slice(5).replace("-","/")),r.push({wch:7})}),n.push("Avg"),r.push({wch:6}),n.push("Trend"),r.push({wch:7})}t.push("Overall"),n.push("Avg"),r.push({wch:8});const l=[t,n];for(const s of f){const e=[s.name];for(const{skill:n,sessions:r}of y){var o;const t=null===(o=b[n])||void 0===o?void 0:o.data[s.id];r.forEach((s,n)=>e.push(null!=(null===t||void 0===t?void 0:t.bands[n])?t.bands[n]:"\u2014")),e.push(null!=(null===t||void 0===t?void 0:t.avg)?t.avg:"\u2014"),e.push("up"===(null===t||void 0===t?void 0:t.trend)?"\u2191":"down"===(null===t||void 0===t?void 0:t.trend)?"\u2193":"\u2192")}const t=y.map(e=>{var t,n;let{skill:r}=e;return null===(t=b[r])||void 0===t||null===(n=t.data[s.id])||void 0===n?void 0:n.avg}).filter(e=>null!=e);e.push(t.length?Math.round(t.reduce((e,t)=>e+t,0)/t.length*10)/10:"\u2014"),l.push(e)}const d=["Class Average"];for(const{skill:s,sessions:a}of y){const e=b[s];a.forEach((t,s)=>{const n=f.map(t=>{var n;return null===e||void 0===e||null===(n=e.data[t.id])||void 0===n?void 0:n.bands[s]}).filter(e=>null!=e);d.push(n.length?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(1):"\u2014")});const t=f.map(t=>{var s;return null===e||void 0===e||null===(s=e.data[t.id])||void 0===s?void 0:s.avg}).filter(e=>null!=e);d.push(t.length?(t.reduce((e,t)=>e+t,0)/t.length).toFixed(1):"\u2014"),d.push("")}const c=f.map(e=>{const t=y.map(t=>{var s,n;let{skill:r}=t;return null===(s=b[r])||void 0===s||null===(n=s.data[e.id])||void 0===n?void 0:n.avg}).filter(e=>null!=e);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}).filter(e=>null!=e);d.push(c.length?(c.reduce((e,t)=>e+t,0)/c.length).toFixed(1):"\u2014"),l.push(d);const x=a.Wp.aoa_to_sheet(l);x["!cols"]=r;
1const u=[];let m=1;for(const{sessions:s}of y)u.push({s:{r:0,c:m},e:{r:0,c:m+s.length+1}}),m+=s.length+2;x["!merges"]=u,a.Wp.book_append_sheet(e,x,"Grade Matrix ".concat(s).slice(0,31)),a._h(e,"grade_matrix_".concat(s,".xlsx"))},className:"bg-green-600 hover:bg-green-700 text-white px-3 py-1.5 rounded-lg text-sm font-medium",children:"\ud83d\udce5 Export Excel"})}),(0,l.jsx)("div",{className:"overflow-x-auto rounded-lg border border-gray-200 shadow-sm",children:(0,l.jsxs)("table",{className:"text-sm border-collapse",style:{minWidth:"100%"},children:[(0,l.jsxs)("thead",{children:[(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{rowSpan:2,className:"px-4 py-2 text-left text-xs font-semibold text-gray-500 uppercase border border-gray-200 bg-gray-50",style:{position:"sticky",left:0,zIndex:2,minWidth:150},children:"Student"}),y.map(e=>{let{skill:t,sessions:s}=e;const{emoji:n,label:r,color:a,bg:o,border:d}=i[t];return(0,l.jsxs)("th",{colSpan:s.length+2,className:"px-2 py-1.5 text-center text-xs font-bold uppercase tracking-wide border border-gray-200",style:{backgroundColor:o,color:a,borderColor:d},children:[n," ",r]},t)}),(0,l.jsx)("th",{rowSpan:2,className:"px-2 py-1.5 text-center text-xs font-bold uppercase tracking-wide border border-gray-200",style:{backgroundColor:"#1e293b",color:"#f8fafc",minWidth:60},children:"Overall"})]}),(0,l.jsx)("tr",{className:"bg-gray-50 text-xs text-gray-400",children:y.flatMap(e=>{let{skill:t,sessions:s}=e;return[...s.map(e=>(0,l.jsx)("th",{className:"px-1.5 py-1 text-center border border-gray-200 font-medium whitespace-nowrap",style:{minWidth:44},children:e.date.slice(5).replace("-","/")},e.id)),(0,l.jsx)("th",{className:"px-1.5 py-1 text-center border border-gray-200 font-semibold text-gray-500 bg-gray-100",style:{minWidth:44},children:"Avg"},"".concat(t,"-avg")),(0,l.jsx)("th",{className:"px-1.5 py-1 text-center border border-gray-200 font-semibold text-gray-500 bg-gray-100",style:{minWidth:46},children:"Trend"},"".concat(t,"-trend"))]})})]}),(0,l.jsxs)("tbody",{children:[f.map((e,t)=>(0,l.jsxs)("tr",{style:{backgroundColor:t%2===0?"#ffffff":"#f9fafb"},className:"hover:bg-blue-50/30",children:[(0,l.jsx)("td",{className:"px-4 py-2 font-medium text-gray-800 border border-gray-100 text-sm",style:{position:"sticky",left:0,zIndex:1,backgroundColor:t%2===0?"#ffffff":"#f9fafb"},children:e.name}),y.flatMap(t=>{var s;let{skill:n,sessions:r}=t;const a=null===(s=b[n])||void 0===s?void 0:s.data[e.id];return[...r.map((e,t)=>(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-100",children:(0,l.jsx)(x,{band:null===a||void 0===a?void 0:a.bands[t]})},e.id)),(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-100 bg-gray-50",children:(0,l.jsx)(x,{band:null===a||void 0===a?void 0:a.avg})},"".concat(n,"-avg")),(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-100 bg-gray-50",children:(0,l.jsx)(c,{t:null===a||void 0===a?void 0:a.trend})},"".concat(n,"-trend"))]}),(()=>{const t=y.map(t=>{var s,n;let{skill:r}=t;return null===(s=b[r])||void 0===s||null===(n=s.data[e.id])||void 0===n?void 0:n.avg}).filter(e=>null!=e),s=t.length?Math.round(t.reduce((e,t)=>e+t,0)/t.length*10)/10:null;return(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-200",style:{backgroundColor:"#1e293b"},children:null!=s?(0,l.jsx)("span",{style:{fontWeight:800,fontSize:"0.95rem",color:d(s)},children:s}):(0,l.jsx)("span",{style:{color:"#64748b",fontSize:"0.75rem"},children:"\u2014"})})})()]},e.id)),f.length>1&&(0,l.jsxs)("tr",{style:{backgroundColor:"#eff6ff",fontWeight:600},children:[(0,l.jsx)("td",{className:"px-4 py-2 text-sm font-bold text-blue-700 border border-gray-200",style:{position:"sticky",left:0,zIndex:1,backgroundColor:"#eff6ff"},children:"Class Average"}),y.flatMap(e=>{let{skill:t,sessions:s}=e;const n=b[t];return[...s.map((e,s)=>{const r=f.map(e=>{var t;return null===n||void 0===n||null===(t=n.data[e.id])||void 0===t?void 0:t.bands[s]}).filter(e=>null!=e),a=r.length?r.reduce((e,t)=>e+t,0)/r.length:null;return(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-200",children:(0,l.jsx)(x,{band:null!=a?Math.round(10*a)/10:null})},"".concat(t,"-").concat(s,"-cavg"))}),(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-200",style:{backgroundColor:"#dbeafe"},children:(()=>{const e=f.map(e=>{var t;return null===n||void 0===n||null===(t=n.data[e.id])||void 0===t?void 0:t.avg}).filter(e=>null!=e),t=e.length?e.reduce((e,t)=>
1e+t,0)/e.length:null;return(0,l.jsx)(x,{band:null!=t?Math.round(10*t)/10:null})})()},"".concat(t,"-avg-cavg")),(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-200",style:{backgroundColor:"#dbeafe"},children:(0,l.jsx)("span",{className:"text-gray-400 text-xs",children:"\u2014"})},"".concat(t,"-trend-cavg"))]}),(()=>{const e=f.map(e=>{const t=y.map(t=>{var s,n;let{skill:r}=t;return null===(s=b[r])||void 0===s||null===(n=s.data[e.id])||void 0===n?void 0:n.avg}).filter(e=>null!=e);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}).filter(e=>null!=e),t=e.length?Math.round(e.reduce((e,t)=>e+t,0)/e.length*10)/10:null;return(0,l.jsx)("td",{className:"px-1 py-2 text-center border border-gray-200",style:{backgroundColor:"#0f172a"},children:null!=t?(0,l.jsx)("span",{style:{fontWeight:800,fontSize:"0.95rem",color:d(t)},children:t}):(0,l.jsx)("span",{style:{color:"#64748b",fontSize:"0.75rem"},children:"\u2014"})})})()]})]})]})}),(0,l.jsx)("div",{className:"mt-4 grid grid-cols-2 md:grid-cols-4 gap-3",children:y.map(e=>{let{skill:t,sessions:s}=e;const n=b[t],{emoji:r,label:a,color:o,bg:d,border:c}=i[t],x=f.map(e=>{var t;return null===n||void 0===n||null===(t=n.data[e.id])||void 0===t?void 0:t.avg}).filter(e=>null!=e),u=x.length?x.reduce((e,t)=>e+t,0)/x.length:null,m=f.filter(e=>{var t;return"up"===(null===n||void 0===n||null===(t=n.data[e.id])||void 0===t?void 0:t.trend)}).length,p=f.filter(e=>{var t;return"down"===(null===n||void 0===n||null===(t=n.data[e.id])||void 0===t?void 0:t.trend)}).length,h=f.length-m-p;return(0,l.jsxs)("div",{className:"rounded-lg p-3 border",style:{backgroundColor:d,borderColor:c},children:[(0,l.jsxs)("div",{className:"text-xs font-bold uppercase tracking-wide mb-1",style:{color:o},children:[r," ",a]}),(0,l.jsx)("div",{className:"text-2xl font-black",style:{color:o},children:null!=u?u.toFixed(1):"\u2014"}),(0,l.jsxs)("div",{className:"text-xs text-gray-500 mt-0.5",children:[s.length," session",1!==s.length?"s":""]}),(0,l.jsxs)("div",{className:"flex gap-2 mt-1.5 text-xs font-medium",children:[(0,l.jsxs)("span",{style:{color:"#16a34a"},children:["\u2191 ",m]}),(0,l.jsxs)("span",{style:{color:"#dc2626"},children:["\u2193 ",p]}),(0,l.jsxs)("span",{style:{color:"#9ca3af"},children:["\u2192 ",h]})]})]},t)})})]})}},9107(e,t,s){s.d(t,{A:()=>m});var n=s(9379),r=s(5043),a=s(3862),l=s(579);const o=[{value:"",label:"All Skills"},{value:"LISTENING",label:"\ud83c\udfa7 Listening"},{value:"READING",label:"\ud83d\udcd6 Reading"},{value:"WRITING",label:"\u270d\ufe0f Writing"},{value:"GENERAL",label:"\ud83d\udcc1 General"}],i=["","A1","A2","B1","B2","C1","C2"],d={AUDIO:"\ud83c\udfb5",PDF:"\ud83d\udcc4",WORD:"\ud83d\udcdd",EXCEL:"\ud83d\udcca",HTML:"\ud83c\udfa7",OTHER:"\ud83d\udcce"};function c(e){return"HTML"===e.fileType&&"READING"===e.skillType?"\ud83d\udcd6":d[e.fileType]||"\ud83d\udcce"}const x={LISTENING:"#3b82f6",READING:"#10b981",WRITING:"#f59e0b",GENERAL:"#8b5cf6"};function u(e){return e<1048576?(e/1024).toFixed(0)+" KB":(e/1048576).toFixed(1)+" MB"}function m(e){let{groups:t,defaultGroupId:s,onClose:d,onAssigned:m}=e;const[p,h]=(0,r.useState)([]),[g,f]=(0,r.useState)(0),[b,y]=(0,r.useState)(1),[v,j]=(0,r.useState)(1),[N,S]=(0,r.useState)(!1),[w,k]=(0,r.useState)(""),[A,C]=(0,r.useState)(""),[T,E]=(0,r.useState)(""),[I,R]=(0,r.useState)(""),[D,L]=(0,r.useState)(null),[z,W]=(0,r.useState)(!1),[B,M]=(0,r.useState)(""),[P,O]=(0,r.useState)({dueDate:"",points:100,title:"",description:"",audioUrl:""}),[G,F]=(0,r.useState)(s?[s]:t[0]?[t[0].id]:[]);(0,r.useEffect)(()=>{_()},[b,w,A,I]),(0,r.useEffect)(()=>{D&&O(e=>(0,n.A)((0,n.A)({},e),{}
1,{title:D.title,description:D.description||""}))},[D]);const _=async()=>{S(!0);try{const e=new URLSearchParams({page:String(b),limit:"20"});w&&e.set("skillType",w),A&&e.set("level",A),I&&e.set("search",I);const t=await(0,a.n)("/library?".concat(e)),s=await t.json();s.success&&(h(s.data),f(s.pagination.total),j(s.pagination.pages))}catch(e){M("Failed to load library")}finally{S(!1)}},U=async e=>{if(e.preventDefault(),0!==G.length)if(P.dueDate){W(!0),M("");try{const e=await Promise.all(G.map(e=>(0,a.n)("/library/".concat(D.id,"/assign"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,n.A)({groupId:e,dueDate:new Date(P.dueDate).toISOString(),points:Number(P.points),title:P.title.trim()||D.title,description:P.description.trim()},"HTML"===D.fileType&&P.audioUrl.trim()&&{audioUrl:P.audioUrl.trim()}))}).then(e=>e.json()))),t=e.filter(e=>!e.success);0===t.length?(m&&m((0,n.A)((0,n.A)({},e[0].data),{},{groupCount:G.length})),d()):M(t[0].message||"Some assignments failed")}catch(t){M("Assignment failed")}finally{W(!1)}}else M("Due date is required");else M("Select at least one group")};return D?(0,l.jsx)("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-md",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between p-5 border-b",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:()=>L(null),className:"text-gray-400 hover:text-gray-600 text-sm border rounded-lg px-2 py-1",children:"\u2190 Back"}),(0,l.jsx)("h2",{className:"text-base font-bold",children:"Assign to Group"})]}),(0,l.jsx)("button",{onClick:d,className:"text-gray-400 hover:text-gray-600 text-xl leading-none",children:"\u2715"})]}),(0,l.jsxs)("div",{className:"mx-5 mt-4 p-3 rounded-xl border flex gap-3 items-start",style:{backgroundColor:x[D.skillType]+"10",borderColor:x[D.skillType]+"40"},children:[(0,l.jsx)("span",{className:"text-2xl",children:c(D)}),(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("p",{className:"font-semibold text-sm text-gray-900 truncate",children:D.title}),(0,l.jsxs)("p",{className:"text-xs text-gray-500",children:[D.skillType," \xb7 ",D.level||"Any level"," \xb7 ",u(D.fileSize)]})]})]}),(0,l.jsxs)("form",{onSubmit:U,className:"p-5 space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Groups *"}),(0,l.jsxs)("div",{className:"flex gap-1",children:[(0,l.jsx)("button",{type:"button",onClick:()=>F(t.map(e=>e.id)),className:"text-xs px-2 py-0.5 bg-blue-100 text-blue-700 rounded hover:bg-blue-200",children:"All"}),(0,l.jsx)("button",{type:"button",onClick:()=>F([]),className:"text-xs px-2 py-0.5 bg-gray-100 text-gray-600 rounded hover:bg-gray-200",children:"None"})]})]}),(0,l.jsx)("div",{className:"border rounded-lg overflow-hidden max-h-36 overflow-y-auto divide-y",children:t.map(e=>(0,l.jsxs)("label",{className:"flex items-center gap-2 px-3 py-1.5 cursor-pointer hover:bg-blue-50 transition-colors",style:{backgroundColor:G.includes(e.id)?"#eff6ff":void 0},children:[(0,l.jsx)("input",{type:"checkbox",checked:G.includes(e.id),onChange:t=>{t.target.checked?F(t=>[...t,e.id]):F(t=>t.filter(t=>t!==e.id))},className:"accent-blue-600"}),(0,l.jsx)("span",{className:"text-sm font-medium text-gray-800",children:e.name}),e.level&&(0,l.jsxs)("span",{className:"text-xs text-gray-400",children:["(",e.level,")"]})]},e.id))}),G.length>0&&(0,l.jsxs)("p",{className:"text-xs text-blue-600 mt-1",children:[G.length," group",G.length>1?"s":""," selected"]})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Due Date *"}),(0,l.jsx)("input",{type:"datetime-local",value:P.dueDate,onChange:e=>O(t=>(0,n.A)((0,n.A)({},t),{},{dueDate:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300",required:!0})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Points"}),(0,l.jsx)("input",{type:"number",min:1,max:1e3,value:P.points,onChange:e=>O(t=>(0,n.A)((0,n.A)({},t),{},{points:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Homework Title"}),(0,l.jsx)("input",{value:P.title,onChange:e=>O(t=>(0,n.A)((0,n.A)({},t),{},{title:e.target.value})),placeholder:"Leave blank to use resource title",className:"w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Instructions (optional)"}),(0,l.jsx)("textarea",{value:P.description,onChange:e=>O(t=>(0,n.A)((0,n.A)({},t),{},{description:e.target.value})),rows:2,placeholder:"Extra instructions for students...",className:"w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300 resize-none"})]}),"HTML"===D.fileType&&(0,l.jsxs)("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-xl space-y-2",children:[(0,l.jsx)("p",{className:"text-xs font-semibold text-blue-700",children:"\ud83c\udfa7 HTML Listening Test"}),(0,l.jsx)("p",{className:"text-xs text-blue-600",children:"Audio is auto-checked when students submit. If this test needs an external audio file, paste the URL below."}),(0,l.jsx)("input",{value:P.audioUrl,onChange:e=>O(t=>(0,n.A)((0,n.A)({},t),{},{audioUrl:e.target.value})),placeholder:"Audio URL (leave blank if audio is embedded in the test)",className:"w-full border border-blue-300 rounded-lg px-3 py-2 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-blue-300"})]}),B&&(0,l.jsx)("p",{className:"text-sm text-red-600",children:B}),(0,l.jsxs)("div",{className:"flex gap-3 pt-1",children:[(0,l.jsx)("button",{type:"button",onClick:()=>L(null),className:"flex-1 py-2 border rounded-lg text-sm font-medium text-gray-600 hover:bg-gray-50",children:"Back"}),(0,l.jsx)("button",{type:"submit",disabled:z,className:"flex-1 py-2 rounded-lg text-sm font-medium text-white disabled:opacity-50",style:{backgroundColor:"#002147"},children:z?"Assigning...":"Assign as Homework"})]})]})]})}):(0,l.jsx)("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-3xl max-h-[90vh] flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between p-5 border-b flex-shrink-0",children:[(0,l.jsx)("h2",{className:"text-lg font-bold",children:"Assign from Library"}),(0,l.jsx)("button",{onClick:d,className:"text-gray-400 hover:text-gray-600 text-xl leading-none",children:"\u2715"})]}),(0,l.jsxs)("div",{className:"p-4 border-b flex-shrink-0",children:[(0,l.jsxs)("form",{onSubmit:e=>{e.preventDefault(),R(T),y(1)},className:"flex flex-wrap gap-2 items-end",children:[(0,l.jsx)("input",{value:T,onChange:e=>E(e.target.value),placeholder:"Search title, tags...",className:"flex-1 min-w-[150px] border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"}),(0,l.jsx)("select",{value:w,onChange:e=>{k(e.target.value),y(1)},className:"border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300",children:o.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,l.jsx)("select",{value:A,onChange:e=>{C(e.target.value),y(1)},className:"border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300",children:i.map(e=>(0,l.jsx)("option",{value:e,children:e||"All Levels"},e))}),(0,l.jsx)("button",{type:"submit",className:"px-3 py-1.5 bg-gray-800 text-white rounded-lg text-sm",children:"Search"})]}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-2",children:[g," resource",1!==g?"s":""," \xb7 select one to assign"]})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:N?(0,l.jsx)("div",{className:"text-center py-8 text-gray-400 text-sm",children:"Loading..."}):0===p.length?(0,l.jsxs)("div",{className:"text-center py-8 text-gray-400",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udced"}),(0,l.jsx)("p",{className:"text-sm",children:"No resources found"})]}):(0,l.jsx)("div",{className:"space-y-2",children:p.map(e=>(0,l.jsxs)("div",{onClick:()=>L(e),className:"flex items-center gap-3 p-3 rounded-xl border cursor-pointer hover:shadow-md transition-all hover:border-blue-300",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center text-xl flex-shrink-0",style:{backgroundColor:x[e.skillType]+"15"},children:c(e)}),(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,l.jsx)("p",{className:"font-semibold text-sm text-gray-900 truncate",children:e.title}),(0,l.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded flex-shrink-0 font-medium",style:{backgroundColor:x[e.skillType]+"20",color:x[e.skillType]},children:e.skillType}),"HTML"===e.fileType&&(0,l.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded flex-shrink-0 font-medium bg-indigo-100 text-indigo-700",children:"Auto-graded"})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[e.level&&(0,l.jsx)("span",{className:"text-xs text-gray-500",children:e.level}),e.tags.slice(0,2).map(e=>(0,l.jsx)("span",{className:"text-xs bg-gray-100 text-gray-600 px-1.5 py-0.5 rounded",children:e},e)),(0,l.jsx)("span",{className:"text-xs text-gray-400 ml-auto",children:u(e.fileSize)})]})]}),(0,l.jsx)("span",{className:"text-gray-400 text-sm flex-shrink-0",children:"\u2192"})]},e.id))})}),v>1&&(0,l.jsxs)("div",{className:"flex justify-center gap-2 p-3 border-t flex-shrink-0",children:[(0,l.jsx)("button",{disabled:1===b,onClick:()=>y(e=>e-1),className:"px-3 py-1 text-sm border rounded-lg disabled:opacity-40",children:"Prev"}),(0,l.jsxs)("span",{className:"px-3 py-1 text-sm text-gray-600",children:[b,"/",v]}
1),(0,l.jsx)("button",{disabled:b===v,onClick:()=>y(e=>e+1),className:"px-3 py-1 text-sm border rounded-lg disabled:opacity-40",children:"Next"})]})]})})}},943(e,t,s){s.r(t),s.d(t,{default:()=>Dt});var n=s(5043),r=s(3862),a=s(9379),l=s(579);function o(){const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)(!0),[i,d]=(0,n.useState)({}),[c,x]=(0,n.useState)("ALL"),[u,m]=(0,n.useState)({}),[p,h]=(0,n.useState)({}),g=(()=>{try{return JSON.parse(localStorage.getItem("user")||"{}").id}catch(e){return null}})(),f=(0,n.useCallback)(async()=>{o(!0);const e=await(0,r.n)("/todos/my"),s=await e.json();s.success&&t(s.data),o(!1)},[]);(0,n.useEffect)(()=>{f()},[f]);const b=async(e,t)=>{const s=(u[e]||"").trim();if(!s)return;h(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!0}));const n=await(0,r.n)("/todos/sections/"+e+"/items",{method:"POST",body:JSON.stringify({title:s})});h(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!1})),n.ok&&(m(t=>(0,a.A)((0,a.A)({},t),{},{[e]:""})),f())},y=e.filter(e=>"ALL"===c||e.type===c);return(0,l.jsxs)("div",{className:"p-6 max-w-3xl mx-auto",children:[(0,l.jsx)("h1",{className:"text-2xl font-bold text-[#002147] mb-1",children:"My TO DO"}),(0,l.jsx)("p",{className:"text-sm text-gray-500 mb-5",children:"Track your assigned tasks"}),(0,l.jsx)("div",{className:"flex gap-2 mb-5",children:["ALL","GENERAL","DAILY"].map(e=>(0,l.jsx)("button",{onClick:()=>x(e),className:"px-4 py-1.5 rounded-full text-sm font-medium transition-colors "+(c===e?"bg-[#002147] text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"),children:"ALL"===e?"All":"GENERAL"===e?"General":"Daily"},e))}),s?(0,l.jsx)("div",{className:"text-center py-12 text-gray-400",children:"Loading\u2026"}):0===y.length?(0,l.jsx)("div",{className:"text-center py-12 text-gray-400",children:"No tasks assigned yet."}):(0,l.jsx)("div",{className:"space-y-4",children:y.map(e=>{const{total:s,done:n,pct:o}=(e=>{let t=0,s=0;for(const n of e.sections)for(const e of n.items)t++,e.completions&&e.completions.length>0&&s++;return{total:t,done:s,pct:0===t?0:Math.round(s/t*100)}})(e),c=!!i[e.id],x=e.date?new Date(e.date).toLocaleDateString("ru-RU"):null;return(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsxs)("div",{className:"px-4 py-3 cursor-pointer flex items-center justify-between",onClick:()=>{return t=e.id,d(e=>(0,a.A)((0,a.A)({},e),{},{[t]:!e[t]}));var t},children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium "+("GENERAL"===e.type?"bg-blue-50 text-blue-700":"bg-amber-50 text-amber-700"),children:"GENERAL"===e.type?"General":"Daily"}),x&&(0,l.jsx)("span",{className:"text-xs text-gray-400",children:x})]}),(0,l.jsx)("h3",{className:"font-semibold text-[#002147] text-sm",children:e.title}),(0,l.jsxs)("div",{className:"flex items-center gap-2 mt-1.5",children:[(0,l.jsx)("div",{className:"flex-1 bg-gray-100 rounded-full h-1.5 max-w-xs",children:(0,l.jsx)("div",{className:"bg-[#002147] h-1.5 rounded-full transition-all",style:{width:o+"%"}})}),(0,l.jsxs)("span",{className:"text-xs text-gray-500",children:[n,"/",s]})]})]}),(0,l.jsx)("span",{className:"text-gray-400 ml-3",children:c?"\u25b2":"\u25bc"})]}),c&&(0,l.jsx)("div",{className:"border-t border-gray-100",children:e.sections.map(s=>(0,l.jsxs)("div",{className:"px-4 py-3 border-b border-gray-50 last:border-0",children:[(0,l.jsx)("h4",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2",children:s.title}),(0,l.jsx)("div",{className:"space-y-1.5",children:s.items.map(s=>{const n=s.completions&&s.completions.length>0,o=!s.isAdminCreated&&s.createdBy&&s.createdBy.id===g;return(0,l.jsxs)("div",{className:"flex items-center gap-3 group",children:[(0,l.jsx)("button",{onClick:()=>(async(e,s)=>{t(t=>t.map(t=>t.id!==s?t:(0,a.A)((0,a.A)({},t),{},{sections:t.sections.map(t=>(0,a.A)((0,a.A)({},t),{},{items:t.items.map(t=>{if(t.id!==e)return t;const s=t.completions&&t.completions.length>0;return(0,a.A)((0,a.A)({},t),{},{completions:s?[]:[{id:"temp",completedAt:new Date}]})})}))}))),await(0,r.n)("/todos/items/"+e+"/toggle",{method:"POST"}),f()}
1)(s.id,e.id),className:"w-5 h-5 rounded border-2 flex-shrink-0 flex items-center justify-center transition-all "+(n?"bg-[#002147] border-[#002147] text-white":"border-gray-300 hover:border-[#002147]"),children:n&&(0,l.jsx)("span",{className:"text-xs leading-none",children:"\u2713"})}),(0,l.jsx)("span",{className:"text-sm flex-1 "+(n?"line-through text-gray-400":"text-gray-800"),children:s.title}),o&&(0,l.jsx)("button",{onClick:()=>(async e=>{await(0,r.n)("/todos/items/"+e,{method:"DELETE"}),f()})(s.id),className:"opacity-0 group-hover:opacity-100 text-red-400 hover:text-red-600 text-xs transition-opacity",children:"\u2715"})]},s.id)})}),(0,l.jsxs)("div",{className:"flex gap-2 mt-2",children:[(0,l.jsx)("input",{className:"flex-1 border border-gray-200 rounded px-2 py-1 text-xs placeholder-gray-300",placeholder:"Add your own task\u2026",value:u[s.id]||"",onChange:e=>m(t=>(0,a.A)((0,a.A)({},t),{},{[s.id]:e.target.value})),onKeyDown:t=>"Enter"===t.key&&b(s.id,e.id)}),(0,l.jsx)("button",{onClick:()=>b(s.id,e.id),disabled:!!p[s.id],className:"text-xs px-2 py-1 bg-gray-100 hover:bg-gray-200 rounded text-gray-600 disabled:opacity-50",children:"+"})]})]},s.id))})]},e.id)})})]})}var i=s(7902);const d=()=>(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"})}),c=()=>(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19.128a9.38 9.38 0 002.625.372 9.337 9.337 0 004.121-.952 4.125 4.125 0 00-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 018.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0111.964-3.07M12 6.375a3.375 3.375 0 11-6.75 0 3.375 3.375 0 016.75 0zm8.25 2.25a2.625 2.625 0 11-5.25 0 2.625 2.625 0 015.25 0z"})}),x=()=>(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z"})}),u=()=>(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),m=()=>(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5"})}),p={PENDING:{bg:"bg-gray-100",text:"text-gray-600",label:"Pending"},IN_PROGRESS:{bg:"bg-yellow-100",text:"text-yellow-800",label:"In Progress"},COMPLETED:{bg:"bg-green-100",text:"text-green-700",label:"Completed"},CANCELLED:{bg:"bg-red-100",text:"text-red-700",label:"Cancelled"}};function h(e){let{status:t}=e;const s=p[t]||p.PENDING;return(0,l.jsx)("span",{className:"inline-flex px-2 py-0.5 rounded-full text-xs font-semibold ".concat(s.bg," ").concat(s.text),children:s.label})}function g(e){let{user:t,onNavigate:s}=e;const[a,o]=(0,n.useState)([]),[i,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(null),[y,v]=(0,n.use
1State)(!1),[j,N]=(0,n.useState)(!1),[S,w]=(0,n.useState)([]),[k,A]=(0,n.useState)(!0),[C,T]=(0,n.useState)([]),[E,I]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&o(e.data)}).catch(()=>{}).finally(()=>p(!1)),(0,r.n)("/readiness-checks").then(e=>e.json()).then(e=>{e.success&&w(e.data||[])}).catch(()=>{}).finally(()=>A(!1)),(0,r.n)("/srs/errors/pending-feedback").then(e=>e.json()).then(e=>{e.success&&T(e.data||[])}).catch(()=>{})},[]);const R=a.reduce((e,t)=>{var s,n;return e+(null!==(s=null===(n=t._count)||void 0===n?void 0:n.enrollments)&&void 0!==s?s:0)},0);return(0,l.jsxs)("div",{className:"p-6 sm:p-8",children:[(0,l.jsxs)("div",{className:"mb-7",children:[(0,l.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-1",children:"Teacher Portal"}),(0,l.jsxs)("h2",{className:"text-3xl sm:text-4xl font-black tracking-tight text-gray-900 mb-1",children:["Welcome back, ",t.firstName,"!"]}),(0,l.jsx)("p",{className:"text-gray-500 text-sm",children:"Here's your overview for today."})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 mb-8",children:[(0,l.jsx)(f,{icon:(0,l.jsx)(d,{}),label:"My Groups",value:i?"\u2026":a.length,iconBg:"#ede9fe",iconColor:"#7c3aed"}),(0,l.jsx)(f,{icon:(0,l.jsx)(c,{}),label:"Total Students",value:i?"\u2026":R,iconBg:"#e0f2fe",iconColor:"#0891b2"}),(0,l.jsx)(f,{icon:(0,l.jsx)(x,{}),label:"Active Checks",value:k?"\u2026":S.filter(e=>"PENDING"===e.status||"IN_PROGRESS"===e.status).length,iconBg:"#fff7ed",iconColor:"#ea580c",onClick:()=>s("readiness"),clickable:!0}),(0,l.jsx)(f,{icon:(0,l.jsx)(u,{}),label:"Pending Feedback",value:C.length,iconBg:"#fefce8",iconColor:"#ca8a04",onClick:()=>I(e=>!e),clickable:!0}),(0,l.jsx)(f,{icon:(0,l.jsx)(m,{}),label:"Today",value:(new Date).toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),iconBg:"#f0fdf4",iconColor:"#16a34a"})]}),(0,l.jsx)("div",{className:"bg-sky-50 border border-sky-100 rounded-2xl p-5 mb-7",children:(0,l.jsxs)("div",{className:"flex items-start gap-3.5",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-xl bg-sky-100 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("svg",{className:"w-5 h-5 text-sky-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})})}),(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("h4",{className:"font-bold text-gray-900 mb-1",children:"Telegram Bot"}),(0,l.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"Connect your Telegram to send print requests directly \u2014 just send a file to the bot!"}),y&&!g?(0,l.jsxs)("p",{className:"text-sm text-green-600 font-semibold flex items-center gap-1.5",children:[(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Telegram already connected"]}):g?(0,l.jsxs)("div",{children:[y&&(0,l.jsxs)("p",{className:"text-xs text-green-600 mb-2 flex items-center gap-1",children:[(0,l.jsx)("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),"Already connected \u2014 use this to re-link if needed"]}),(0,l.jsx)("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-sky-500 text-white text-sm font-semibold rounded-xl hover:bg-sky-600 transition-colors",children:"Open in Telegram"}),(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-2",children:"Link expires in 7 days"})]}):(0,l.jsx)("button",{onClick:async()=>{N(!0);try{const e=await(0,r.n)("/teachers/".concat(t.id,"/generate-telegram-link"),{method:"POST"}),s=await e.json();s.success&&(b(s.data.link),s.data.telegramLinked&&v(!0))}catch(e){console.error("Failed to generate link:",e)}finally{N(!1)}},disabled:j,className:"px-4 py-2 bg-sky-500 text-white text-sm font-semibold rounded-xl hover:bg-sky-600 disabled:opacity-50 transition-colors cursor-pointer border-none",children:j?"Generating\u2026":"Connect Telegram"})]})]})}),(0,l.jsxs)("div",{className:"mb-7",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsx)("h3",{className:"text-base font-black tracking-tight text-gray-900",children:"Readiness Checks"}),(0,l.jsx)("button",{onClick:()=>s("readiness"),className:"text-xs px-3 py-1.5 bg-slate-900 text-white rounded-lg hover:bg-slate-700 transition-colors cursor-pointer border-none font-semibold",children:"View All \u2192"})]}),k?(0,l.jsx)("p",{className:"text-sm text-gray-400",children:"Loading\u2026"}):(()=>{const e=S.filter(e=>"PENDING"===e.status||"IN_PROGRESS"===e.status);return 0===e.length?(0,l.jsxs)("div",{className:"bg-green-50 border border-green-100 rounded-2xl p-4 flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-xl bg-green-100 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("svg",{className:"w-4 h-4 text-green-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),(0,l.jsx)("p",{className:"text-sm text-green-700 font-semibold",children:"No active readiness checks \u2014 all clear!"})]}):(0,l.jsx)("div",{className:"space-y-2",children:e.map(e=>{var t,n,r,a,o,i,d,c;const x=e.assignedTo,u=x?"".concat(x.firstName," ").concat(x.lastName):"\u2014",m=null!==(t=null!==(n=null===(r=e._
1count)||void 0===r?void 0:r.enrollments)&&void 0!==n?n:null===(a=e.enrollments)||void 0===a?void 0:a.length)&&void 0!==t?t:0,p=e.enrollments?e.enrollments.filter(e=>"PENDING"!==e.status).length:null;return(0,l.jsxs)("button",{onClick:()=>s("readiness"),className:"w-full text-left bg-white border border-gray-100 hover:border-slate-300 hover:shadow-md rounded-2xl p-4 shadow-sm transition-all flex items-center gap-4",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("p",{className:"font-bold text-gray-900 truncate text-sm",children:e.title||"".concat(null!==(o=null===(i=e.group)||void 0===i?void 0:i.name)&&void 0!==o?o:"Group"," \u2014 Readiness Check")}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:["Group: ",null!==(d=null===(c=e.group)||void 0===c?void 0:c.name)&&void 0!==d?d:"\u2014"," \xb7 TA: ",u]}),null!==p&&(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:[p," / ",m," students marked"]})]}),(0,l.jsx)(h,{status:e.status})]},e.id)})})})()]}),E&&(0,l.jsxs)("div",{className:"mb-7 bg-amber-50 border border-amber-100 rounded-2xl overflow-hidden",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-b border-amber-100",children:[(0,l.jsxs)("h3",{className:"text-sm font-bold text-amber-800 flex items-center gap-2",children:[(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Errors Awaiting Delayed Feedback"]}),(0,l.jsx)("button",{onClick:()=>I(!1),className:"text-amber-400 hover:text-amber-600 transition-colors cursor-pointer border-none bg-transparent leading-none text-xl",children:"\xd7"})]}),0===C.length?(0,l.jsx)("p",{className:"px-5 py-4 text-sm text-amber-700",children:"All caught up \u2014 no pending feedback."}):(0,l.jsx)("div",{className:"divide-y divide-amber-100",children:C.map(e=>{var t,s,n,a,o,i,d;return(0,l.jsxs)("div",{className:"flex items-start gap-3 px-5 py-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("p",{className:"text-sm font-bold text-gray-800",children:[null===(t=e.student)||void 0===t||null===(s=t.user)||void 0===s?void 0:s.firstName," ",null===(n=e.student)||void 0===n||null===(a=n.user)||void 0===a?void 0:a.lastName,(0,l.jsxs)("span",{className:"ml-2 text-xs font-normal text-gray-500",children:["in ",null===(o=e.session)||void 0===o||null===(i=o.group)||void 0===i?void 0:i.name," \xb7 ",(null===(d=e.session)||void 0===d?void 0:d.topic)||"Session"]})]}),(0,l.jsxs)("p",{className:"text-sm text-red-600 mt-0.5",children:["\u2717 ",e.errorText]}),e.correction&&(0,l.jsxs)("p",{className:"text-sm text-green-600",children:["\u2713 ",e.correction]}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:["Scheduled: ",e.feedbackScheduledFor?new Date(e.feedbackScheduledFor).toLocaleDateString("en-GB",{day:"2-digit",month:"short"}):"\u2014"]})]}),(0,l.jsx)("button",{onClick:()=>(async e=>{try{await(0,r.n)("/srs/errors/".concat(e,"/feedback-given"),{method:"POST"}),T(t=>t.filter(t=>t.id!==e))}catch(t){console.error(t)}})(e.id),className:"shrink-0 px-3 py-1.5 text-xs bg-green-100 text-green-700 hover:bg-green-200 rounded-lg font-semibold transition-colors cursor-pointer border-none",children:"Mark given \u2713"})]},e.id)})})]}),(0,l.jsx)("h3",{className:"text-base font-black tracking-tight text-gray-900 mb-4",children:"My Groups"}),i?(0,l.jsx)("p",{className:"text-gray-400 text-sm",children:"Loading\u2026"}):0===a.length?(0,l.jsx)("p",{className:"text-gray-400 text-sm",children:"No groups assigned yet."}):(0,l.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(e=>{var t,n;return(0,l.jsxs)("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-gray-100 hover:shadow-md transition-shadow flex items-center justify-between",children:[(0,l.jsxs)("div",{className:"min-w-0 flex-1 mr-3",children:[(0,l.jsx)("p",{className:"font-bold text-gray-900 truncate",children:e.name}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:[e.groupCode," \xb7 ",e.level||"No level"]}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:[null!==(t=null===(n=e._count)||void 0===n?void 0:n.enrollments)&&void 0!==t?t:0," students"]})]}),(0,l.jsxs)("div",{className:"flex flex-col gap-2 flex-shrink-0",children:[(0,l.jsx)("button",{onClick:()=>s("attendance"),className:"text-xs px-3 py-1.5 bg-slate-900 text-white rounded-lg hover:bg-slate-700 transition-colors cursor-pointer border-none font-semibold",children:"Attendance"}),(0,l.jsx)("button",{onClick:()=>s("exams"),className:"text-xs px-3 py-1.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors cursor-pointer border-none font-semibold",children:"Grades"})]})]},e.id)})})]})}function f(e){let{icon:t,label:s,value:n,iconBg:r,iconColor:a,onClick:o,clickable:i}=e;return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-100 shadow-sm p-5 ".concat(i?"cursor-pointer hover:shadow-md hover:-translate-y-0.5 transition-all duration-200":""),onClick:o,children:[(0,l.jsx)("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center mb-3",style:{backgroundColor:r,color:a},children:(0,l.jsx)("div",{className:"w-5 h-5",children:t})}),(0,l.jsx)("p",{className:"text-2xl font-black tracking-tight text-gray-900 leading-none",children:n}),(0,l.jsx)("p",{className:"text-[0.65rem] font-semibold text-gray-400 uppercase tracking-widest mt-1.5",children:s})]})}
1const b=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],y=["","Mon","Tue","Wed","Thu","Fri","Sat","Sun"],v=["#3b82f6","#8b5cf6","#10b981","#f59e0b","#ef4444","#06b6d4","#f97316","#ec4899"];function j(){const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)(!0);if((0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&t(e.data||[])}).finally(()=>o(!1))},[]),s)return(0,l.jsx)("div",{className:"p-8 text-[#708090]",children:"Loading schedule..."});const i={};for(let n=1;n<=7;n++)i[n]=[];const d=[];e.forEach((e,t)=>{const s=v[t%v.length];e.daysOfWeek&&0!==e.daysOfWeek.length?[...e.daysOfWeek].sort((e,t)=>e-t).forEach(t=>{i[t]&&i[t].push((0,a.A)((0,a.A)({},e),{},{color:s}))}):d.push((0,a.A)((0,a.A)({},e),{},{color:s}))});const c=[1,2,3,4,5,6,7].filter(e=>i[e].length>0);return(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147] mb-2",children:"\ud83d\uddd3\ufe0f My Schedule"}),(0,l.jsxs)("p",{className:"text-sm text-[#708090] mb-6",children:[e.length," group",1!==e.length?"s":""," assigned"]}),0===e.length?(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow border border-gray-100 p-12 text-center",children:[(0,l.jsx)("div",{className:"text-5xl mb-3",children:"\ud83d\udced"}),(0,l.jsx)("p",{className:"text-[#708090]",children:"No groups assigned to you yet."})]}):(0,l.jsxs)(l.Fragment,{children:[c.length>0&&(0,l.jsx)("div",{className:"grid gap-5 mb-8",style:{gridTemplateColumns:"repeat(".concat(Math.min(c.length,4),", 1fr)")},children:c.map(e=>(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow border border-gray-100 overflow-hidden",children:[(0,l.jsx)("div",{className:"px-4 py-2.5 bg-[#002147]",children:(0,l.jsx)("p",{className:"text-white font-bold text-sm",children:b[e]})}),(0,l.jsx)("div",{className:"p-3 space-y-2",children:i[e].map(e=>{var t,s;return(0,l.jsxs)("div",{style:{borderLeft:"4px solid ".concat(e.color),background:"".concat(e.color,"10")},className:"rounded-lg px-3 py-2",children:[(0,l.jsx)("p",{className:"font-semibold text-[#002147] text-sm",children:e.name}),(0,l.jsxs)("p",{className:"text-xs text-[#708090]",children:[e.level||""," \xb7 ",null!==(t=null===(s=e._count)||void 0===s?void 0:s.enrollments)&&void 0!==t?t:0," students"]}),e.startTime&&e.endTime&&(0,l.jsxs)("p",{className:"text-xs font-medium mt-0.5",style:{color:e.color},children:["\ud83d\udd50 ",e.startTime," \u2013 ",e.endTime]}),e.room&&(0,l.jsxs)("p",{className:"text-xs text-[#708090]",children:["\ud83d\udccd ",e.room]})]},e.id)})})]},e))}),(0,l.jsx)("h3",{className:"text-lg font-bold text-[#002147] mb-3",children:"All Groups"}),(0,l.jsx)("div",{className:"space-y-3",children:e.map((e,t)=>{var s,n;const r=v[t%v.length],a=[...e.daysOfWeek||[]].sort((e,t)=>e-t);return(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow border border-gray-100 p-4 flex items-start gap-4",children:[(0,l.jsx)("div",{className:"w-1 self-stretch rounded-full flex-shrink-0",style:{background:r}}),(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,l.jsx)("p",{className:"font-semibold text-[#002147]",children:e.name}),e.groupCode&&(0,l.jsxs)("span",{className:"text-xs text-[#708090] font-mono",children:["#",e.groupCode]}),e.level&&(0,l.jsx)("span",{className:"text-xs font-bold px-2 py-0.5 rounded",style:{background:"".concat(r,"20"),color:r},children:e.level})]}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-1.5 mt-2",children:[a.length>0?a.map(e=>(0,l.jsx)("span",{className:"text-xs font-bold text-white px-2 py-0.5 rounded",style:{background:r},children:y[e]},e)):(0,l.jsx)("span",{className:"text-xs text-gray-400 italic",children:"No days set"}),e.startTime&&e.endTime&&(0,l.jsxs)("span",{className:"text-xs font-medium text-[#374151] ml-1",children:["\ud83d\udd50 ",e.startTime," \u2013 ",e.endTime]}),e.room&&(0,l.jsxs)("span",{className:"text-xs text-[#708090]",children:["\ud83d\udccd ",e.room]})]}),(0,l.jsxs)("p",{className:"text-xs text-[#708090] mt-1",children:["\ud83d\udc65 ",null!==(s=null===(n=e._count)||void 0===n?void 0:n.enrollments)&&void 0!==s?s:0," active students"]})]})]},e.id)})}),d.length>0&&(0,l.jsxs)("div",{className:"mt-6",children:[(0,l.jsxs)("h3",{className:"text-sm font-semibold text-[#708090] mb-2",children:["\u26a0\ufe0f Groups without schedule (",d.length,")"]}),(0,l.jsx)("div",{className:"space-y-2",children:d.map(e=>(0,l.jsxs)("div",{className:"bg-white rounded-lg border border-dashed border-gray-300 px-4 py-2.5 flex items-center justify-between",children:[(0,l.jsx)("p",{className:"font-medium text-[#002147] text-sm",children:e.name}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"No days/time set"})]},e.id))})]})]})]})}var N=s(3488);const S={NOT_STARTED:{icon:"\u25cb",label:"Not Started",color:"#9ca3af",bg:"#f3f4f6"},IN_PROGRESS:{icon:"\u25d1",label:"In Progress",color:"#d97706",bg:"#fef3c7"}
1,DONE:{icon:"\u2713",label:"Done",color:"#16a34a",bg:"#dcfce7"}},w=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#06b6d4","#ef4444"];function k(){var e,t;const[s,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!0),[c,x]=(0,n.useState)(null),[u,m]=(0,n.useState)("students");(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&o(e.data)}).finally(()=>d(!1))},[]);if(!c)return(0,l.jsxs)("div",{className:"p-6 max-w-3xl mx-auto",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold mb-6",style:{color:"#111827"},children:"\ud83d\udcda My Groups"}),i?(0,l.jsx)("p",{style:{color:"#9ca3af"},children:"Loading..."}):0===s.length?(0,l.jsx)("p",{style:{color:"#9ca3af"},children:"No groups assigned to you yet."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:s.map(e=>{var t,s;return(0,l.jsxs)("div",{onClick:()=>(e=>{x(e),m("students")})(e),style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",border:"1px solid #f0f0f0",cursor:"pointer",transition:"box-shadow 0.15s, transform 0.1s",display:"flex",alignItems:"center",justifyContent:"space-between"},onMouseEnter:e=>{e.currentTarget.style.boxShadow="0 4px 16px rgba(0,0,0,0.12)",e.currentTarget.style.transform="translateY(-1px)"},onMouseLeave:e=>{e.currentTarget.style.boxShadow="0 1px 4px rgba(0,0,0,0.08)",e.currentTarget.style.transform="translateY(0)"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:17,color:"#111827",marginBottom:3},children:e.name}),(0,l.jsxs)("p",{style:{fontSize:13,color:"#6b7280"},children:[e.groupCode," \xb7 ",e.level||"\u2014",e.schedule?" \xb7 ".concat(e.schedule):"",e.room?" \xb7 Room ".concat(e.room):""]}),(0,l.jsxs)("p",{style:{fontSize:13,color:"#9ca3af",marginTop:2},children:[null!==(t=null===(s=e._count)||void 0===s?void 0:s.enrollments)&&void 0!==t?t:0," students"]})]}),(0,l.jsx)("span",{style:{fontSize:18,color:"#9ca3af"},children:"\u203a"})]},e.id)})})]});return(0,l.jsxs)("div",{style:{minHeight:"100%"},children:[(0,l.jsxs)("div",{style:{background:"white",borderBottom:"1px solid #f0f0f0",padding:"16px 24px",position:"sticky",top:0,zIndex:10},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:14},children:[(0,l.jsx)("button",{onClick:()=>x(null),style:{background:"none",border:"none",color:"#6b7280",cursor:"pointer",fontSize:14,padding:"4px 0",display:"flex",alignItems:"center",gap:4},children:"\u2190 My Groups"}),(0,l.jsx)("span",{style:{color:"#d1d5db"},children:"|"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{style:{fontWeight:700,fontSize:17,color:"#111827"},children:c.name}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#9ca3af",marginLeft:8},children:[c.level," \xb7 ",null!==(e=null===(t=c._count)||void 0===t?void 0:t.enrollments)&&void 0!==e?e:0," students"]})]})]}),(0,l.jsx)("div",{style:{display:"flex",gap:4,overflowX:"auto"},children:[{id:"students",icon:"\ud83d\udc65",label:"Students"},{id:"syllabus",icon:"\ud83d\udccb",label:"Syllabus"},{id:"exams",icon:"\ud83d\udcca",label:"Exam Results"},{id:"attendance",icon:"\ud83d\udcdd",label:"Attendance"},{id:"comments",icon:"\ud83d\udcac",label:"Comments"}].map(e=>(0,l.jsxs)("button",{onClick:()=>m(e.id),style:{padding:"7px 14px",borderRadius:20,border:"none",cursor:"pointer",fontWeight:600,fontSize:13,whiteSpace:"nowrap",transition:"all 0.15s",background:u===e.id?"#111827":"#f3f4f6",color:u===e.id?"white":"#374151"},children:[e.icon," ",e.label]},e.id))})]}),(0,l.jsxs)("div",{style:{padding:"20px 24px"},children:["students"===u&&(0,l.jsx)(A,{group:c,onCountChange:e=>o(t=>t.map(t=>t.id===c.id?(0,a.A)((0,a.A)({},t),{},{_count:(0,a.A)((0,a.A)({},t._count),{},{enrollments:e})}):t))}),"syllabus"===u&&(0,l.jsx)(T,{group:c}),"exams"===u&&(0,l.jsx)(E,{group:c}),"attendance"===u&&(0,l.jsx)(I,{group:c}),"comments"===u&&(0,l.jsx)(R,{group:c})]})]})}function A(e){let{group:t,onCountChange:s}=e;const[a,o]=(0,n.useState)([]),[i,d]=(0,n.useState)([]),[c,x]=(0,n.useState)(""),[u,m]=(0,n.useState)({text:"",ok:!0}),[p,h]=(0,n.useState)(null);(0,n.useEffect)(()=>{g(),(0,r.n)("/students?limit=5000").then(e=>e.json()).then(e=>{e.success&&d(e.data||[])})},[t.id]);const g=async()=>{const e=await(0,r.n)("/groups/".concat(t.id,"/roster")),n=await e.json();n.success&&(o(n.data||[]),null===s||void 0===s||s(n.data.length))},f=new Set(a.map(e=>e.id)),b=i.filter(e=>{var t,s,n;if(f.has(e.id))return!1;if(!c)return!0;const r=c.toLowerCase();return"".concat((null===(t=e.user)||void 0===t?void 0:t.firstName)||""," ").concat((null===(s=e.user)||void 0===s?void 0:s.lastName)||"").toLowerCase().includes(r)||(null===(n=e.studentId)||void 0===n?void 0:n.toLowerCase().includes(r))});return(0,l.jsxs)(l.Fragment,{children:[p&&(0,l.jsx)(C,{studentId:p,onClose:()=>h(null)}),(0,l.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(300px, 1fr))",gap:16},children:[u.text&&(0,l.jsx)("div",{style:{gridColumn:"1/-1",padding:"10px 14px",borderRadius:8,background:u.ok?"#dcfce7":"#fee2e2",color:u.ok?"#166534":"#991b1b",fontSize:13,fontWeight:500},children:u.text}),(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:20,boxSh
1adow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsxs)("h3",{style:{fontWeight:700,marginBottom:12,fontSize:15,color:"#111827"},children:["Enrolled (",a.length,")"]}),0===a.length?(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:13},children:"No students yet."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:a.map((e,s)=>(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",background:"#f9fafb",borderRadius:8},children:[(0,l.jsxs)("div",{style:{cursor:"pointer",flex:1},onClick:()=>h(e.id),children:[(0,l.jsxs)("p",{style:{fontSize:14,fontWeight:600,color:"#111827"},children:[s+1,". ",e.firstName," ",e.lastName]}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af"},children:[e.studentId,e.enrolledAt?" \xb7 ".concat(new Date(e.enrolledAt).toLocaleDateString("en-GB")):""]})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,l.jsx)("button",{onClick:()=>h(e.id),style:{padding:"4px 10px",background:"#eff6ff",color:"#2563eb",border:"none",borderRadius:6,cursor:"pointer",fontSize:12,fontWeight:600},children:"View"}),(0,l.jsx)("button",{onClick:()=>(async e=>{if(!window.confirm("Remove this student from the group?"))return;const s=await(0,r.n)("/groups/".concat(t.id,"/students/").concat(e),{method:"DELETE"}),n=await s.json();n.success?(m({text:"\u2705 Removed",ok:!0}),g()):m({text:n.message||"Error",ok:!1})})(e.enrollmentId),style:{padding:"4px 10px",background:"#fee2e2",color:"#dc2626",border:"none",borderRadius:6,cursor:"pointer",fontSize:12,fontWeight:600},children:"Remove"})]})]},e.id))})]}),(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsx)("h3",{style:{fontWeight:700,marginBottom:12,fontSize:15,color:"#111827"},children:"Add Student"}),(0,l.jsx)("input",{value:c,onChange:e=>x(e.target.value),placeholder:"Search by name or ID...",style:{width:"100%",padding:"8px 12px",border:"1px solid #e5e7eb",borderRadius:8,fontSize:13,boxSizing:"border-box",marginBottom:10}}),(0,l.jsxs)("div",{style:{maxHeight:320,overflowY:"auto",display:"flex",flexDirection:"column",gap:6},children:[b.slice(0,30).map(e=>{var s,n;return(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",background:"#f9fafb",borderRadius:8},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("p",{style:{fontSize:14,fontWeight:500,color:"#111827"},children:[(null===(s=e.user)||void 0===s?void 0:s.firstName)||""," ",(null===(n=e.user)||void 0===n?void 0:n.lastName)||""]}),(0,l.jsx)("p",{style:{fontSize:12,color:"#9ca3af"},children:e.studentId})]}),(0,l.jsx)("button",{onClick:()=>(async e=>{m({text:"",ok:!0});const s=await(0,r.n)("/groups/".concat(t.id,"/enroll"),{method:"POST",body:JSON.stringify({studentId:e})}),n=await s.json();n.success?(m({text:"\u2705 Student added",ok:!0}),g()):m({text:n.message||"Error",ok:!1})})(e.id),style:{padding:"4px 10px",background:"#dcfce7",color:"#166534",border:"none",borderRadius:6,cursor:"pointer",fontSize:12,fontWeight:600},children:"+ Add"})]},e.id)}),0===b.length&&(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:13},children:"No students to add."}),b.length>30&&(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:12,textAlign:"center"},children:"Showing 30 \u2014 refine search"})]})]})]})]})}function C(e){var t,s,o,i,d;let{studentId:c,onClose:x}=e;const[u,m]=(0,n.useState)("overview"),[p,h]=(0,n.useState)(null),[g,f]=(0,n.useState)([]),[b,y]=(0,n.useState)([]),[v,j]=(0,n.useState)([]),[S,w]=(0,n.useState)([]),[k,A]=(0,n.use
1State)([]),[C,T]=(0,n.useState)([]),[E,I]=(0,n.useState)(!0);(0,n.useEffect)(()=>{I(!0);const e=e=>(0,r.n)(e).then(e=>e.json()).catch(()=>({success:!1}));Promise.all([e("/students/".concat(c,"/details")),e("/exams/student/".concat(c)),e("/students/".concat(c,"/homework-submissions")),e("/grades/sessions?studentId=".concat(c)),e("/speaking-schedules/student/".concat(c))]).then(async e=>{var t;let[s,n,a,l,o]=e;const i=s.success?s.data:null;if(h(i),n.success&&f(n.data||[]),a.success&&y(a.data||[]),l.success&&j(l.data||[]),o.success&&w(o.data||[]),fetch("".concat(N.H,"/api/vocab/progress/").concat(c)).then(e=>e.json()).then(e=>{e.success&&T(e.data||[])}).catch(()=>{}),(null===i||void 0===i||null===(t=i.enrollments)||void 0===t?void 0:t.length)>0){const e=i.enrollments.map(e=>e.groupId),t=(await Promise.allSettled(e.map(e=>(0,r.n)("/homework/group/".concat(e)).then(e=>e.json())))).filter(e=>{var t;return"fulfilled"===e.status&&(null===(t=e.value)||void 0===t?void 0:t.success)}).flatMap(e=>e.value.data||[]);A(t)}}).finally(()=>I(!1))},[c]);const R=(null===p||void 0===p?void 0:p.attendanceRecords)||[],D=R.length,L=R.filter(e=>"PRESENT"===e.status).length,z=R.filter(e=>"LATE"===e.status).length,W=R.filter(e=>"ABSENT"===e.status).length,B=null!==(t=null===p||void 0===p?void 0:p.attendanceRate)&&void 0!==t?t:D>0?Math.round(L/D*100):0,M=p?"".concat((null===(s=p.user)||void 0===s?void 0:s.firstName)||""," ").concat((null===(o=p.user)||void 0===o?void 0:o.lastName)||"").trim():"\u2026",P=(null===p||void 0===p?void 0:p.enrollments)||[],O={};b.forEach(e=>{e.homeworkId&&(O[e.homeworkId]=e)});const G=k.map(e=>(0,a.A)((0,a.A)({},e),{},{submission:O[e.id]||null})),F=G.filter(e=>e.submission&&"PENDING"!==e.submission.status).length,_=G.filter(e=>!e.submission).length,U={PRESENT:"#16a34a",LATE:"#d97706",ABSENT:"#dc2626",EXCUSED:"#6b7280",EARLY_LEAVE:"#9333ea"},H={GRADED:"#16a34a",SUBMITTED:"#2563eb",PENDING:"#d97706",LATE:"#dc2626",NOT_SUBMITTED:"#dc2626"},V=[{id:"overview",label:"Overview"},{id:"attendance",label:"Attendance (".concat(D,")")},{id:"exams",label:"Exams (".concat(g.length,")")},{id:"homework",label:"Homework (".concat(G.length||b.length,")")},{id:"grades",label:"Grades (".concat(v.length,")")},...S.length>0?[{id:"speaking",label:"Speaking (".concat(S.length,")")}]:[],{id:"vocabulary",label:"\ud83d\udcda Vocab".concat(C.length>0?" (".concat(C.length,")"):"")}];return(0,l.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",justifyContent:"flex-end"},children:[(0,l.jsx)("div",{onClick:x,style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.4)"}}),(0,l.jsxs)("div",{style:{position:"relative",width:"100%",maxWidth:560,background:"white",height:"100%",display:"flex",flexDirection:"column",boxShadow:"-4px 0 24px rgba(0,0,0,0.15)"},children:[(0,l.jsxs)("div",{style:{padding:"20px 24px 16px",borderBottom:"1px solid #f0f0f0",background:"#f9fafb"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14},children:[(0,l.jsx)("div",{style:{width:52,height:52,borderRadius:"50%",background:"#1e3a5f",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontWeight:700,fontSize:20,flexShrink:0},children:E?"\u2026":((null===p||void 0===p||null===(i=p.user)||void 0===i||null===(d=i.firstName)||void 0===d?void 0:d[0])||"?").toUpperCase()}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:18,color:"#111827",lineHeight:1.2},children:M}),(0,l.jsx)("p",{style:{fontSize:13,color:"#6b7280",marginTop:2},children:(null===p||void 0===p?void 0:p.studentId)||""}),(null===p||void 0===p?void 0:p.status)&&(0,l.jsx)("span",{style:{display:"inline-block",marginTop:4,padding:"2px 8px",borderRadius:12,fontSize:11,fontWeight:600,background:"ACTIVE"===p.status?"#dcfce7":"#f3f4f6",color:"ACTIVE"===p.status?"#166534":"#4b5563"},children:p.status})]})]}),(0,l.jsx)("button",{onClick:x,style:{background:"none",border:"none",cursor:"pointer",fontSize:22,color:"#9ca3af",padding:4},children:"\u2715"})]}),P.length>0&&(0,l.jsx)("div",{style:{marginTop:12,display:"flex",flexWrap:"wrap",gap:6},children:P.map(e=>{var t;return(0,l.jsx)("span",{style:{padding:"3px 10px",background:"#eff6ff",color:"#1d4ed8",borderRadius:12,fontSize:12,fontWeight:500},children:(null===(t=e.group)||void 0===t?void 0:t.name)||e.groupId},e.id)})})]}),(0,l.jsx)("div",{style:{display:"flex",borderBottom:"1px solid #f0f
10f0",padding:"0 16px",gap:4,flexShrink:0,overflowX:"auto"},children:V.map(e=>(0,l.jsx)("button",{onClick:()=>m(e.id),style:{padding:"10px 14px",border:"none",background:"none",cursor:"pointer",fontWeight:600,fontSize:13,whiteSpace:"nowrap",color:u===e.id?"#1e3a5f":"#6b7280",borderBottom:u===e.id?"2px solid #1e3a5f":"2px solid transparent"},children:e.label},e.id))}),(0,l.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px"},children:E?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:40},children:"Loading\u2026"}):"overview"===u?(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:12,padding:16},children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:14,color:"#111827",marginBottom:10},children:"Attendance"}),(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:8},children:[(0,l.jsx)("div",{style:{flex:1,height:8,background:"#e5e7eb",borderRadius:4,overflow:"hidden"},children:(0,l.jsx)("div",{style:{width:"".concat(B,"%"),height:"100%",background:B>=75?"#16a34a":B>=50?"#d97706":"#dc2626",borderRadius:4}})}),(0,l.jsxs)("span",{style:{fontWeight:700,fontSize:15,color:B>=75?"#16a34a":B>=50?"#d97706":"#dc2626",minWidth:38,textAlign:"right"},children:[B,"%"]})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:16},children:[(0,l.jsxs)("span",{style:{fontSize:13,color:"#16a34a"},children:["\u2713 ",L," present"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#d97706"},children:["\u23f0 ",z," late"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#dc2626"},children:["\u2717 ",W," absent"]})]})]}),(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:12,padding:16},children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:14,color:"#111827",marginBottom:10},children:"Recent Exams"}),0===g.length?(0,l.jsx)("p",{style:{fontSize:13,color:"#9ca3af"},children:"No exam results yet."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:g.slice(0,4).map(e=>{var t;return(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:e.examTitle}),(0,l.jsx)("p",{style:{fontSize:11,color:"#9ca3af"},children:e.date?new Date(e.date).toLocaleDateString("en-GB"):""})]}),(0,l.jsx)("span",{style:{fontWeight:700,fontSize:14,color:e.absent?"#9ca3af":"#1e3a5f"},children:e.absent?"Absent":"IELTS"===e.gradingType?"".concat(null!==(t=e.score)&&void 0!==t?t:"\u2014"," band"):null!=e.score?"".concat(e.score,"%"):"\u2014"})]},e.id)})})]}),(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:12,padding:16},children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:14,color:"#111827",marginBottom:10},children:"Homework Summary"}),0===G.length&&0===b.length?(0,l.jsx)("p",{style:{fontSize:13,color:"#9ca3af"},children:"No homework yet."}):(0,l.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap"},children:[(0,l.jsxs)("span",{style:{fontSize:13,color:"#16a34a"},children:["\u2713 ",F," done"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#dc2626"},children:["\u2717 ",_," not submitted"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#d97706"},children:[G.filter(e=>{var t;return"PENDING"===(null===(t=e.submission)||void 0===t?void 0:t.status)}).length," pending"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#2563eb"},children:[G.filter(e=>{var t;return"SUBMITTED"===(null===(t=e.submission)||void 0===t?void 0:t.status)}).length," submitted"]})]})]}),v.length>0&&(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:12,padding:16},children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:14,color:"#111827",marginBottom:10},children:"Recent Grades"}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:v.slice(0,4).map(e=>{var t,s,n;const r=null===(t=e.grades)||void 0===t?void 0:t.find(e=>e.studentId===c);return(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("p",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:[e.type," \u2014 ",(null===(s=e.group)||void 0===s?void 0:s.name)||""]}),(0,l.jsx)("p",{style:{fontSize:11,color:"#9ca3af"},children:e.date?new Date(e.date).toLocaleDateString("en-GB"):""})]}),r&&(0,l.jsx)("span",{style:{fontWeight:700,fontSize:14,color:"#1e3a5f"},children:null!=r.band?"".concat(r.band," band"):"".concat(null!==(n=r.score)&&void 0!==n?n:"\u2014")}
1)]},e.id)})})]}),S.length>0&&(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:12,padding:16},children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:14,color:"#111827",marginBottom:10},children:"Speaking Schedule"}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:S.slice(0,3).map(e=>{var t;return(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:e.title}),(0,l.jsxs)("p",{style:{fontSize:11,color:"#9ca3af"},children:[e.date?new Date(e.date).toLocaleDateString("en-GB"):"",null!==(t=e.group)&&void 0!==t&&t.name?" \xb7 ".concat(e.group.name):""]})]}),(0,l.jsxs)("span",{style:{fontWeight:700,fontSize:14,color:"#7c3aed"},children:[e.slotTime||"\u2014"," ",(0,l.jsxs)("span",{style:{fontWeight:400,fontSize:12},children:["(",e.durationMins,"min)"]})]})]},e.slotId)})})]})]}):"attendance"===u?(0,l.jsx)("div",{children:0===R.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No attendance records."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:R.map(e=>{var t,s,n;return(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",background:"#f9fafb",borderRadius:8},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:null!==(t=e.session)&&void 0!==t&&t.scheduledDate?new Date(e.session.scheduledDate).toLocaleDateString("en-GB"):e.createdAt?new Date(e.createdAt).toLocaleDateString("en-GB"):"\u2014"}),(0,l.jsxs)("p",{style:{fontSize:11,color:"#9ca3af"},children:[(null===(s=e.session)||void 0===s||null===(n=s.group)||void 0===n?void 0:n.name)||"",e.teacherNotes?" \xb7 ".concat(e.teacherNotes):""]})]}),(0,l.jsx)("span",{style:{fontSize:12,fontWeight:700,padding:"2px 8px",borderRadius:10,background:"".concat(U[e.status]||"#9ca3af","20"),color:U[e.status]||"#9ca3af"},children:e.status})]},e.id)})})}):"exams"===u?(0,l.jsx)("div",{children:0===g.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No exam results."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:g.map(e=>{var t;return(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:10,padding:"12px 14px"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("p",{style:{fontSize:14,fontWeight:700,color:"#111827"},children:e.examTitle}),(0,l.jsx)("p",{style:{fontSize:12,color:"#9ca3af"},children:e.date?new Date(e.date).toLocaleDateString("en-GB"):"\u2014"})]}),(0,l.jsxs)("div",{style:{textAlign:"right"},children:[e.absent?(0,l.jsx)("span",{style:{fontSize:13,color:"#9ca3af",fontWeight:600},children:"Absent"}):"IELTS"===e.gradingType?(0,l.jsx)("span",{style:{fontSize:16,fontWeight:700,color:"#1e3a5f"},children:null!==(t=e.score)&&void 0!==t?t:"\u2014"}):(0,l.jsx)("span",{style:{fontSize:16,fontWeight:700,color:"#1e3a5f"},children:null!=e.score?"".concat(e.score,"%"):"\u2014"}),e.rank>0&&e.totalStudents>0&&(0,l.jsxs)("p",{style:{fontSize:11,color:"#9ca3af"},children:["#",e.rank," of ",e.totalStudents]})]})]}),"IELTS"===e.gradingType&&!e.absent&&(0,l.jsx)("div",{style:{display:"flex",gap:8,marginTop:8,flexWrap:"wrap"},children:[["L",e.listeningScore],["R",e.readingScore],["W",e.writingScore],["S",e.speakingScore]].map(e=>{let[t,s]=e;return null!=s&&(0,l.jsxs)("span",{style:{fontSize:12,padding:"2px 8px",background:"#eff6ff",color:"#1d4ed8",borderRadius:8,fontWeight:600},children:[t,": ",s]},t)})})]},e.id)})})}):"homework"===u?(0,l.jsx)("div",{children:0===G.length&&0===b.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No homework assigned."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(G.length>0?G:b.map(e=>{var t,s,n,r;return{id:e.homeworkId,title:null===(t=e.homework)||void 0===t?void 0:t.t
1itle,group:null===(s=e.homework)||void 0===s?void 0:s.group,dueDate:null===(n=e.homework)||void 0===n?void 0:n.dueDate,points:null===(r=e.homework)||void 0===r?void 0:r.points,submission:e}})).map((e,t)=>{var s,n;const r=e.submission,a=r?r.status:"NOT_SUBMITTED",o=H[a]||"#9ca3af";return(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:10,padding:"12px 14px",borderLeft:"3px solid ".concat(o)},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("p",{style:{fontSize:14,fontWeight:700,color:"#111827"},children:e.title||"\u2014"}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af"},children:[(null===(s=e.group)||void 0===s?void 0:s.name)||"",e.dueDate?" \xb7 Due: ".concat(new Date(e.dueDate).toLocaleDateString("en-GB")):"",null!==r&&void 0!==r&&r.submittedAt?" \xb7 Submitted: ".concat(new Date(r.submittedAt).toLocaleDateString("en-GB")):""]})]}),(0,l.jsxs)("div",{style:{textAlign:"right",display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4},children:[(0,l.jsx)("span",{style:{fontSize:12,fontWeight:700,padding:"2px 8px",borderRadius:10,background:"".concat(o,"20"),color:o},children:"NOT_SUBMITTED"===a?"Not Submitted":a}),null!=(null===r||void 0===r?void 0:r.score)&&(0,l.jsxs)("span",{style:{fontSize:13,fontWeight:700,color:"#1e3a5f"},children:[r.score,"/",null!==(n=e.points)&&void 0!==n?n:100]})]})]}),(null===r||void 0===r?void 0:r.feedback)&&(0,l.jsxs)("p",{style:{fontSize:12,color:"#6b7280",marginTop:6,fontStyle:"italic"},children:['"',r.feedback,'"']})]},e.id||t)})})}):"grades"===u?(0,l.jsx)("div",{children:0===v.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No grade sheet entries yet."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:v.map(e=>{var t,s,n;const r=null===(t=e.grades)||void 0===t?void 0:t.find(e=>e.studentId===c),a={LISTENING:"#2563eb",READING:"#16a34a",WRITING:"#d97706",SPEAKING:"#7c3aed"}[e.type]||"#374151";return(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:10,padding:"12px 14px",borderLeft:"3px solid ".concat(a)},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[(0,l.jsx)("span",{style:{fontSize:12,fontWeight:700,padding:"1px 8px",borderRadius:10,background:"".concat(a,"20"),color:a},children:e.type}),(0,l.jsx)("p",{style:{fontSize:14,fontWeight:700,color:"#111827"},children:(null===(s=e.group)||void 0===s?void 0:s.name)||""})]}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af"},children:[e.date?new Date(e.date).toLocaleDateString("en-GB"):"",e.teacher?" \xb7 ".concat(e.teacher.firstName," ").concat(e.teacher.lastName):""]})]}),r?(0,l.jsxs)("div",{style:{textAlign:"right"},children:[(0,l.jsx)("p",{style:{fontSize:18,fontWeight:800,color:"#1e3a5f"},children:null!=r.band?"".concat(r.band):null!==(n=r.score)&&void 0!==n?n:"\u2014"}),(0,l.jsx)("p",{style:{fontSize:11,color:"#9ca3af"},children:null!=r.band?"band":"/ ".concat(e.maxScore||40)})]}):(0,l.jsx)("span",{style:{fontSize:12,color:"#9ca3af"},children:"\u2014"})]}),e.notes&&(0,l.jsx)("p",{style:{fontSize:12,color:"#6b7280",marginTop:6,fontStyle:"italic"},children:e.notes})]},e.id)})})}):"speaking"===u?(0,l.jsx)("div",{children:0===S.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No speaking schedule entries."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:S.map(e=>{var t;const s="COMPLETED"===e.status?"#16a34a":"ACTIVE"===e.status?"#2563eb":"#9ca3af";return(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:10,padding:"12px 14px",borderLeft:"3px solid #7c3aed"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontSize:14,fontWeight:700,color:"#111827"},children:e.title}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af"},children:[e.date?new Date(e.date).toLocaleDateString("en-GB",{weekday:"short",day:"2-digit",month:"short",year:"numeric"}):"",null!==(t=e.group)&&void 0!==t&&t.name?" \xb7 ".concat(e.group.name):""]})]}),(0,l.jsxs)("div",{style:{textAlign:"right"},children:[(0,l.jsx)("p",{style:{fontSize:18,fontWeight:800,color:"#7c3aed"},children:e.slotTime||"\u2014"}),(0,l.jsxs)("p",{style:{fontSize:11,color:"#9ca3af"},children:[e.durationMins," min"]})]})]}),(0,l.jsx)("span",{style:{fontSize:11,fontWeight:700,padding:"2px 8px",borderRadius:10,background:"".concat(s,"20"),color:s,marginTop:6,display:"inline-block"},children:e.status})]},e.slotId)})})}):"vocabulary"===u?(0,l.jsx)("div",{children:0===C.length?(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",paddingTop:20},children:"No vocabulary activity yet."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:C.map(e=>{const t=e.total_words||0,s=Number(e.flashcard_known_count)||0,n=Number(e.test_correct_count)||0,r=t>0?Math.round(s/t*100):0,a=t>0?Math.round(n/t*100):0,o=e=>100===e?"#059669":e>=50?"#2563eb":e>0?"#d97706":"#e5e7eb",i=e=>100===e?"#059669":e>=50?"#2563eb":e>0?"#d97706":"#9ca3af";return(0,l.jsxs)("div",{style:{background:"#f9fafb",borderRadius:10,padding:"12px 14px"},children:[(0,l.jsx)("p",{style:{fontSize:14,fontWeight:700,color:"#111827",marginBottom:2},children:e.topic_title}),(0,l.jsx)("p",{style:{fontSize:11,color:"#9ca3af",marginBottom:8},children:e.category_name||""}),[{label:"\ud83d\udcc7 Flashcards",known:s,pct:r},{label:"\ud83d\udcdd Test",known:n,pct:a}].map(e=>{let{label:s,known:n,pct:r}=e;return(0,l.jsxs)("div",{style:{marginBottom:6},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:3},children:[(0,l.jsx)("span",{style:{fontSize:12,color:"#6b7280"},children:s}),(0,l.jsxs)("span",{style:{fontSize:12,fontWeight:700,color:i(r)},children:[n,"/",t," \u2014 ",r,"%"]})]}),(0,l.jsx)("div",{style:{height:5,background:"#e5e7eb",borderRadius:9999,overflow:"hidden"},children:(0,l.jsx)("div",{style:{height:"100%",width:"".concat(r,"%"),background:o(r),borderRadius:9999}})})]},s)})]},e.topic_id)})})}):null})]})]})}function T(e){var t,s,o,i,d,c,x;let{group:u}=e;
1const[m,p]=(0,n.useState)(null),[h,g]=(0,n.useState)(null),[f,b]=(0,n.useState)(!0),[y,v]=(0,n.useState)(new Set),[j,k]=(0,n.useState)(null),[A,C]=(0,n.useState)({suggestedName:"",reason:""}),[T,E]=(0,n.useState)(""),[I,R]=(0,n.useState)(null),[D,L]=(0,n.useState)({}),[z,W]=(0,n.useState)(new Set),B=(0,n.useCallback)(async e=>{if(I!==e){if(R(e),!D[e]){W(t=>new Set(t).add(e));try{const t=await(0,r.n)("/syllabus/topics/".concat(e,"/materials")),s=await t.json();s.success&&L(t=>(0,a.A)((0,a.A)({},t),{},{[e]:s.data}))}catch(t){}W(t=>{const s=new Set(t);return s.delete(e),s})}}else R(null)},[I,D]);(0,n.useEffect)(()=>{b(!0),(0,r.n)("/syllabus/groups/".concat(u.id)).then(e=>e.json()).then(e=>{var t,s;e.success&&e.data&&(p(e.data),(null===(t=e.data.template)||void 0===t||null===(s=t.modules)||void 0===s?void 0:s.length)>0&&g(e.data.template.modules[0].id))}).finally(()=>b(!1))},[u.id]);const M=e=>{var t,s;return(null===m||void 0===m||null===(t=m.topicStatuses)||void 0===t||null===(s=t.find(t=>t.topicId===e))||void 0===s?void 0:s.status)||"NOT_STARTED"};if(f)return(0,l.jsx)("p",{style:{color:"#9ca3af",padding:20},children:"Loading syllabus..."});if(!m)return(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsx)("div",{style:{fontSize:40,marginBottom:10},children:"\ud83d\udced"}),(0,l.jsx)("p",{style:{fontWeight:600,color:"#374151"},children:"No syllabus assigned to this group yet"}),(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:13,marginTop:4},children:"Ask your admin to assign a syllabus template."})]});const P=null===(t=m.template)||void 0===t||null===(s=t.modules)||void 0===s?void 0:s.find(e=>e.id===h),O=(null===(o=m.template)||void 0===o||null===(i=o.modules)||void 0===i?void 0:i.flatMap(e=>e.topics||[]))||[],G=O.filter(e=>"DONE"===M(e.id)).length,F=O.length?Math.round(G/O.length*100):0;return(0,l.jsxs)("div",{children:[T&&(0,l.jsx)("div",{style:{padding:"10px 14px",borderRadius:8,marginBottom:12,background:"#dcfce7",color:"#166534",fontSize:13,fontWeight:500},children:T}),(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:"16px 20px",marginBottom:14,boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[(0,l.jsx)("span",{style:{fontWeight:700,fontSize:15,color:"#111827"},children:null===(d=m.template)||void 0===d?void 0:d.name}),(0,l.jsxs)("span",{style:{fontWeight:800,fontSize:22,color:"#4f46e5"},children:[F,"%"]})]}),(0,l.jsx)("div",{style:{height:8,background:"#e5e7eb",borderRadius:9999,overflow:"hidden"},children:(0,l.jsx)("div",{style:{height:"100%",width:"".concat(F,"%"),background:"linear-gradient(90deg,#6366f1,#4f46e5)",borderRadius:9999,transition:"width 0.4s"}})}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af",marginTop:5},children:[G," of ",O.length," topics covered"]})]}),(0,l.jsx)("div",{style:{display:"flex",gap:8,marginBottom:14,flexWrap:"wrap"},children:null===(c=m.template)||void 0===c||null===(x=c.modules)||void 0===x?void 0:x.map((e,t)=>{const s=e.color||w[t%w.length],n=(e.topics||[]).filter(e=>"DONE"===M(e.id)).length,r=h===e.id;return(0,l.jsxs)("button",{onClick:()=>g(e.id),style:{padding:"6px 14px",borderRadius:20,border:"none",cursor:"pointer",fontWeight:600,fontSize:13,background:r?s:"white",color:r?"white":"#374151",boxShadow:r?"0 2px 8px ".concat(s,"55"):"0 1px 3px rgba(0,0,0,0.08)",transition:"all 0.15s"},children:[e.name," ",(0,l.jsxs)("span",{style:{opacity:.8,fontSize:11},children:[n,"/",(e.topics||[]).length]})]},e.id)})}),P&&(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(()=>{const e=m.template.modules.findIndex(e=>e.id===P.id),t=P.color||w[e%w.length],s=(P.topics||[]).filter(e=>"DONE"===M(e.id)).length;return(0,l.jsxs)("div",{style:{padding:"12px 18px",background:t,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsx)("span",{style:{fontWeight:700,color:"white",fontSize:14},children:P.name}),(0,l.jsxs)("span",{style:{color:"rgba(255,255,255,0.85)",fontSize:12},children:[s,"/",(P.topics||[]).length," done"]})]})})(),(P.topics||[]).map((e,t)=>{var s,n,o;const i=M(e.id),d=S[i],c=y.has(e.id),x=I===e.id,m=D[e.id]||[],h=null!==(s=null!==(n=null===(o=e._count)||void 0===o?void 0:o.materials)&&void 0!==n?n:e.materialCount)&&void 0!==s?s:null;return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"11px 18px",borderBottom:!x&&t<P.topics.length-1?"1px solid #f3f4f6":"none",background:"DONE"===i?"#f0fdf4":"white",transition:"background 0.2s"},children:[(0,l.jsx)("span",{style:{fontSize:12,color:"#9ca3af",fontFamily:"monospace",minWidth:22},children:String(t+1).padStart(2,"0")}),(0,l.jsx)("button",{onClick:()=>!c&&(async(e,t)=>{const s=["NOT_STARTED","IN_PROGRESS","DONE"],n=s[(s.indexOf(t)+1)%s.length];v(t=>new Set(t).add(e)),p(t=>{const s=t.topicStatuses.find(t=>t.topicId===e);return(0,a.A)((0,a.A)({},t),{},{topicStatuses:s?t.topicStatuses.map(t=>t.topicId===e?(0,a.A)((0,a.A)({},t),{},{status:n}):t):[...t.topicStatuses,{topicId:e,status:n}]})}),await(0,r.n)("/syllabus/groups/".concat(u.id,"/topics/").concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:n})}).catch(()=>{}),v(t=>{const s=new Set(t);return s.delete(e),s})})(e.id,i),style:{width:30,height:30,borderRadius:"50%",border:"2px s
1olid ".concat(d.color),background:d.bg,color:d.color,cursor:c?"wait":"pointer",fontSize:13,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.15s"},title:"Click to change status",children:c?"\u2026":d.icon}),(0,l.jsx)("span",{onClick:()=>B(e.id),style:{flex:1,fontSize:14,color:"DONE"===i?"#9ca3af":"#111827",textDecoration:"DONE"===i?"line-through":"none",cursor:"pointer"},children:e.name}),(0,l.jsxs)("button",{onClick:()=>B(e.id),style:{background:x?"#eff6ff":"#f3f4f6",border:"none",borderRadius:6,padding:"3px 8px",cursor:"pointer",fontSize:11,color:x?"#3b82f6":"#6b7280",fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:3},title:"View materials",children:["\ud83d\udcce ",null!=h?h:""," ",(0,l.jsx)("span",{style:{fontSize:10},children:x?"\u25b2":"\u25bc"})]}),(0,l.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:d.bg,color:d.color,flexShrink:0},children:d.label}),(0,l.jsx)("button",{onClick:()=>{k({type:"EDIT",topic:e,moduleId:P.id,moduleName:P.name}),C({suggestedName:e.name,reason:""})},style:{background:"none",border:"1px solid #e5e7eb",borderRadius:6,padding:"3px 7px",cursor:"pointer",color:"#9ca3af",fontSize:11,flexShrink:0},title:"Suggest edit",children:"\u270f\ufe0f"})]}),x&&(0,l.jsx)("div",{style:{padding:"10px 18px 14px 64px",background:"#f9fafb",borderBottom:t<P.topics.length-1?"1px solid #f3f4f6":"none"},children:z.has(e.id)?(0,l.jsx)("p",{style:{fontSize:13,color:"#9ca3af"},children:"Loading materials..."}):0===m.length?(0,l.jsx)("p",{style:{fontSize:13,color:"#9ca3af"},children:"No materials attached to this topic."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:m.map(e=>{const t="BOOK_REFERENCE"===e.type?"\ud83d\udcd6":"PDF"===e.fileType?"\ud83d\udcc4":"WORD"===e.fileType?"\ud83d\udcdd":"HTML"===e.fileType?"\ud83c\udf10":"\ud83d\udcce",s=e.fileSize?e.fileSize<1048576?"".concat(Math.round(e.fileSize/1024)," KB"):"".concat((e.fileSize/1048576).toFixed(1)," MB"):"";return(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 12px",background:"white",borderRadius:8,border:"1px solid #e5e7eb"},children:[(0,l.jsx)("span",{style:{fontSize:18,flexShrink:0},children:t}),(0,l.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,l.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"#374151",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.title}),"BOOK_REFERENCE"===e.type&&e.book&&(0,l.jsxs)("div",{style:{fontSize:11,color:"#9ca3af"},children:[e.book.title,e.book.author?" \u2014 ".concat(e.book.author):"",e.pageFrom?" \xb7 pp. ".concat(e.pageFrom).concat(e.pageTo?"\u2013"+e.pageTo:""):""]}),"FILE"===e.type&&(0,l.jsxs)("div",{style:{fontSize:11,color:"#9ca3af"},children:[e.fileType||"File",s?" \xb7 ".concat(s):""]})]}),"FILE"===e.type&&e.fileUrl&&(!1===e.fileAvailable?(0,l.jsx)("span",{style:{padding:"4px 10px",background:"#fef2f2",color:"#ef4444",borderRadius:6,fontSize:11,fontWeight:600,flexShrink:0,border:"1px solid #fecaca"},children:"File missing"}):(0,l.jsx)("a",{href:"".concat(N.C,"/syllabus/materials/files/").concat(e.fileUrl.split("/").pop()),target:"_blank",rel:"noreferrer",style:{padding:"4px 10px",background:"#eff6ff",color:"#3b82f6",borderRadius:6,fontSize:12,fontWeight:600,textDecoration:"none",flexShrink:0,border:"1px solid #bfdbfe"},children:"View \u2197"}))]},e.id)})})})]},e.id)}),(0,l.jsx)("div",{style:{padding:"8px 18px",borderTop:"1px dashed #e5e7eb"},children:(0,l.jsxs)("button",{onClick:()=>{k({type:"ADD",moduleId:P.id,moduleName:P.name}),C({suggestedName:"",reason:""})},style:{background:"none",border:"none",color:"#4f46e5",cursor:"pointer",fontSize:13,fontWeight:600},children:["+ Suggest new topic in ",P.name]})})]}),j&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:16},children:(0,l.jsxs)("div",{style:{background:"white",borderRadius:16,padding:28,width:"100%",maxWidth:440,boxShadow:"0 20px 60px rgba(0,0,0,0.2)"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[(0,l.jsx)("h3",{style:{margin:0,fontSize:16,fontWeight:700},children:"EDIT"===j.type?"\u270f\ufe0f Suggest Edit":"\u2795 Suggest New Topic"}),(0,l.jsx)("button",{onClick:()=>k(null),style:{background:"none",border:"none",fontSize:18,cursor:"pointer",color:"#9ca3af"},children:"\u2715"})]}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af",marginBottom:12},children:["Module: ",(0,l.jsx)("strong",{children:j.moduleName}),j.topic?' \xb7 Current: "'.concat(j.topic.name,'"'):""]}),(0,l.jsx)("input",{value:A.suggestedName,onChange:e=>C(t=>(0,a.A)((0,a.A)({},t),{},{suggestedName:e.target.value})),placeholder:"EDIT"===j.type?"Corrected name...":"New topic name...",style:{width:"100%",padding:"9px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:14,boxSizing:"border-box",marginBottom:10}}),(0,l.jsx)("textarea",{value:A.reason,onChange:e=>C(t=>(0,a.A)((0,a.A)({},t),{},{reason:e.target.value})),placeholder:"Reason (optional)",rows:2,style:{width:"100%",padding:"9px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,boxSizing:"border-box",resize:"vertical",marginBottom:16}}),(0,l.jsxs)("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{onClick:()=>k(null),style:{padding:"8px 16px",background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb",borderRadius:8,cursor:"pointer",fontSize:13},children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{var e;if(!j||!A.suggestedName.trim())return;const t=await(0,r.n)("/syllabus/suggestions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({templateId:m.templateId,type:j.type,topicId:"EDIT"===j.type?null===(e=j.topic)||void 0===e?void 0:e.id:void 0,moduleId:j.moduleId,suggestedName:A.suggestedName.trim(),reason:A.reason.trim()||void 0})});(await t.json()).success&&(k(null),C({suggestedName:"",reason:""}),E("\u2705 Suggestion sent to admin"),setTimeout(()=>E(""),3e3))},disabled:!A.suggestedName.trim(),style:{padding:"8px 16px",background:"#4f46e5",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontWeight:600,fontSize:13,opacity:A.suggestedName.trim()?1:.5},children:"Send"})]})]})})]})}function E(e){let{group:t}=e;
1const[s,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!0),[c,x]=(0,n.useState)(null),[u,m]=(0,n.useState)([]),[p,h]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(0,r.n)("/exams?groupId=".concat(t.id)).then(e=>e.json()).then(e=>{e.success&&o((e.data||e.exams||[]).filter(e=>e.groupId===t.id||!e.groupId))}).catch(()=>{}).finally(()=>d(!1))},[t.id]);const g=e=>e>=80?"#16a34a":e>=65?"#2563eb":e>=50?"#d97706":"#dc2626";return i?(0,l.jsx)("p",{style:{color:"#9ca3af"},children:"Loading exams..."}):0===s.length?(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsx)("div",{style:{fontSize:36,marginBottom:8},children:"\ud83d\udccb"}),(0,l.jsx)("p",{style:{fontWeight:600,color:"#374151"},children:"No exams yet for this group"})]}):(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:c?20:0},children:s.map(e=>(0,l.jsxs)("div",{onClick:()=>(async e=>{x(e),h(!0);const t=await(0,r.n)("/exams/".concat(e.id,"/results")),s=await t.json();m(s.success&&(s.data||s.results)||[]),h(!1)})(e),style:{background:"white",borderRadius:12,padding:"14px 18px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)",border:(null===c||void 0===c?void 0:c.id)===e.id?"2px solid #4f46e5":"1px solid #f0f0f0",transition:"all 0.15s",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontWeight:700,fontSize:15,color:"#111827"},children:e.title}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#9ca3af",marginTop:2},children:[e.subject||e.type||"",e.date?" \xb7 ".concat(new Date(e.date).toLocaleDateString("en-GB")):"",e.maxScore?" \xb7 Max: ".concat(e.maxScore):""]})]}),(0,l.jsx)("span",{style:{fontSize:18,color:(null===c||void 0===c?void 0:c.id)===e.id?"#4f46e5":"#9ca3af"},children:"\u203a"})]},e.id))}),c&&(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.07)",overflow:"hidden"},children:[(0,l.jsxs)("div",{style:{padding:"12px 18px",background:"#4f46e5",color:"white",fontWeight:700,fontSize:14},children:[c.title," \u2014 Results"]}),p?(0,l.jsx)("p",{style:{padding:20,color:"#9ca3af"},children:"Loading results..."}):0===u.length?(0,l.jsx)("p",{style:{padding:20,color:"#9ca3af",fontSize:13},children:"No results recorded yet."}):(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse"},children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{style:{background:"#f9fafb"},children:[(0,l.jsx)("th",{style:D,children:"#"}),(0,l.jsx)("th",{style:D,children:"Student"}),(0,l.jsx)("th",{style:D,children:"Score"}),(0,l.jsx)("th",{style:D,children:"%"}),(0,l.jsx)("th",{style:D,children:"Grade"})]})}),(0,l.jsx)("tbody",{children:u.map((e,t)=>{var s,n,r;const o=null!==(s=null!==(n=e.totalScore)&&void 0!==n?n:e.score)&&void 0!==s?s:0,i=c.maxScore||100,d=Math.round(o/i*100),x=null!==(r=e.student)&&void 0!==r&&r.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):e.studentName||"\u2014";return(0,l.jsxs)("tr",{style:{borderBottom:"1px solid #f3f4f6"},children:[(0,l.jsx)("td",{style:L,children:t+1}),(0,l.jsx)("td",{style:L,children:x}),(0,l.jsxs)("td",{style:(0,a.A)((0,a.A)({},L),{},{fontWeight:700}),children:[o,"/",i]}),(0,l.jsxs)("td",{style:(0,a.A)((0,a.A)({},L),{},{color:g(d),fontWeight:700}),children:[d,"%"]}),(0,l.jsx)("td",{style:L,children:(0,l.jsx)("span",{style:{padding:"2px 8px",borderRadius:12,background:g(d)+"22",color:g(d),fontSize:12,fontWeight:700},children:d>=80?"A":d>=65?"B":d>=50?"C":d>=40?"D":"F"})})]},e.id)})})]})]})]})}function I(e){let{group:t}=e;const[s,a]=(0,n.useState)([]),[o,i]=(0,n.useState)(!0),[d,c]=(0,n.useState)(null),[x,u]=(0,n.use
1State)([]),[m,p]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(0,r.n)("/attendance/group/".concat(t.id,"/sessions")).then(e=>e.json()).then(e=>{e.success&&a(e.data||[])}).catch(()=>{}).finally(()=>i(!1))},[t.id]);const h={PRESENT:{bg:"#dcfce7",color:"#166534"},ABSENT:{bg:"#fee2e2",color:"#991b1b"},LATE:{bg:"#fef9c3",color:"#713f12"},EXCUSED:{bg:"#dbeafe",color:"#1e40af"},EARLY_LEAVE:{bg:"#f3e8ff",color:"#6b21a8"}};return o?(0,l.jsx)("p",{style:{color:"#9ca3af"},children:"Loading attendance..."}):(0,l.jsx)("div",{style:{display:"grid",gridTemplateColumns:s.length>0?"240px 1fr":"1fr",gap:16,alignItems:"flex-start"},children:0===s.length?(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsx)("div",{style:{fontSize:36,marginBottom:8},children:"\ud83d\udcdd"}),(0,l.jsx)("p",{style:{fontWeight:600,color:"#374151"},children:"No sessions recorded yet"})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.07)",overflow:"hidden"},children:[(0,l.jsx)("p",{style:{padding:"10px 14px",fontWeight:700,fontSize:13,color:"#374151",borderBottom:"1px solid #f3f4f6"},children:"Sessions"}),s.slice(0,30).map(e=>(0,l.jsxs)("div",{onClick:()=>(async e=>{c(e),p(!0);const t=await(0,r.n)("/attendance/sessions/".concat(e.id,"/attendance")),s=await t.json();u(s.success&&s.data||[]),p(!1)})(e),style:{padding:"10px 14px",cursor:"pointer",borderBottom:"1px solid #f9fafb",background:(null===d||void 0===d?void 0:d.id)===e.id?"#eff6ff":"white",transition:"background 0.1s"},children:[(0,l.jsx)("p",{style:{fontSize:13,fontWeight:600,color:(null===d||void 0===d?void 0:d.id)===e.id?"#2563eb":"#374151"},children:e.date?new Date(e.date).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"2-digit"}):"\u2014"}),e.topic&&(0,l.jsx)("p",{style:{fontSize:11,color:"#9ca3af",marginTop:1},children:e.topic})]},e.id))]}),(0,l.jsx)("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.07)",overflow:"hidden",minHeight:120},children:d?m?(0,l.jsx)("p",{style:{padding:24,color:"#9ca3af",fontSize:13},children:"Loading..."}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{style:{padding:"10px 16px",borderBottom:"1px solid #f3f4f6",fontWeight:700,fontSize:13,color:"#374151"},children:[new Date(d.date).toLocaleDateString("en-GB",{weekday:"long",day:"2-digit",month:"long"}),d.topic?" \u2014 ".concat(d.topic):""]}),0===x.length?(0,l.jsx)("p",{style:{padding:20,color:"#9ca3af",fontSize:13},children:"No records."}):(0,l.jsx)("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:6},children:x.map(e=>{var t;const s=h[e.status]||h.PRESENT,n=null!==(t=e.student)&&void 0!==t&&t.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):e.studentName||"\u2014";return(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"7px 12px",background:"#f9fafb",borderRadius:8},children:[(0,l.jsx)("span",{style:{fontSize:13,fontWeight:500,color:"#374151"},children:n}),(0,l.jsx)("span",{style:{fontSize:11,padding:"2px 10px",borderRadius:12,background:s.bg,color:s.color,fontWeight:700},children:e.status})]},e.id)})})]}):(0,l.jsx)("p",{style:{padding:24,color:"#9ca3af",fontSize:13,textAlign:"center"},children:"Select a session to view attendance"})})]})})}function R(e){let{group:t}=e;const[s,a]=(0,n.useState)([]),[o,i]=(0,n.useState)(!0);(0,n.useEffect)(()=>{(0,r.n)("/comments?groupId=".concat(t.id,"&limit=50")).then(e=>e.json()).then(e=>{e.success&&a(e.data||e.comments||[])}).catch(()=>{}).finally(()=>i(!1))},[t.id]);const d={POSITIVE:{bg:"#dcfce7",color:"#166534"},NEUTRAL:{bg:"#f3f4f6",color:"#374151"},NEEDS_WORK:{bg:"#fef3c7",color:"#92400e"},BEHAVIORAL:{bg:"#fee2e2",color:"#991b1b"},ACADEMIC:{bg:"#dbeafe",color:"#1e40af"},ATTENDANCE:{bg:"#f3e8ff",color:"#6b21a8"}};return o?(0,l.jsx)("p",{style:{color:"#9ca3af"},children:"Loading comments..."}):0===s.length?(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsx)("div",{style:{fontSize:36,marginBottom:8},children:"\ud83d\udcac"}),(0,l.jsx)("p",{style:{fontWeight:600,color:"#374151"},children:"No comments yet for this group"})]}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:s.map(e=>{var t;const s=d[e.category]||d.NEUTRAL,n=null!==(t=e.student)&&void 0!==t&&t.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):e.studentName||"\u2014";return(0,l.jsxs)("div",{style:{background:"white",borderRadius:12,padding:"14px 18px",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:6},children:[(0,l.jsx)("span",{style:{fontWeight:700,fontSize:14,color:"#111827"},children:n}),(0,l.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[(0,l.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:s.bg,color:s.color,fontWeight:700},children:e.category}),(0,l.jsx)("span",{style:{fontSize:11,color:"#9ca3af"},children:e.createdAt?new Date(e.createdAt).toLocaleDateString("en-GB"):""})]})]}),(0,l.jsx)("p",{style:{fontSize:13,color:"#374151",lineHeight:1.5},children:e.text})]},e.id)})})}const D={padding:"10px 14px",textAlign:"left",fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase",letterSpacing:"0.04em"},L={padding:"10px 14px",fontSize:13,color:"#374151",borderBottom:"1px solid #f3f4f6"},z=[{value:"GRAMMAR",label:"Grammar"},{value:"VOCABULARY",label:"Vocabulary"},{value:"PRONUNCIATION",label:"Pronunciation"},{value:"FLUENCY",label:"Fluency"},{value:"TASK_RESPONSE",label:"Task Response"},{value:"COHERENCE",label:"Coherence"}],W={GRAMMAR:"#fef2f2 #dc2626",VOCABULARY:"#faf5ff #7c3aed",PRONUNCIATION:"#fdf2f8 #be185d",FLUENCY:"#fff7ed #c2410c",TASK_RESPONSE:"#fefce8 #a16207",COHERENCE:"#eef2ff #4338ca"};function B(e){const t=(W[e]||"#f3f4f6 #6b7280").split(" ");return{backgroundColor:t[0],color:t[1]}}function M(e){let{sessionId:t,students:s,onLogged:a}=e;
1const[o,i]=(0,n.useState)(""),[d,c]=(0,n.useState)("GRAMMAR"),[x,u]=(0,n.useState)(""),[m,p]=(0,n.useState)(""),[h,g]=(0,n.useState)(!1),[f,b]=(0,n.useState)(""),y=async()=>{if(o&&x.trim()){g(!0);try{await(0,r.n)("/srs/errors",{method:"POST",body:JSON.stringify({sessionId:t,studentId:o,errorText:x,category:d,correction:m||void 0})}),u(""),p(""),b("Logged"),setTimeout(()=>b(""),2e3),a()}catch(e){b("Error: "+(e.message||"failed"))}finally{g(!1)}}};return(0,l.jsxs)("div",{style:{padding:"0.75rem 1rem",backgroundColor:"#fffbeb",borderTop:"1px solid #fde68a",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,l.jsx)("p",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#92400e",marginBottom:"0.25rem"},children:"\u26a0\ufe0f Log Error"}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[(0,l.jsxs)("select",{value:o,onChange:e=>i(e.target.value),style:{flex:"1 1 180px",fontSize:"0.8rem",border:"1px solid #d97706",borderRadius:"0.375rem",padding:"0.3rem 0.5rem",outline:"none",minWidth:"140px"},children:[(0,l.jsx)("option",{value:"",children:"\u2014 Select student \u2014"}),s.map(e=>(0,l.jsx)("option",{value:e.profileId,children:e.name},e.profileId))]}),(0,l.jsx)("select",{value:d,onChange:e=>c(e.target.value),style:{flex:"1 1 130px",fontSize:"0.8rem",border:"1px solid #d97706",borderRadius:"0.375rem",padding:"0.3rem 0.5rem",outline:"none"},children:z.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,l.jsx)("input",{value:x,onChange:e=>u(e.target.value),placeholder:"What they said / wrote incorrectly\u2026",style:{fontSize:"0.82rem",border:"1px solid #d97706",borderRadius:"0.375rem",padding:"0.3rem 0.6rem",outline:"none",width:"100%"},onKeyDown:e=>"Enter"===e.key&&!e.shiftKey&&y()}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem"},children:[(0,l.jsx)("input",{value:m,onChange:e=>p(e.target.value),placeholder:"Correct form (optional)\u2026",style:{flex:1,fontSize:"0.82rem",border:"1px solid #d97706",borderRadius:"0.375rem",padding:"0.3rem 0.6rem",outline:"none"},onKeyDown:e=>"Enter"===e.key&&y()}),(0,l.jsx)("button",{onClick:y,disabled:h||!o||!x.trim(),style:{padding:"0.3rem 1rem",backgroundColor:!h&&o&&x.trim()?"#d97706":"#fde68a",color:"white",border:"none",borderRadius:"0.375rem",fontSize:"0.82rem",fontWeight:"600",cursor:!h&&o&&x.trim()?"pointer":"not-allowed"},children:h?"\u2026":"Log"}),f&&(0,l.jsxs)("span",{style:{fontSize:"0.8rem",color:"Logged"===f?"#059669":"#dc2626",alignSelf:"center",fontWeight:"600"},children:["Logged"===f?"\u2713 ":"\u26a0 ",f]})]})]})}function P(e){let{sessionId:t}=e;const[s,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{(async()=>{try{const e=await(0,r.n)("/srs/errors/session/".concat(t));o(e.data||[])}catch(e){console.error(e)}finally{d(!1)}})()},[t]),i?(0,l.jsx)("p",{style:{fontSize:"0.78rem",color:"#9ca3af",padding:"0.5rem 1rem"},children:"Loading\u2026"}):s.length?(0,l.jsx)("div",{style:{maxHeight:"140px",overflowY:"auto",padding:"0.25rem 1rem 0.5rem"},children:s.map(e=>{var t,s,n,r;return(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-start",padding:"0.35rem 0",borderBottom:"1px solid #f3f4f6"},children:[(0,l.jsx)("span",{style:(0,a.A)((0,a.A)({},B(e.category)),{},{fontSize:"0.65rem",padding:"0.1rem 0.4rem",borderRadius:"0.25rem",fontWeight:"700",whiteSpace:"nowrap",flexShrink:0}),children:e.category}),(0,l.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,l.jsxs)("span",{style:{fontSize:"0.78rem",color:"#374151",fontWeight:"600"},children:[null===(t=e.student)||void 0===t||null===(s=t.user)||void 0===s?void 0:s.firstName," ",null===(n=e.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.lastName]}),(0,l.jsxs)("span",{style:{fontSize:"0.75rem",color:"#6b7280",marginLeft:"0.4rem"},children:["\u2014 ",e.errorText]}),e.correction&&(0,l.jsxs)("span",{style:{fontSize:"0.75rem",color:"#059669",marginLeft:"0.4rem"},children:["\u2192 ",e.correction]})]})]},e.id)})}):(0,l.jsx)("p",{style:{fontSize:"0.78rem",color:"#9ca3af",padding:"0.5rem 1rem"},children:"No errors logged yet."})}function O(e){let{sessionId:t,students:s}=e;
1const[r,a]=(0,n.useState)(!1),[o,i]=(0,n.useState)(0);return(0,l.jsxs)("div",{style:{borderTop:"1px solid #f3f4f6"},children:[(0,l.jsxs)("button",{onClick:()=>a(e=>!e),style:{width:"100%",padding:"0.5rem 1rem",display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:r?"#fffbeb":"#fff",border:"none",cursor:"pointer",fontSize:"0.82rem",fontWeight:"600",color:"#92400e"},children:[(0,l.jsxs)("span",{children:["\u26a0\ufe0f Error Log ",o>0&&(0,l.jsx)("span",{style:{background:"#fde68a",color:"#92400e",borderRadius:"9999px",padding:"0.1rem 0.45rem",fontSize:"0.7rem",marginLeft:"0.4rem"},children:o})]}),(0,l.jsx)("span",{style:{color:"#d97706",fontSize:"0.75rem"},children:r?"\u25b2 Close":"\u25bc Open"})]}),r&&(0,l.jsxs)("div",{children:[(0,l.jsx)(P,{sessionId:t},o),(0,l.jsx)(M,{sessionId:t,students:s,onLogged:()=>i(e=>e+1)})]})]})}const G={PRESENT:{bg:"#d1fae5",color:"#065f46",border:"#6ee7b7"},ABSENT:{bg:"#fee2e2",color:"#991b1b",border:"#fca5a5"},LATE:{bg:"#fef9c3",color:"#713f12",border:"#fde68a"},EXCUSED:{bg:"#dbeafe",color:"#1e40af",border:"#93c5fd"}},F=[{value:"WELL_PREPARED",label:"\u2705 Well prepared"},{value:"NOT_FULLY_PREPARED",label:"\u26a0\ufe0f Not fully"},{value:"NOT_PREPARED",label:"\u274c Not prepared"}],_=["PRESENT","ABSENT","LATE","EXCUSED"];function U(e){let{session:t,group:s,onClose:o,onUpdated:i}=e;
1const[d,c]=(0,n.useState)([]),[x,u]=(0,n.useState)(new Set),[m,p]=(0,n.useState)(!0),[h,g]=(0,n.useState)({}),[f,b]=(0,n.useState)({}),[y,v]=(0,n.useState)({}),[j,N]=(0,n.useState)(!1),[S,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)("");(0,n.useEffect)(()=>{Promise.all([(0,r.n)("/attendance/sessions/".concat(t.id,"/attendance")).then(e=>e.json()),(0,r.n)("/groups/".concat(s.id,"/roster")).then(e=>e.json())]).then(e=>{let[t,s]=e;const n=Array.isArray(t.data)?t.data:[],r={ABSENT:0,LATE:1,EXCUSED:2,PRESENT:3};n.sort((e,t)=>{var s,n;return(null!==(s=r[e.status])&&void 0!==s?s:9)-(null!==(n=r[t.status])&&void 0!==n?n:9)}),c(n);const a={},l={},o={};n.forEach(e=>{a[e.id]=e.status,l[e.id]=e.preparation||"",o[e.id]=e.notes||""}),g(a),b(l),v(o),u(new Set((s.data||[]).map(e=>e.id)))}).finally(()=>p(!1))},[t.id,s.id]);const C=t.date?new Date(t.date).toLocaleDateString("en-GB",{weekday:"long",day:"2-digit",month:"short",year:"numeric"}):"Session #".concat(t.sessionNumber);return(0,l.jsx)("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1100},children:(0,l.jsxs)("div",{style:{backgroundColor:"white",borderRadius:"0.75rem",width:"98%",maxWidth:"860px",maxHeight:"90vh",display:"flex",flexDirection:"column",boxShadow:"0 24px 64px rgba(0,0,0,0.25)"},children:[(0,l.jsxs)("div",{style:{padding:"1.25rem 1.5rem",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("h2",{style:{fontSize:"1.1rem",fontWeight:"700",color:"#002147",marginBottom:"0.2rem"},children:["\u270f\ufe0f Edit Attendance \u2014 ",s.name]}),(0,l.jsxs)("p",{style:{fontSize:"0.8rem",color:"#6b7280"},children:[C," \xb7 Session #",t.sessionNumber]})]}),(0,l.jsx)("button",{onClick:o,style:{background:"none",border:"none",fontSize:"1.5rem",cursor:"pointer",color:"#9ca3af",lineHeight:1},children:"\xd7"})]}),(0,l.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"0.75rem 1rem"},children:m?(0,l.jsx)("p",{style:{textAlign:"center",padding:"2rem",color:"#9ca3af"},children:"Loading\u2026"}):0===d.length?(0,l.jsx)("p",{style:{textAlign:"center",padding:"2rem",color:"#9ca3af"},children:"No attendance records found."}):(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"0.85rem"},children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{style:{backgroundColor:"#002147",color:"white"},children:[(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"left",fontWeight:"600",fontSize:"0.75rem"},children:"#"}),(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"left",fontWeight:"600",fontSize:"0.75rem"},children:"Student"}),(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"center",fontWeight:"600",fontSize:"0.75rem"},children:"Status"}),(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"center",fontWeight:"600",fontSize:"0.75rem"},children:"Preparation"}),(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"left",fontWeight:"600",fontSize:"0.75rem"},children:"Notes"})]})}),(0,l.jsx)("tbody",{children:d.map((e,t)=>{var s,n;const r=h[e.id]||e.status,o=null!==(s=e.student)&&void 0!==s&&s.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):e.studentId,i=(null===(n=e.student)||void 0===n?void 0:n.id)&&!x.has(e.student.id);return(0,l.jsxs)("tr",{style:{borderBottom:"1px solid #f3f4f6",backgroundColor:t%2===0?"white":"#fafafa"},children:[(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem",color:"#9ca3af",fontSize:"0.75rem"},children:t+1}),(0,l.jsxs)("td",{style:{padding:"0.6rem 0.75rem",fontWeight:"600",color:i?"#9ca3af":"#111827"},children:[o,i&&(0,l.jsx)("span",{style:{marginLeft:"0.4rem",fontSize:"0.65rem",color:"#9ca3af",fontStyle:"italic",fontWeight:"400",background:"#f3f4f6",padding:"0.1rem 0.35rem",borderRadius:"0.25rem"},children:"moved"})]}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:(0,l.jsx)("div",{style:{display:"flex",gap:"0.3rem",justifyContent:"center",flexWrap:"wrap"},children:_.map(t=>(0,l.jsx)("button",{onClick:()=>g(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t})),style:{padding:"0.2rem 0.45rem",borderRadius:"0.375rem",fontSize:"0.7rem",cursor:"pointer",fontWeight:r===t?"700":"400",backgroundColor:r===t?G[t].bg:"#f9fafb",color:r===t?G[t].color:"#6b7280",border:r===t?"2px solid ".concat(G[t].border):"1px solid #e5e7eb"},children:t.charAt(0)+t.slice(1).toLowerCase()},t))})}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:"ABSENT"===r?(0,l.jsx)("span",{style:{fontSize:"0.72rem",color:"#d1d5db",fontStyle:"italic"},children:"N/A"}):(0,l.jsxs)("select",{value:f[e.id]||"",onChange:t=>b(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t.target.value})),style:{fontSize:"0.75rem",border:"1px solid #e5e7eb",borderRadius:"0.375rem",padding:"0.25rem 0.4rem",outline:"none",cursor:"pointer",backgroundColor:"NOT_PREPARED"===f[e.id]?"#fef2f2":"NOT_FULLY_PREPARED"===f[e.id]?"#fefce8":"WELL_PREPARED"===f[e.id]?"#f0fdf4":"white"},children:[(0,l.jsx)("option",{value:"",children:"\u2014 prep \u2014"}),F.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))]})}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:(0,l.jsx)("input",{value:y[e.id]||"",onChange:t=>v(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t.target.value})),placeholder:"Optional note\u2026",style:{width:"100%",fontSize:"0.78rem",border:"1px solid #e5e7eb",borderRadius:"0.375rem",padding:"0.25rem 0.5rem",outline:"none",minWidth:"120px"}})})]},e.id)})})]})}),!m&&d.length>0&&(0,l.jsx)(O,{sessionId:t.id,students:d.filter(e=>{var t;return null===(t=e.student)||void 0===t?void 0:t.id}).map(e=>{var t;return{profileId:e.student.id,name:null!==(t=e.student)&&void 0!==t&&t.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):e.studentId}})}),(0,l.jsxs)("div",{style:{padding:"1rem 1.5rem",borderTop:"1px solid #f3f4f6",display:"flex",alignItems:"center",gap:"0.75rem",flexWrap:"wrap"},children:[(0,l.jsx)("button",{onClick:async()=>{N(!0),A("");try{const e=d.map(e=>({studentId:e.student.studentId,status:h[e.id]||e.status,preparation:f[e.id]||null,notes:y[e.id]||""})),n=await(0,r.n)("/attendance/submit",{method:"POST",body:JSON.stringify({groupId:s.id,date:t.date,attendanceRecords:e})}),a=await n.json();a.success?(A("\u2705 Saved!"),i(),setTimeout(o,900)):A(a.message||"Error saving")}catch(e){A("Network error")}finally{N(!1)}},disabled:j||m,style:{padding:"0.5rem 1.5rem",backgroundColor:"#002147",color:"white",border:"none",borderRadius:"0.5rem",cursor:j?"not-allowed":"pointer",fontWeight:"600",fontSize:"0.875rem",opacity:j?.6:1},children:j?"Saving\u2026":"\ud83d\udcbe Save Changes"}),(0,l.jsx)("button",{onClick:async()=>{w(!0),A("");try{const e=await(0,r.n)("/attendance/sessions/".concat(t.id,"/send-telegram"),{method:"POST"}),s=await e.json();A(s.success?"\ud83d\udce4 Sent to Telegram!":"\u274c "+(s.message||"Failed"))}catch(e){A("\u274c Network error")}finally{w(!1)}},disabled:S,style:{padding:"0.5rem 1.25rem",backgroundColor:"#0088cc",color:"white",border:"none",borderRadius:"0.5rem",cursor:S?"not-allowed":"pointer",fontWeight:"600",fontSize:"0.875rem",opacity:S?.6:1},children:S?"Sending\u2026":"\ud83d\udce4 Send to Telegram"}),(0,l.jsx)("button",{onClick:o,style:{padding:"0.5rem 1.25rem",backgroundColor:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb",borderRadius:"0.5rem",cursor:"pointer",fontSize:"0.875rem"},children:"Cancel"}),k&&(0,l.jsx)("span",{style:{fontSize:"0.875rem",fontWeight:"500",color:k.startsWith("\u2705")||k.startsWith("\ud83d\udce4")?"#10b981":"#ef4444"},children:k})]})]})})}function H(e){let{group:t,onClose:s,onSaved:o}=e;
1const i=(new Date).toISOString().split("T")[0],[d,c]=(0,n.useState)(i),[x,u]=(0,n.useState)([]),[m,p]=(0,n.useState)({}),[h,g]=(0,n.useState)({}),[f,b]=(0,n.useState)({}),[y,v]=(0,n.useState)(!0),[j,N]=(0,n.useState)(!1),[S,w]=(0,n.useState)(null),[k,A]=(0,n.useState)(!1),[C,T]=(0,n.useState)("");(0,n.useEffect)(()=>{(0,r.n)("/groups/".concat(t.id,"/roster")).then(e=>e.json()).then(e=>{const t=e.data||[];u(t);const s={},n={},r={};t.forEach(e=>{s[e.id]="PRESENT",n[e.id]="",r[e.id]=""}),p(s),g(n),b(r)}).finally(()=>v(!1))},[t.id]);const E=Object.values(m).filter(e=>"PRESENT"===e).length,I=Object.values(m).filter(e=>"ABSENT"===e).length;return(0,l.jsx)("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1100},children:(0,l.jsxs)("div",{style:{backgroundColor:"white",borderRadius:"0.75rem",width:"98%",maxWidth:"860px",maxHeight:"92vh",display:"flex",flexDirection:"column",boxShadow:"0 24px 64px rgba(0,0,0,0.25)"},children:[(0,l.jsxs)("div",{style:{padding:"1.25rem 1.5rem",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("h2",{style:{fontSize:"1.1rem",fontWeight:"700",color:"#002147",marginBottom:"0.25rem"},children:["\ud83d\udcdd Take Attendance \u2014 ",t.name]}),(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",flexWrap:"wrap"},children:[(0,l.jsx)("input",{type:"date",value:d,onChange:e=>c(e.target.value),style:{fontSize:"0.85rem",border:"1px solid #d1d5db",borderRadius:"6px",padding:"0.25rem 0.5rem"}}),!y&&(0,l.jsxs)("span",{style:{fontSize:"0.78rem",color:"#6b7280"},children:[(0,l.jsxs)("span",{style:{color:"#10b981",fontWeight:"700"},children:[E," present"]}),I>0&&(0,l.jsxs)("span",{style:{color:"#ef4444",fontWeight:"700"},children:[" \xb7 ",I," absent"]})," \xb7 ",x.length," total"]})]})]}),(0,l.jsx)("button",{onClick:s,style:{background:"none",border:"none",fontSize:"1.5rem",cursor:"pointer",color:"#9ca3af"},children:"\xd7"})]}),!y&&x.length>0&&(0,l.jsxs)("div",{style:{padding:"0.6rem 1.5rem",borderBottom:"1px solid #f3f4f6",display:"flex",gap:"0.5rem",alignItems:"center"},children:[(0,l.jsx)("span",{style:{fontSize:"0.75rem",color:"#9ca3af",marginRight:"0.25rem"},children:"Mark all:"}),_.map(e=>(0,l.jsx)("button",{onClick:()=>{return t=e,p(e=>Object.fromEntries(Object.keys(e).map(e=>[e,t])));var t},style:{padding:"0.2rem 0.6rem",borderRadius:"0.375rem",fontSize:"0.72rem",cursor:"pointer",fontWeight:"600",backgroundColor:G[e].bg,color:G[e].color,border:"1px solid ".concat(G[e].border)},children:e.charAt(0)+e.slice(1).toLowerCase()},e))]}),(0,l.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"0.75rem 1rem"},children:y?(0,l.jsx)("p",{style:{textAlign:"center",padding:"2rem",color:"#9ca3af"},children:"Loading students\u2026"}):0===x.length?(0,l.jsx)("p",{style:{textAlign:"center",padding:"2rem",color:"#9ca3af"},children:"No students enrolled in this group."}):(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"0.85rem"},children:[(0,l.jsx)("thead",{children:(0,l.jsx)("tr",{style:{backgroundColor:"#002147",color:"white"},children:["#","Student","Status","Preparation","Notes"].map(e=>(0,l.jsx)("th",{style:{padding:"0.6rem 0.75rem",textAlign:"Status"===e?"center":"left",fontWeight:"600",fontSize:"0.75rem"},children:e},e))})}),(0,l.jsx)("tbody",{children:x.map((e,t)=>{var s,n;const r=m[e.id]||"PRESENT",o="".concat(e.firstName||(null===(s=e.user)||void 0===s?void 0:s.firstName)||""," ").concat(e.lastName||(null===(n=e.user)||void 0===n?void 0:n.lastName)||"").trim();return(0,l.jsxs)("tr",{style:{borderBottom:"1px solid #f3f4f6",backgroundColor:t%2===0?"white":"#fafafa"},children:[(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem",color:"#9ca3af",fontSize:"0.75rem"},children:t+1}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem",fontWeight:"600",color:"#111827"},children:o}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:(0,l.jsx)("div",{style:{display:"flex",gap:"0.3rem",justifyContent:"center",flexWrap:"wrap"},children:_.map(t=>(0,l.jsx)("button",{onClick:()=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t})),style:{padding:"0.2rem 0.45rem",borderRadius:"0.375rem",fontSize:"0.7rem",cursor:"pointer",fontWeight:r===t?"700":"400",backgroundColor:r===t?G[t].bg:"#f9fafb",color:r===t?G[t].color:"#6b7280",border:r===t?"2px solid ".concat(G[t].border):"1px solid #e5e7eb"},children:t.charAt(0)+t.slice(1).toLowerCase()},t))})}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:"ABSENT"===r?(0,l.jsx)("span",{style:{fontSize:"0.72rem",color:"#d1d5db",fontStyle:"italic"},children:"N/A"}):(0,l.jsxs)("select",{value:h[e.id]||"",onChange:t=>g(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t.target.value})),style:{fontSize:"0.75rem",border:"1px solid #e5e7eb",borderRadius:"0.375rem",padding:"0.25rem 0.4rem",outline:"none",cursor:"pointer",backgroundColor:"NOT_PREPARED"===h[e.id]?"#fef2f2":"NOT_FULLY_PREPARED"===h[e.id]?"#fefce8":"WELL_PREPARED"===h[e.id]?"#f0fdf4":"white"},children:[(0,l.jsx)("option",{value:"",children:"\u2014 prep \u2014"}),F.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))]})}),(0,l.jsx)("td",{style:{padding:"0.6rem 0.75rem"},children:(0,l.jsx)("input",{value:f[e.id]||"",onChange:t=>b(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t.target.value})),placeholder:"Optional note\u2026",style:{width:"100%",fontSize:"0.78rem",border:"1px solid #e5e7eb",borderRadius:"0.375rem",padding:"0.25rem 0.5rem",outline:"none",minWidth:"120px"}})})]},e.id)})})]})}),(0,l.jsxs)("div",{style:{padding:"1rem 1.5rem",borderTop:"1px solid #f3f4f6",display:"flex",alignItems:"center",gap:"0.75rem",flexWrap:"wrap"},children:[(0,l.jsx)("button",{onClick:async()=>
1{if(d){N(!0),T("");try{const n=await(0,r.n)("/attendance/submit",{method:"POST",body:JSON.stringify({groupId:t.id,date:d,attendanceRecords:x.map(e=>({studentId:e.studentId,status:m[e.id]||"PRESENT",preparation:h[e.id]||null,notes:f[e.id]||""}))})}),a=await n.json();var e,s;if(a.success)w((null===(e=a.data)||void 0===e||null===(s=e.session)||void 0===s?void 0:s.id)||null),T("\u2705 Saved!"),o();else T(a.message||"Error saving")}catch(n){T("Network error")}finally{N(!1)}}else T("Please select a date")},disabled:j||y||!!S,style:{padding:"0.5rem 1.5rem",backgroundColor:"#002147",color:"white",border:"none",borderRadius:"0.5rem",cursor:j||S?"not-allowed":"pointer",fontWeight:"600",fontSize:"0.875rem",opacity:j||S?.5:1},children:j?"Saving\u2026":"\ud83d\udcbe Save Attendance"}),S&&(0,l.jsx)("button",{onClick:async()=>{A(!0),T("");try{const e=await(0,r.n)("/attendance/sessions/".concat(S,"/send-telegram"),{method:"POST"}),t=await e.json();T(t.success?"\ud83d\udce4 Sent to Telegram!":"\u274c "+(t.message||"Failed"))}catch(e){T("\u274c Network error")}finally{A(!1)}},disabled:k,style:{padding:"0.5rem 1.25rem",backgroundColor:"#0088cc",color:"white",border:"none",borderRadius:"0.5rem",cursor:k?"not-allowed":"pointer",fontWeight:"600",fontSize:"0.875rem",opacity:k?.6:1},children:k?"Sending\u2026":"\ud83d\udce4 Send to Telegram"}),(0,l.jsx)("button",{onClick:s,style:{padding:"0.5rem 1.25rem",backgroundColor:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb",borderRadius:"0.5rem",cursor:"pointer",fontSize:"0.875rem"},children:S?"Close":"Cancel"}),C&&(0,l.jsx)("span",{style:{fontSize:"0.875rem",fontWeight:"500",color:C.startsWith("\u2705")||C.startsWith("\ud83d\udce4")?"#10b981":"#ef4444"},children:C})]})]})})}function V(e){let{group:t,onBack:s}=e;const[a,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!0),[c,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!1),p=()=>{d(!0),(0,r.n)("/attendance/group/".concat(t.id,"/sessions")).then(e=>e.json()).then(e=>{e.success&&o(e.data||[])}).finally(()=>d(!1))};return(0,n.useEffect)(()=>{p()},[t.id]),(0,l.jsxs)("div",{children:[(0,l.jsx)("button",{onClick:s,className:"mb-4 text-sm text-[#708090] hover:text-[#002147] flex items-center gap-1",children:"\u2190 Back to groups"}),(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsx)("h3",{className:"text-lg font-bold text-[#002147]",children:t.name}),(0,l.jsx)("button",{onClick:()=>m(!0),style:{padding:"0.4rem 1rem",backgroundColor:"#002147",color:"white",border:"none",borderRadius:"0.5rem",cursor:"pointer",fontWeight:"600",fontSize:"0.85rem"},children:"\ud83d\udcdd Take Attendance"})]}),(0,l.jsxs)("p",{className:"text-sm text-[#708090] mb-5",children:[t.groupCode," \xb7 ",t.level," \xb7 Sessions history"]}),i?(0,l.jsx)("p",{className:"text-[#708090] text-sm",children:"Loading sessions\u2026"}):0===a.length?(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-100 p-10 text-center",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udced"}),(0,l.jsx)("p",{className:"text-[#708090] font-medium",children:"No sessions recorded yet."}),(0,l.jsx)("p",{className:"text-sm text-gray-400 mt-1",children:'Click "Take Attendance" above to record the first session.'})]}):(0,l.jsx)("div",{className:"bg-white rounded-xl shadow border border-gray-100 overflow-hidden",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-[#002147] text-white",children:(0,l.jsx)("tr",{children:["#","Date","Total","Present","Absent","Late","Rate",""].map(e=>(0,l.jsx)("th",{className:"px-4 py-3 text-left text-xs font-semibold",children:e},e))})}),(0,l.jsx)("tbody",{children:a.map((e,t)=>{const s=null===e.rate?"#9ca3af":e.rate>=80?"#10b981":e.rate>=60?"#f59e0b":"#ef4444";return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsxs)("td",{className:"px-4 py-3 text-[#708090]",children:["#",e.sessionNumber]}),(0,l.jsx)("td",{className:"px-4 py-3 text-gray-700 whitespace-nowrap",children:e.date?new Date(e.date).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"\u2014"}),(0,l.jsx)("td",{className:"px-4 py-3 text-gray-700",children:e.total}),(0,l.jsx)("td",{className:"px-4 py-3 text-green-600 font-semibold",children:e.present}),(0,l.jsx)("td",{className:"px-4 py-3",children:e.absent>0?(0,l.jsx)("span",{className:"text-red-600 font-bold",children:e.absent}):(0,l.jsx)("span",{className:"text-gray-300",children:"0"})}),(0,l.jsx)("td",{className:"px-4 py-3 text-yellow-600 font-semibold",children:e.late}),(0,l.jsx)("td",{className:"px-4 py-3",children:null!==e.rate?(0,l.jsxs)("span",{style:{color:s},className:"font-bold text-xs",children:[e.rate,"%"]}):(0,l.jsx)("span",{className:"text-gray-300 text-xs",children:"\u2014"})}),(0,l.jsx)("td",{className:"px-4 py-3",children:(0,l.jsx)("button",{onClick:()=>x(e),style:{padding:"0.25rem 0.65rem",borderRadius:"0.375rem",fontSize:"0.75rem",fontWeight:"600",cursor:"pointer",backgroundColor:e.absent>0?"#fef9c3":"#f9fafb",color:e.absent>0?"#713f12":"#6b7280",border:e.absent>0?"1px solid #fde68a":"1px solid #e5e7eb"},children:e.absent>0?"\u270f\ufe0f Edit":"\ud83d\udc41 View"})})]},e.id)})})]})}),c&&(0,l.jsx)(U,{session:c,group:t,onClose:()=>x(null),onUpdated:p}),u&&(0,l.jsx)(H,{group:t,onClose:()=>m(!1),onSaved:p})]})}
1function Y(){const[e,t]=(0,n.useState)([]),[s,a]=(0,n.useState)(!1),[o,i]=(0,n.useState)(null);return(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&t(e.data||[])}).finally(()=>a(!0))},[]),s?0===e.length?(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147] mb-6",children:"\ud83d\udcdd Attendance"}),(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow border border-gray-100 p-12 text-center",children:[(0,l.jsx)("div",{className:"text-5xl mb-3",children:"\ud83d\udced"}),(0,l.jsx)("p",{className:"text-[#708090] font-medium",children:"No groups assigned to you yet."})]})]}):(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147] mb-2",children:"\ud83d\udcdd Attendance"}),(0,l.jsx)("p",{className:"text-sm text-[#708090] mb-6",children:"Select a group to view sessions and edit attendance, preparation and notes."}),o?(0,l.jsx)(V,{group:o,onBack:()=>i(null)}):(0,l.jsx)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:e.map(e=>{var t,s;return(0,l.jsxs)("button",{onClick:()=>i(e),className:"text-left bg-white rounded-xl border border-gray-100 shadow-sm p-4 hover:border-[#002147] hover:shadow-md transition-all",children:[(0,l.jsx)("div",{className:"font-semibold text-[#002147] mb-1",children:e.name}),(0,l.jsxs)("div",{className:"text-xs text-[#708090]",children:[e.groupCode," \xb7 ",e.level]}),(0,l.jsxs)("div",{className:"text-xs text-gray-400 mt-1",children:[null!==(t=null===(s=e._count)||void 0===s?void 0:s.enrollments)&&void 0!==t?t:0," students"]})]},e.id)})})]}):(0,l.jsx)("div",{className:"p-8 text-[#708090]",children:"Loading groups..."})}var q=s(9107);const J=["GENERAL","IELTS_LISTENING","IELTS_READING","IELTS_WRITING","IELTS_SPEAKING","ASSESSMENT"],K={GENERAL:"General",IELTS_LISTENING:"IELTS Listening",IELTS_READING:"IELTS Reading",IELTS_WRITING:"Writing Task 2",IELTS_SPEAKING:"IELTS Speaking",ASSESSMENT:"Assessment"},Q={GENERAL:"border-l-gray-400",IELTS_LISTENING:"border-l-blue-500",IELTS_READING:"border-l-green-500",IELTS_WRITING:"border-l-teal-500",IELTS_SPEAKING:"border-l-purple-500",ASSESSMENT:"border-l-orange-500"},X={ACTIVE:"bg-green-100 text-green-700",CLOSED:"bg-gray-100 text-gray-600",GRADED:"bg-blue-100 text-blue-700"},Z=e=>e>=8?"#10b981":e>=7?"#3b82f6":e>=6?"#f59e0b":e>=5?"#ef4444":"#6b7280",$=e=>{if(null==e)return"\u2014";const t=Math.floor(e/60),s=e%60;return t>0?"".concat(t,"m ").concat(s,"s"):"".concat(s,"s")};function ee(e){var t,s,o,i,d,c,x,u,m,p,h,g,f,b,y,v,j,N,S,w,k,A,C,T,E,I,R,D,L,z,W,B,M,P,O,G,F,_,U,H;let{sub:V,onClose:Y,onSaved:q}=e;const J=n.useRef(null),[K,Q]=n.useState((null===(t=V.aiFeedback)||void 0===t||null===(s=t.teacher)||void 0===s?void 0:s.annotations)||[]),[X,$]=n.useState(null),[ee,te]=n.useState(""),[se,ne]=n.useState({tr:String(null!==(o=null!==(i=null===(d=V.aiFeedback)||void 0===d||null===(c=d.teacher)||void 0===c?void 0:c.tr)&&void 0!==i?i:null===(x=V.aiFeedback)||void 0===x||null===(u=x.ai)||void 0===u?void 0:u.tr)&&void 0!==o?o:""),cc:String(null!==(m=null!==(p=null===(h=V.aiFeedback)||void 0===h||null===(g=h.teacher)||void 0===g?void 0:g.cc)&&void 0!==p?p:null===(f=V.aiFeedback)||void 0===f||null===(b=f.ai)||void 0===b?void 0:b.cc)&&void 0!==m?m:""),lr:String(null!==(y=null!==(v=null===(j=V.aiFeedback)||void 0===j||null===(N=j.teacher)||void 0===N?void 0:N.lr)&&void 0!==v?v:null===(S=V.aiFeedback)||void 0===S||null===(w=S.ai)||void 0===w?void 0:w.lr)&&void 0!==y?y:""),gra:String(null!==(k=null!==(A=null===(C=V.aiFeedback)||void 0===C||null===(T=C.teacher)||void 0===T?void 0:T.gra)&&void 0!==A?A:null===(E=V.aiFeedback)||void 0===E||null===(I=E.ai)||void 0===I?void 0:I.gra)&&void 0!==k?k:""),overall:String(null!==(R=null!==(D=null===(L=V.aiFeedback)||void 0===L||null===(z=L.teacher)||void 0===z?void 0:z.overall)&&void 0!==D?D:null===(W=V.aiFeedback)||void 0===W||null===(B=W.ai)||void 0===B?void 0:B.overall)&&void 0!==R?R:""),comments:null!==(M=null===(P=V.aiFeedback)||void 0===P||null===(O=P.teacher)||void 0===O?void 0:O.comments)&&void 0!==M?M:""}),[re,ae]=n.useState(!1),[le,oe]=n.useState(""),ie=()=>{var e;X&&ee.trim()&&(Q(e=>[...e,{id:Date.now(),start:X.start,end:X.end,text:X.text,comment:ee.trim()}]),$(null),te(""),null===(e=window.getSelection())||void 0===e||e.removeAllRanges())},de=null===(G=V.aiFeedback)||void 0===G?void 0:G.ai,ce=V.essayText?V.essayText.trim().split(/\s+/).length:0;return(0,l.jsxs)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.75)",zIndex:9e3,display:"flex",flexDirection:"column"},children:[(0,l.jsxs)("div",{style:{background:"#002147",color:"white",padding:"0.75rem 1.5rem",display:"flex",alignItems:"center",gap:"1rem",flexShrink:0},children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsxs)("div",{style:{fontWeight:"700",fontSize:"1rem"},children:["\u270d\ufe0f ",null===(F=V.student)||void 0===F||null===(_=F.user)||void 0===_?void 0:_.firstName," ",null===(U=V.student)||void 0===U||null===(H=U.user)||void 0===H?void 0:H.lastName,"'s Essay"]}),(0,l.jsxs)("div",{style:{fontSize:"0.72rem",color:"rgba(255,255,255,0.6)"},children:[ce," words \xb7 Select text to highlight & comment"]})]}),(0,l.jsx)("button",{onClick:async()=>{const{tr:e,cc:t,lr:s,gra:n,overall:a,comments:l}=se;if([e,t,s,n,a].some(e=>!e))oe("All band scores are required");else{ae(!0),oe("");
1try{(await(0,r.n)("/homework/submissions/".concat(V.id,"/grade-essay"),{method:"PUT",body:JSON.stringify({tr:parseFloat(e),cc:parseFloat(t),lr:parseFloat(s),gra:parseFloat(n),overall:parseFloat(a),comments:l,annotations:K})})).ok?(q(),Y()):oe("Failed to save")}catch(o){oe("Error saving")}ae(!1)}},disabled:re,style:{background:re?"#6b7280":"#059669",border:"none",color:"white",borderRadius:"6px",padding:"0.5rem 1.25rem",cursor:re?"not-allowed":"pointer",fontWeight:"700",fontSize:"0.875rem"},children:re?"\u23f3 Saving\u2026":"\u2705 Save Evaluation"}),(0,l.jsx)("button",{onClick:Y,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",borderRadius:"6px",padding:"0.5rem 0.9rem",cursor:"pointer",fontWeight:"600"},children:"\u2715"})]}),le&&(0,l.jsx)("div",{style:{background:"#fee2e2",color:"#dc2626",padding:"0.5rem 1.5rem",fontSize:"0.8rem",fontWeight:"600",flexShrink:0},children:le}),(0,l.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[(0,l.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"1.5rem",background:"#f9fafb"},children:[(0,l.jsx)("div",{ref:J,onMouseUp:()=>{const e=window.getSelection();if(!e||e.isCollapsed||!e.rangeCount)return;const t=e.getRangeAt(0),s=J.current;if(!s||!s.contains(t.startContainer))return;const n=e.toString();if(!n.trim())return;const r=document.createRange();r.selectNodeContents(s),r.setEnd(t.startContainer,t.startOffset);const a=r.toString().length,l=a+n.length,o=t.getBoundingClientRect();$({start:a,end:l,text:n,x:o.left+o.width/2,y:o.bottom}),te("")},style:{fontFamily:"Georgia,serif",fontSize:"0.95rem",lineHeight:"1.9",color:"#111827",background:"white",padding:"2rem",borderRadius:"0.5rem",border:"1px solid #e5e7eb",userSelect:"text",cursor:"text",whiteSpace:"pre-wrap"},children:((e,t)=>{if(!t.length)return(0,l.jsx)(l.Fragment,{children:e});const s=[...t].sort((e,t)=>e.start-t.start),n=[];let r=0;return s.forEach((t,s)=>{t.start>r&&n.push((0,l.jsx)("span",{children:e.slice(r,t.start)},"t".concat(s)));const a=Math.min(t.end,e.length);n.push((0,l.jsx)("mark",{style:{background:"#fef08a",borderBottom:"2px solid #ca8a04",borderRadius:"2px",padding:"0 1px"},title:t.comment,children:e.slice(t.start,a)},"a".concat(s))),r=a}),r<e.length&&n.push((0,l.jsx)("span",{children:e.slice(r)},"end")),n})(V.essayText||"",K)}),X&&(0,l.jsxs)("div",{style:{position:"fixed",left:X.x,top:X.y+8,transform:"translateX(-50%)",background:"white",border:"1px solid #d1d5db",borderRadius:"0.5rem",padding:"0.75rem",boxShadow:"0 8px 24px rgba(0,0,0,0.15)",zIndex:9100,width:"300px"},children:[(0,l.jsxs)("div",{style:{fontSize:"0.75rem",color:"#6b7280",marginBottom:"0.5rem"},children:["Comment on: ",(0,l.jsxs)("em",{children:['"',X.text.slice(0,50),X.text.length>50?"\u2026":"",'"']})]}),(0,l.jsx)("textarea",{value:ee,onChange:e=>te(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),ie())},placeholder:"Your comment\u2026 (Enter to add)",rows:2,autoFocus:!0,style:{width:"100%",border:"1px solid #d1d5db",borderRadius:"0.375rem",padding:"0.4rem",fontSize:"0.85rem",resize:"none",boxSizing:"border-box"}}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.5rem"},children:[(0,l.jsx)("button",{onClick:ie,style:{flex:1,padding:"0.4rem",background:"#3b82f6",color:"white",border:"none",borderRadius:"0.375rem",cursor:"pointer",fontSize:"0.8rem",fontWeight:"600"},children:"\ud83d\udcac Add"}),(0,l.jsx)("button",{onClick:()=>{var e;$(null),null===(e=window.getSelection())||void 0===e||e.removeAllRanges()},style:{padding:"0.4rem 0.6rem",background:"#f3f4f6",border:"none",borderRadius:"0.375rem",cursor:"pointer",fontSize:"0.8rem"},children:"\u2715"})]})]}),de&&(0,l.jsxs)("div",{style:{marginTop:"1.5rem",background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:"0.5rem",padding:"1rem"},children:[(0,l.jsx)("div",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#1e40af",marginBottom:"0.75rem"},children:"\ud83e\udd16 AI Evaluation"}),(0,l.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(5,1fr)",gap:"0.5rem",marginBottom:"0.75rem"},children:[["TR",de.tr],["CC",de.cc],["LR",de.lr],["GRA",de.gra],["Overall",de.overall]].map(e=>{let[t,s]=e;return(0,l.jsxs)("div",{style:{textAlign:"center",background:"white",borderRadius:"0.375rem",padding:"0.5rem",border:"1px solid #e5e7eb"},children:[(0,l.jsx)("div",{style:{fontSize:"0.6rem",color:"#6b7280",fontWeight:"700",textTransform:"uppercase",marginBottom:"0.2rem"},children:t}),(0,l.jsx)("div",{style:{fontSize:"1.25rem",fontWeight:"800",color:Z(s)},children:null!==s&&void 0!==s?s:"\u2014"})]},t)})}),de.feedback&&(0,l.jsx)("p",{style:{fontSize:"0.85rem",color:"#374151",margin:0,lineHeight:"1.6",whiteSpace:"pre-wrap"},children:de.feedback})]})]}),(0,l.jsxs)("div",{style:{width:"300px",overflowY:"auto",padding:"1.25rem",background:"white",borderLeft:"1px solid #e5e7eb",display:"flex",flexDirection:"column",gap:"1rem",flexShrink:0},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#374151",marginBottom:"0.5rem"},children:"Your Band Scores"}),(0,l.jsx)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.5rem"},children:[["tr","Task Response"],["cc","Coherence & Cohesion"],["lr","Lexical Resource"],["gra","Grammar & Accuracy"]].map(e=>{let[t,s]=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"0.65rem",fontWeight:"600",color:"#6b7280",display:"block",marginBottom:"0.2rem"},children:s}),(0,l.jsx)("input",{type:"number",min:"0",max:"9",step:"0.5",value:se[t],onChange:e=>ne(s=>(0,a.A)((0,a.A)({},s),{},{[t]:e.target.value})),style:{width:"100%",padding:"0.4rem",border:"1px solid #d1d5db",borderRadius:"0.375rem",boxSizing:"border-box",fontSize:"0.9rem",textAlign:"center",fontWeight:"700"}})]},t)})}),(0,l.jsxs)("div",{style:{marginTop:"0.5rem"},children:[(0,l.jsx)("label",{style:{fontSize:"0.72rem",fontWeight:"700",color:"#374151",display:"block",marginBottom:"0.2rem"},children:"Overall Band"}),(0,l.jsx)("input",{type:"number",min:"0",max:"9",step:"0.5",value:se.overall,onChange:e=>ne(t=>(0,a.A)((0,a.A)({},t),{},{overall:e.target.value}
1)),style:{width:"100%",padding:"0.5rem",border:"2px solid #3b82f6",borderRadius:"0.375rem",boxSizing:"border-box",fontSize:"1.25rem",textAlign:"center",fontWeight:"800",color:"#1e40af"}})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"0.72rem",fontWeight:"600",color:"#374151",display:"block",marginBottom:"0.3rem"},children:"General Comments"}),(0,l.jsx)("textarea",{value:se.comments,onChange:e=>ne(t=>(0,a.A)((0,a.A)({},t),{},{comments:e.target.value})),rows:4,placeholder:"Overall feedback\u2026",style:{width:"100%",padding:"0.4rem",border:"1px solid #d1d5db",borderRadius:"0.375rem",boxSizing:"border-box",resize:"vertical",fontSize:"0.85rem"}})]}),K.length>0&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{fontSize:"0.72rem",fontWeight:"700",color:"#374151",marginBottom:"0.4rem"},children:["\ud83d\udcac Inline Comments (",K.length,")"]}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"0.4rem"},children:K.map((e,t)=>(0,l.jsxs)("div",{style:{background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:"0.375rem",padding:"0.5rem",fontSize:"0.75rem"},children:[(0,l.jsxs)("div",{style:{color:"#92400e",fontStyle:"italic",marginBottom:"0.2rem"},children:['"',e.text.slice(0,60),e.text.length>60?"\u2026":"",'"']}),(0,l.jsx)("div",{style:{color:"#374151"},children:e.comment}),(0,l.jsx)("button",{onClick:()=>Q(e=>e.filter((e,s)=>s!==t)),style:{marginTop:"0.2rem",background:"none",border:"none",color:"#ef4444",cursor:"pointer",fontSize:"0.7rem",padding:0},children:"\u2715 Remove"})]},e.id))})]}),!K.length&&(0,l.jsx)("div",{style:{background:"#f9fafb",border:"1px dashed #d1d5db",borderRadius:"0.5rem",padding:"1rem",textAlign:"center",fontSize:"0.75rem",color:"#9ca3af"},children:"Select text in the essay to add inline comments"})]})]})]})}function te(e){let{attemptId:t,studentName:s,attemptNumber:a,score:o,total:i,onClose:d}=e;const[c,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!0);(0,n.useEffect)(()=>{(0,r.n)("/test-bank/attempts/".concat(t,"/detail")).then(e=>e.json()).then(e=>{e.success&&x(e.data),m(!1)}).catch(()=>m(!1))},[t]);const p={MCQ:"MCQ",TRUE_FALSE_NG:"T/F/NG",YES_NO_NG:"Y/N/NG",FILL_IN_BLANK:"Fill",MATCHING_HEADINGS:"Match",MATCHING_FEATURES:"Match",SENTENCE_COMPLETION:"Sentence",SHORT_ANSWER:"Short"};return(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.6)",zIndex:2e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},children:(0,l.jsxs)("div",{style:{background:"white",borderRadius:"0.75rem",width:"100%",maxWidth:"720px",maxHeight:"90vh",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[(0,l.jsxs)("div",{style:{background:"#0f172a",color:"white",padding:"1rem 1.25rem",display:"flex",alignItems:"center",gap:"0.75rem"},children:[(0,l.jsx)("span",{style:{fontSize:"1.1rem"},children:"\ud83d\udccb"}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsxs)("div",{style:{fontWeight:"700",fontSize:"0.9rem"},children:["Answer Sheet \u2014 ",s]}),(0,l.jsxs)("div",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.55)"},children:["Attempt #",a,null!=o?" \xb7 Score: ".concat(o,"/").concat(i):""]})]}),(0,l.jsx)("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",borderRadius:"6px",padding:"0.3rem 0.7rem",cursor:"pointer",fontWeight:"600"},children:"\u2715"})]}),(0,l.jsx)("div",{style:{overflowY:"auto",flex:1},children:u?(0,l.jsx)("div",{style:{padding:"2rem",textAlign:"center",color:"#64748b"},children:"Loading\u2026"}):c?0===c.answers.length?(0,l.jsx)("div",{style:{padding:"2rem",textAlign:"center",color:"#94a3b8"},children:"No answers recorded"}):(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"0.82rem"},children:[(0,l.jsx)("thead",{style:{position:"sticky",top:0,background:"#f1f5f9",zIndex:1},children:(0,l.jsx)("tr",{children:["#","Type","Question","Student Answer","Correct Answer","\u2713"].map(e=>(0,l.jsx)("th",{style:{padding:"0.55rem 0.75rem",textAlign:"left",fontWeight:"600",color:"#475569",fontSize:"0.72rem",textTransform:"uppercase",letterSpacing:"0.04em",borderBottom:"1px solid #e2e8f0"},children:e},e))})}),(0,l.jsx)("tbody",{children:c.answers.map((e,t)=>{var s,n,r,a,o,i;const d=null===(s=e.question)||void 0===s?void 0:s.correctAnswer,c=e.studentAnswer,x=e.isCorrect,u=!0===x?"#f0fdf4":!1===x?"#fef2f2":"#fff",m=!0===x?"#16a34a":!1===x?"#dc2626":"#94a3b8";return(0,l.jsxs)("tr",{style:{background:u,borderBottom:"1px solid #e2e8f0"},children:[(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",color:"#64748b",fontWeight:"600",whiteSpace:"nowrap"},children:null!==(n=null===(r=e.question)||void 0===r?void 0:r.orderIndex)&&void 0!==n?n:t+1}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",color:"#64748b",whiteSpace:"nowrap"},children:p[null===(a=e.question)||void 0===a?void 0:a.type]||(null===(o=e.question)||void 0===o?void 0:o.type)}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",color:"#374151",maxWidth:"220px"},children:null===(i=e.question)||void 0===i?void 0:i.questionText}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",fontWeight:"600",color:!1===x?"#dc2626":"#0f172a"},children:c||(0,l.jsx)("em",{style:{color:"#94a3b8"},children:"blank"})}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",color:"#16a34a",fontWeight:"600"},children:d||"\u2014"}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.75rem",textAlign:"center",fontWeight:"700",color:m,fontSize:"0.9rem"},children:!0===x?"\u2713":!1===x?"\u2717":"\u2014"})]},e.id)})})]}):(0,l.jsx)("div",{style:{padding:"2rem",textAlign:"center",color:"#dc2626"},children:"Failed to load answers"})})]})})}function se(e){var t,s,n,r,a;let{log:o,studentName:i,onClose:d}=e;const c=o.riskLevel||"LOW",x={LOW:"#10b981",MEDIUM:"#f59e0b",HIGH:"#ef4444"}[c],u={LOW:"#d1fae5",MEDIUM:"#fef3c7",HIGH:"#fee2e2"}[c],m=e=>{if(!e&&0!==e)return"\u2014";const t=Math.round(e/1e3);if(t<60)return"".concat(t,"s");const s=Math.floor(t/60);return"".concat(s,"m ").concat(t%60,"s")},p=e=>e?new Date(e).toLocaleTimeString():"\u2014";return(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",zIndex:2e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},children:(0,l.jsxs)("div",{style:{background:"white",borderRadius:"0.75rem",width:"100%",maxWidth:"560px",maxHeight:"90vh",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[(0,l.jsxs)("div",{style:{background:"#0f172a",color:"white",padding:"1rem 1.25rem",display:"flex",alignItems:"center",gap:"0.75rem"},children:[(0,l.jsx)("span",{style:{fontSize:"1.1rem"},children:"\ud83d\udd0d"}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsxs)("div",{style:{fontWeight:"700",fontSize:"0.9rem"},children:["Security Report \u2014 ",i]}),(0,l.jsx)("div",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.5)"},children:"Visible to teachers and admins only"})]}),(0,l.jsxs)("div",{style:{background:u,color:x,borderRadius:"999px",padding:"3px 10px",fontSize:"0.75rem",fontWeight:"800"},children:[c," RISK \xb7 ",o.riskScore,"%"]}),(0,l.jsx)("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",borderRadius:"6px",padding:"0.3rem 0.7rem",cursor:"pointer",fontWeight:"600"},children:"\u2715"})]}),(0,l.jsxs)("div",{style:{overflowY:"auto",padding:"1rem",display:"flex",flexDirection:"column",gap:"0.75rem"},children:[(0,l.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(3,1fr)",gap:"0.6rem"},children:[(0,l.jsxs)("div",{style:{background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:"0.5rem",padding:"0.65rem",textAlign:"center"},children:[(0,l.jsx)("div",{style:{fontSize:"0.62rem",color:"#6b7280",fontWeight:"700",textTransform:"uppercase",marginBottom:"0.2rem"},children:"Blocked Attempts"}),(0,l.jsx)("div",{style:{fontSize:"1.4rem",fontWeight:"800",color:(o.copyBlockedCount||0)>0?"#ef4444":"#10b981"},children:null!==(t=o.copyBlockedCount)&&void 0!==t?t:0}),(0,l.jsx)("div",{style:{fontSize:"0.62rem",color:"#9ca3af"},children:"copy/paste/cut"})]}),(0,l.jsxs)("div",{style:{background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:"0.5rem",padding:"0.65rem",textAlign:"center"},children:[(0,l.jsx)("div",{style:{fontSize:"0.62rem",color:"#6b7280",fontWeight:"700",textTransform:"uppercase",marginBottom:"0.2rem"},children:"Tab Switches"}),(0,l.jsx)("div",{style:{fontSize:"1.4rem",fontWeight:"800",color:((null===(s=o.focusLostEvents)||void 0===s?void 0:s.length)||0)>0?"#f59e0b":"#10b981"},children:null!==(n=null===(r=o.focusLostEvents)||void 0===r?void 0:r.length)&&void 0!==n?n:0})]}),(0,l.jsxs)("div",{style:{background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:"0.5rem",padding:"0.65rem",textAlign:"center"},children:[(0,l.jsx)("div",{style:{fontSize:"0.62rem",color:"#6b7280",fontWeight:"700",textTransform:"uppercase",marginBottom:"0.2rem"},children:"Time Spent"}),(0,l.jsx)("div",{style:{fontSize:"1rem",fontWeight:"800",color:"#111827"},children:m(o.totalTimeMs)})]})]}),(null===(a=o.focusLostEvents)||void 0===a?void 0:a.length)>0&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#374151",marginBottom:"0.4rem"},children:["Tab / Window Switches (",o.focusLostEvents.length,")"]}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"0.3rem"},children:o.focusLostEvents.map((e,t)=>(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.6rem",padding:"0.4rem 0.65rem",background:e.durationMs>3e4?"#fee2e2":"#fffbeb",border:"1px solid ".concat(e.durationMs>3e4?"#fecaca":"#fde68a"),borderRadius:"0.375rem",fontSize:"0.75rem"},children:[(0,l.jsxs)("span",{style:{fontWeight:"700",color:e.durationMs>3e4?"#ef4444":"#92400e"},children:["#",t+1]}),(0,l.jsxs)("span",{style:{color:"#6b7280"},children:["Left ",p(e.outTs)," \xb7 returned ",p(e.returnTs)]}),(0,l.jsxs)("span",{style:{marginLeft:"auto",fontWeight:"700",color:e.durationMs>3e4?"#ef4444":"#92400e"},children:["away ",m(e.durationMs)]})]},t))})]})]})]})})}
1function ne(){const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)(""),[i,d]=(0,n.useState)([]),[c,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(!1),[p,h]=(0,n.useState)({title:"",description:"",dueDate:"",type:"GENERAL",points:100,audioUrl:"",essayPrompt:""}),[g,f]=(0,n.useState)(null),[b,y]=(0,n.useState)([]),[v,j]=(0,n.useState)({word:"",def:""}),[S,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)({text:"",ok:!0}),[C,T]=(0,n.useState)(null),[E,I]=(0,n.useState)({}),[R,D]=(0,n.useState)({}),[L,z]=(0,n.useState)(null),[W,B]=(0,n.useState)(!1),[M,P]=(0,n.useState)(null),[O,G]=(0,n.useState)(null),[F,_]=(0,n.useState)(null);(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&e.data.length>0&&(t(e.data),o(e.data[0].id))})},[]);const U=e=>{e&&(x(!0),(0,r.n)("/homework/group/".concat(e)).then(e=>e.json()).then(e=>{e.success&&d(e.data||[])}).finally(()=>x(!1)))};(0,n.useEffect)(()=>{U(s)},[s]);return(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147]",children:"\ud83d\udcd3 Homework"}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:()=>B(!0),className:"px-4 py-2 rounded-lg text-sm font-medium text-white",style:{backgroundColor:"#7c3aed"},children:"\ud83d\udcda Assign from Library"}),(0,l.jsx)("button",{onClick:()=>{m(!u),A({text:"",ok:!0})},className:"px-4 py-2 bg-[#002147] text-white rounded-lg hover:bg-[#001a39] text-sm font-medium",children:u?"\u2715 Cancel":"+ New Assignment"})]})]}),W&&(0,l.jsx)(q.A,{groups:e,defaultGroupId:s,onClose:()=>B(!1),onAssigned:e=>{const t=(null===e||void 0===e?void 0:e.groupId)||s;o(t),U(t),A({text:"\u2705 Assigned from library!",ok:!0})}}),M&&(0,l.jsx)(ee,{sub:M,onClose:()=>P(null),onSaved:()=>{A({text:"\u2705 Essay graded!",ok:!0});const e=M.homeworkId;(0,r.n)("/homework/".concat(e,"/submissions")).then(e=>e.json()).then(t=>{t.success&&I(s=>(0,a.A)((0,a.A)({},s),{},{[e]:(0,a.A)((0,a.A)({},s[e]),{},{subs:t.data})}))}),P(null)}}),O&&(0,l.jsx)(se,{log:O.log,studentName:O.studentName,onClose:()=>G(null)}),F&&(0,l.jsx)(te,(0,a.A)((0,a.A)({},F),{},{onClose:()=>_(null)})),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] uppercase mb-1",children:"Group"}),(0,l.jsx)("select",{value:s,onChange:e=>o(e.target.value),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))})]}),k.text&&(0,l.jsx)("div",{className:"mb-4 px-4 py-3 rounded-lg text-sm font-medium ".concat(k.ok?"bg-green-50 text-green-700 border border-green-200":"bg-red-50 text-red-700 border border-red-200"),children:k.text}),u&&(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),p.title&&p.dueDate){w(!0),A({text:"",ok:!0});try{const e=new FormData;e.append("groupId",s),e.append("title",p.title),e.append("description",p.description),e.append("type",p.type),e.append("dueDate",p.dueDate),e.append("points",String(p.points)),g&&e.append("file",g),p.audioUrl&&e.append("audioUrl",p.audioUrl),p.essayPrompt&&e.append("essayPrompt",p.essayPrompt),b.length>0&&e.append("vocabularyList",JSON.stringify(b));const t=await(0,r.n)("/homework",{method:"POST",body:e}),n=await t.json();t.ok&&n.success?(U(s),h({title:"",description:"",dueDate:"",type:"GENERAL",points:100,audioUrl:"",essayPrompt:""}),f(null),y([]),j({word:"",def:""}),m(!1),A({text:"\u2705 Homework created!",ok:!0})):A({text:n.message||"Failed to create homework",ok:!1})}catch(t){A({text:"Network error",ok:!1})}finally{w(!1)}}else A({text:"Title and due date are required",ok:!1})},className:"bg-white rounded-xl p-6 shadow border border-gray-100 mb-6 space-y-4",children:[(0,l.jsx)("h3",{className:"font-semibold text-[#002147] text-lg",children:"Create New Homework"}),(0,l.jsx)("input",{required:!0,value:p.title,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),placeholder:"Title *",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("textarea",{value:p.description,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{description:e.target.value})),placeholder:"Description (optional)",rows:3,className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] mb-1",children:"Type"}
1),(0,l.jsx)("select",{value:p.type,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{type:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:J.map(e=>(0,l.jsx)("option",{value:e,children:K[e]||e},e))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] mb-1",children:"Due Date *"}),(0,l.jsx)("input",{type:"date",required:!0,value:p.dueDate,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{dueDate:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] mb-1",children:"Points"}),(0,l.jsx)("input",{type:"number",min:0,value:p.points,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{points:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"})]})]}),"IELTS_WRITING"===p.type&&(0,l.jsxs)("div",{className:"border border-orange-200 rounded-lg p-4 bg-orange-50 space-y-2",children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-orange-700",children:"\u270d\ufe0f Essay Question (Task 2 Prompt) *"}),(0,l.jsx)("textarea",{value:p.essayPrompt,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{essayPrompt:e.target.value})),placeholder:"e.g. Some people think that modern technology is making people less sociable. To what extent do you agree or disagree?",rows:4,className:"w-full border border-orange-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-orange-400 bg-white resize-y"}),(0,l.jsx)("p",{className:"text-xs text-orange-600",children:"Students will see this question and write their essay in a text editor. AI will evaluate their response automatically."})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] mb-1",children:"Upload File (PDF, DOCX, HTML, etc.)"}),(0,l.jsx)("input",{type:"file",onChange:e=>f(e.target.files[0]||null),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-xs focus:outline-none focus:border-[#002147] file:mr-2 file:py-1 file:px-2 file:rounded file:border-0 file:text-xs file:bg-[#002147] file:text-white"}),(0,l.jsx)("p",{className:"text-xs text-[#708090] mt-1",children:"For IELTS tests, upload HTML files with embedded audio/content"}),g&&(0,l.jsxs)("p",{className:"text-xs text-[#708090] mt-1",children:["\ud83d\udcce ",g.name]})]}),g&&g.name.toLowerCase().endsWith(".html")&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] mb-1",children:"\ud83d\udd0a Audio URL (for listening tests)"}),(0,l.jsx)("input",{type:"url",value:p.audioUrl,onChange:e=>h(t=>(0,a.A)((0,a.A)({},t),{},{audioUrl:e.target.value})),placeholder:"https://... (direct link to .mp3 or audio file)",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("p",{className:"text-xs text-[#708090] mt-1",children:"Paste a direct link to the audio file. It will be embedded in the HTML so students can play it."})]}),(0,l.jsxs)("div",{className:"border border-purple-200 rounded-lg p-4 bg-purple-50 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-purple-700 uppercase tracking-wide",children:"\ud83d\udcd6 Vocabulary List (optional)"}),b.length>0&&(0,l.jsxs)("span",{className:"text-xs bg-purple-100 text-purple-600 px-2 py-0.5 rounded-full font-medium",children:[b.length," word",1!==b.length?"s":""]})]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("input",{type:"text",value:v.word,onChange:e=>j(t=>(0,a.A)((0,a.A)({},t),{},{word:e.target.value})),placeholder:"Word or phrase",className:"flex-1 border border-purple-200 rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:border-purple-400 bg-white"}),(0,l.jsx)("input",{type:"text",value:v.def,onChange:e=>j(t=>(0,a.A)((0,a.A)({},t),{},{def:e.target.value})),placeholder:"Definition",className:"flex-[2] border border-purple-200 rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:border-purple-400 bg-white",onKeyDown:e=>{if("Enter"===e.key){e.preventDefault();const t=v.word.trim(),s=v.def.trim();t&&s&&(y(e=>[...e,{word:t,def:s}]),j({word:"",def:""}))}}}),(0,l.jsx)("button",{type:"button",onClick:()=>{const e=v.word.trim(),t=v.def.trim();e&&t&&(y(s=>[...s,{word:e,def:t}]),j({word:"",def:""}))},className:"px-3 py-1.5 bg-purple-600 text-white rounded-lg text-sm font-medium hover:bg-purple-700 whitespace-nowrap",children:"+ Add"})]}),b.length>0&&(0,l.jsx)("div",{className:"space-y-1 max-h-40 overflow-y-auto",children:b.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 bg-white border border-purple-100 rounded-lg px-3 py-1.5 text-sm",children:[(0,l.jsx)("span",{className:"font-semibold text-purple-700 shrink-0",children:e.word}),(0,l.jsx)("span",{className:"text-gray-400",children:"\u2013"}),(0,l.jsx)("span",{className:"text-gray-600 flex-1 truncate",children:e.def}),(0,l.jsx)("button",{type:"button",onClick:()=>y(e=>e.filter((e,s)=>s!==t)),className:"text-gray-300 hover:text-red-400 text-base leading-none ml-1 shrink-0",children:"\u2715"})]},t))})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 pt-1",children:[(0,l.jsx)("button",{type:"submit",disabled:S,className:"px-6 py-2.5 bg-[#002147] text-white rounded-lg hover:bg-[#001a39] text-sm font-medium disabled:opacity-60",children:S?"Creating...":"Create Homework"}),(0,l.jsx)("button",{type:"button",onClick:()=>{m(!1),A({text:"",ok:!0}
1)},className:"px-4 py-2.5 border border-gray-300 text-gray-600 rounded-lg hover:bg-gray-50 text-sm",children:"Cancel"})]})]}),c?(0,l.jsx)("p",{className:"text-[#708090]",children:"Loading..."}):0===i.length?(0,l.jsx)("div",{className:"bg-white rounded-xl p-10 text-center text-[#708090] shadow border border-gray-100",children:"No homework assigned to this group yet."}):(0,l.jsx)("div",{className:"space-y-3",children:i.map(e=>{var t,s,n,o;const c=C===e.id,x=E[e.id],u=!(!e.hasHtmlContent&&!e.htmlContent);return(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow border border-gray-100 border-l-4 overflow-hidden ".concat(Q[e.type]||"border-l-gray-400"),children:[(0,l.jsx)("div",{className:"p-5",children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,l.jsx)("p",{className:"font-semibold text-[#002147]",children:e.title}),(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium ".concat(X[e.status]||"bg-gray-100 text-gray-600"),children:e.status}),(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-500",children:K[e.type]||e.type}),u&&(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full bg-purple-50 text-purple-600 border border-purple-200",children:"HTML Test"})]}),e.description&&(0,l.jsx)("p",{className:"text-sm text-[#708090] mb-2",children:e.description}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-3 text-xs text-[#708090]",children:[(0,l.jsxs)("span",{children:["\ud83d\udcc5 Due: ",e.dueDate?new Date(e.dueDate).toLocaleDateString("en-GB"):"\u2014"]}),(0,l.jsxs)("span",{children:["\ud83c\udfc6 ",e.points," pts"]}),(0,l.jsxs)("span",{children:["\ud83d\udce8 ",null!==(t=null===(s=e._count)||void 0===s?void 0:s.submissions)&&void 0!==t?t:0," submissions"]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[(0,l.jsx)("button",{onClick:()=>(async e=>{if(C===e)return void T(null);T(e);const t=i.find(t=>t.id===e),s="NATIVE_TEST"===(null===t||void 0===t?void 0:t.type),[n,l]=await Promise.all([(0,r.n)("/homework/".concat(e,"/submissions")).then(e=>e.json()),s?(0,r.n)("/test-bank/homework/".concat(e,"/attempts")).then(e=>e.json()):(0,r.n)("/homework/".concat(e,"/attempts")).then(e=>e.json())]);I(t=>(0,a.A)((0,a.A)({},t),{},{[e]:{subs:n.success?n.data:[],attempts:l.success?l.data:[],error:n.success?null:n.message||"Failed to load submissions"}})),n.success&&d(t=>t.map(t=>t.id===e?(0,a.A)((0,a.A)({},t),{},{_count:(0,a.A)((0,a.A)({},t._count),{},{submissions:n.data.length})}):t))})(e.id),className:"px-3 py-1.5 text-xs border rounded-lg font-medium ".concat(c?"bg-[#002147] text-white border-[#002147]":"bg-indigo-50 text-indigo-600 border-indigo-200 hover:bg-indigo-100"),children:c?"\u25b2 Hide":"\ud83d\udccb Submissions (".concat(null!==(n=null===(o=e._count)||void 0===o?void 0:o.submissions)&&void 0!==n?n:0,")")}),e.fileUrl&&(0,l.jsx)("a",{href:"".concat(N.C,"/homework/files/").concat(e.fileUrl.split("/").pop()),target:"_blank",rel:"noopener noreferrer",className:"px-3 py-1.5 text-xs bg-blue-50 text-blue-600 border border-blue-200 rounded-lg hover:bg-blue-100 font-medium",children:"\ud83d\udcce File"}),(0,l.jsx)("button",{onClick:()=>(async e=>{if(!window.confirm("Delete this homework?"))return;const t=await(0,r.n)("/homework/".concat(e),{method:"DELETE"});if(t.ok)d(t=>t.filter(t=>t.id!==e));else{const e=await t.json().catch(()=>({}));A({text:"\u274c "+(e.message||"Failed to delete homework"),ok:!1})}})(e.id),className:"px-3 py-1.5 text-xs bg-red-50 text-red-600 border border-red-200 rounded-lg hover:bg-red-100 font-medium",children:"\ud83d\uddd1 Delete"})]})]})}),c&&(0,l.jsx)("div",{className:"border-t border-gray-100 bg-gray-50 p-4",children:x?x.error?(0,l.jsxs)("p",{className:"text-sm text-red-500",children:["\u26a0\ufe0f ",x.error]}):u?(0,l.jsxs)("div",{children:[(0,l.jsxs)("p",{className:"text-xs font-semibold text-[#708090] uppercase mb-2",children:["Attempts \u2014 ",x.attempts.length]}),0===x.attempts.length?(0,l.jsx)("p",{className:"text-sm text-[#708090]",children:"No attempts yet."}):(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-sm border-collapse",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{className:"text-left text-xs text-[#708090] border-b border-gray-200",children:[(0,l.jsx)("th",{className:"pb-2 pr-4",children:"Student"}),(0,l.jsx)("th",{className:"pb-2 pr-4",children:"Started"}),(0,l.jsx)("th",{className:"pb-2 pr-4",children:"Duration"}),(0,l.jsx)("th",{className:"pb-2 pr-4",children:"Score"}),(0,l.jsx)("th",{className:"pb-2",children:"Band"})]})}),(0,l.jsx)("tbody",{children:x.attempts.map(e=>{var t,s,n,r;return(0,l.jsxs)("tr",{className:"border-b border-gray-100 hover:bg-white",children:[(0,l.jsxs)("td",{className:"py-2 pr-4 font-medium",children:[null===(t=e.student)||void 0===t||null===(s=t.user)||void 0===s?void 0:s.firstName," ",null===(n=e.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.lastName]}),(0,l.jsx)("td",{className:"py-2 pr-4 text-[#708090]",children:new Date(e.startedAt).toLocaleStr
1ing("en-GB",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),(0,l.jsx)("td",{className:"py-2 pr-4 text-[#708090]",children:e.durationSeconds?"".concat(Math.floor(e.durationSeconds/60),"m ").concat(e.durationSeconds%60,"s"):"\u2014"}),(0,l.jsx)("td",{className:"py-2 pr-4",children:null!=e.score?(0,l.jsx)("span",{className:"font-semibold text-green-700",children:e.score}):(0,l.jsx)("span",{className:"text-gray-400",children:"\u2014"})}),(0,l.jsx)("td",{className:"py-2",children:null!=e.bandScore?(0,l.jsx)("span",{className:"font-semibold text-blue-700",children:e.bandScore}):(0,l.jsx)("span",{className:"text-gray-400",children:"\u2014"})})]},e.id)})})]})})]}):(0,l.jsxs)("div",{children:[(0,l.jsxs)("p",{className:"text-xs font-semibold text-[#708090] uppercase mb-2",children:["Submissions \u2014 ",x.subs.length]}),0===x.subs.length?(0,l.jsx)("p",{className:"text-sm text-[#708090]",children:"No submissions yet."}):(0,l.jsx)("div",{className:"space-y-3",children:x.subs.map(t=>{var s,n,o,i,d,c,u,m,p,h;const g=R[t.id]||{},f="IELTS_WRITING"===e.type;return(0,l.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-3",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3 mb-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("span",{className:"font-semibold text-sm",children:[null===(s=t.student)||void 0===s||null===(n=s.user)||void 0===n?void 0:n.firstName," ",null===(o=t.student)||void 0===o||null===(i=o.user)||void 0===i?void 0:i.lastName]}),(0,l.jsx)("span",{className:"ml-2 text-xs text-[#708090]",children:new Date(t.submittedAt).toLocaleString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})})]}),(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.4rem",flexWrap:"wrap",justifyContent:"flex-end"},children:[(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium ".concat("GRADED"===t.status?"bg-green-50 text-green-700":"bg-blue-50 text-blue-600"),children:t.status}),null!=t.attemptCount&&(0,l.jsxs)("span",{style:{fontSize:"0.7rem",padding:"1px 7px",background:"#eff6ff",color:"#1d4ed8",borderRadius:"999px",fontWeight:"600"},children:["\ud83d\udd04 ",t.attemptCount," attempt",1!==t.attemptCount?"s":""]}),null!=(null===(d=t.firstAttempt)||void 0===d?void 0:d.durationSeconds)&&(0,l.jsxs)("span",{style:{fontSize:"0.7rem",padding:"1px 7px",background:"#f0fdf4",color:"#15803d",borderRadius:"999px",fontWeight:"600"},children:["\u23f1 ",t.attemptCount>1?"First: ":"",$(t.firstAttempt.durationSeconds)]}),null!=(null===(c=t.latestAttempt)||void 0===c?void 0:c.durationSeconds)&&(0,l.jsxs)("span",{style:{fontSize:"0.7rem",padding:"1px 7px",background:"#fefce8",color:"#92400e",borderRadius:"999px",fontWeight:"600"},children:["\u23f1 Latest: ",$(t.latestAttempt.durationSeconds)]}),t.securityLog&&(()=>{const e=t.securityLog.riskLevel||"LOW",s={LOW:"#10b981",MEDIUM:"#d97706",HIGH:"#ef4444"}[e],n={LOW:"#d1fae5",MEDIUM:"#fef3c7",HIGH:"#fee2e2"}[e];return(0,l.jsxs)("button",{onClick:()=>{var e,s,n,r;return G({log:t.securityLog,studentName:"".concat(null===(e=t.student)||void 0===e||null===(s=e.user)||void 0===s?void 0:s.firstName," ").concat(null===(n=t.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.lastName)})},style:{fontSize:"0.7rem",padding:"1px 7px",background:n,color:s,border:"1px solid ".concat(s,"40"),borderRadius:"999px",fontWeight:"700",cursor:"pointer"},children:["\ud83d\udd0d ",e," RISK \xb7 ",t.securityLog.riskScore,"%"]})})()]})]}),t.notes&&(0,l.jsx)("div",{className:"bg-gray-50 rounded p-2 mb-2 text-sm text-[#374151] whitespace-pre-wrap border border-gray-100",children:t.notes}),f&&t.aiFeedback&&(0,l.jsx)("div",{style:{marginBottom:"0.5rem"},children:(t.aiFeedback.teacher||t.aiFeedback.ai)&&(0,l.jsxs)("div",{style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",alignItems:"center"},children:[(0,l.jsx)("span",{style:{fontSize:"0.65rem",color:"#6b7280",fontWeight:"600"},children:t.aiFeedback.teacher?"\u2705 Teacher:":"\ud83e\udd16 AI:"}),["tr","cc","lr","gra","overall"].map(e=>{var s,n,r;const a=null!==(s=null===(n=t.aiFeedback.teacher)||void 0===n?void 0:n[e])&&void 0!==s?s:null===(r=t.aiFeedback.ai)||void 0===r?void 0:r[e];return null!=a?(0,l.jsxs)("span",{style:{fontSize:"0.7rem",fontWeight:"700",color:Z(a),background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:"0.25rem",padding:"1px 5px"},children:[e.toUpperCase()," ",a]},e):null})]})}),!f&&null!=t.score&&(0,l.jsx)("p",{className:"text-xs text-green-700 font-semibold mb-1",children:"NATIVE_TEST"===e.type?"Auto-score: ".concat(t.score).concat(null!=t.totalPoints?"/".concat(t.totalPoints):""," correct").concat(null!==(u=t.firstAttempt)&&void 0!==u&&u.bandScore?" \xb7 Band ".concat(t.firstAttempt.bandScore):""):"Score: ".concat(t.score)}),t.feedback&&(0,l.jsxs)("p",{className:"text-xs text-[#708090] mb-2",children:["Feedback: ",t.feedback]}),f&&t.essayText&&(0,l.jsxs)("button",{onClick:()=>P(t),style:{padding:"0.4rem 0.9rem",background:"#fef3c7",color:"#d97706",border:"1px solid #fde68a",borderRadius:"0.375rem",cursor:"pointer",fontSize:"0.8rem",fontWeight:"600",marginTop:"0.25rem"},children:["\u270f\ufe0f ",null!==(m=t.aiFeedback)&&void 0!==m&&m.teacher?"Edit Review":"Review Essay"]}),!f&&(0,l.jsxs)("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:[(0,l.jsx)("input",{type:"number",placeholder:"Score",min:0,max:e.points,value:null!=g.score?g.score:null!==(p=t.score)&&void 0!==p?p:"",onCh
1ange:e=>D(s=>(0,a.A)((0,a.A)({},s),{},{[t.id]:(0,a.A)((0,a.A)({},s[t.id]),{},{score:e.target.value})})),className:"w-20 border border-gray-300 rounded px-2 py-1 text-xs focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("input",{type:"text",placeholder:"Feedback (optional)",value:null!=g.feedback?g.feedback:null!==(h=t.feedback)&&void 0!==h?h:"",onChange:e=>D(s=>(0,a.A)((0,a.A)({},s),{},{[t.id]:(0,a.A)((0,a.A)({},s[t.id]),{},{feedback:e.target.value})})),className:"flex-1 min-w-0 border border-gray-300 rounded px-2 py-1 text-xs focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("button",{onClick:()=>(async(e,t)=>{const s=R[e]||{};z(e);const n=await(0,r.n)("/homework/submissions/".concat(e,"/grade"),{method:"PUT",body:JSON.stringify({score:null!=s.score?Number(s.score):void 0,feedback:s.feedback||void 0})});(await n.json()).success&&I(n=>(0,a.A)((0,a.A)({},n),{},{[t]:(0,a.A)((0,a.A)({},n[t]),{},{subs:n[t].subs.map(t=>t.id===e?(0,a.A)((0,a.A)({},t),{},{score:null!=s.score?Number(s.score):t.score,feedback:s.feedback||t.feedback,status:"GRADED"}):t)})})),z(null)})(t.id,e.id),disabled:L===t.id,className:"px-3 py-1 bg-[#002147] text-white text-xs rounded font-medium disabled:opacity-60",children:L===t.id?"Saving\u2026":"\u2713 Grade"})]}),"NATIVE_TEST"===e.type&&(()=>{const e=(x.attempts||[]).filter(e=>e.studentId===t.studentId);if(!e.length)return null;const s=e[0];return(0,l.jsx)("button",{onClick:()=>{var e,n,r,a;return _({attemptId:s.id,studentName:"".concat(null===(e=t.student)||void 0===e||null===(n=e.user)||void 0===n?void 0:n.firstName," ").concat(null===(r=t.student)||void 0===r||null===(a=r.user)||void 0===a?void 0:a.lastName),attemptNumber:s.attemptNumber,score:s.autoScore,total:s.totalPoints})},style:{marginTop:"0.5rem",padding:"0.35rem 0.85rem",background:"#eff6ff",color:"#2563eb",border:"1px solid #bfdbfe",borderRadius:"0.375rem",cursor:"pointer",fontSize:"0.78rem",fontWeight:"600"},children:"\ud83d\udccb View Answer Sheet"})})()]},t.id)})})]}):(0,l.jsx)("p",{className:"text-sm text-[#708090]",children:"Loading\u2026"})})]},e.id)})})]})}const re=["ALL","READING","LISTENING","WRITING"],ae={READING:"\ud83d\udcd6",LISTENING:"\ud83c\udfa7",WRITING:"\u270d\ufe0f"};function le(){const[e,t]=(0,n.useState)([]),[s,a]=(0,n.useState)(!0),[o,i]=(0,n.useState)("ALL"),[d,c]=(0,n.useState)([]),[x,u]=(0,n.use
1State)(null);return(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&c(e.data||[])})},[]),(0,n.useEffect)(()=>{a(!0);const e=new URLSearchParams({status:"READY"});"ALL"!==o&&e.set("subject",o),(0,r.n)("/test-bank?".concat(e)).then(e=>e.json()).then(e=>{e.success&&t(e.data)}).finally(()=>a(!1))},[o]),(0,l.jsxs)("div",{style:{padding:"1.5rem",maxWidth:"1100px",margin:"0 auto"},children:[(0,l.jsxs)("div",{style:{marginBottom:"1.5rem"},children:[(0,l.jsx)("h2",{style:{fontSize:"1.4rem",fontWeight:"700",color:"#0f172a",margin:0},children:"\ud83e\uddea Test Bank"}),(0,l.jsx)("p",{style:{color:"#64748b",margin:"0.15rem 0 0",fontSize:"0.875rem"},children:"Ready IELTS tests \u2014 assign to your groups"})]}),(0,l.jsx)("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1.25rem",flexWrap:"wrap"},children:re.map(e=>(0,l.jsx)("button",{onClick:()=>i(e),style:{padding:"0.4rem 0.9rem",border:"1.5px solid",borderRadius:"20px",borderColor:o===e?"#2563eb":"#e2e8f0",background:o===e?"#eff6ff":"#fff",color:o===e?"#2563eb":"#64748b",fontWeight:o===e?"600":"400",fontSize:"0.8rem",cursor:"pointer"},children:"ALL"===e?"All":"".concat(ae[e]," ").concat(e)},e))}),s?(0,l.jsx)("div",{style:{textAlign:"center",padding:"3rem",color:"#64748b"},children:"Loading\u2026"}):0===e.length?(0,l.jsxs)("div",{style:{textAlign:"center",padding:"4rem",color:"#94a3b8"},children:[(0,l.jsx)("div",{style:{fontSize:"2.5rem",marginBottom:"0.75rem"},children:"\ud83d\udced"}),(0,l.jsx)("div",{style:{fontWeight:"600"},children:"No ready tests yet"}),(0,l.jsx)("div",{style:{fontSize:"0.875rem",marginTop:"0.25rem"},children:"Tests will appear here once they are marked Ready by admin"})]}):(0,l.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(320px, 1fr))",gap:"1rem"},children:e.map(e=>(0,l.jsxs)("div",{style:{background:"#fff",borderRadius:"12px",boxShadow:"0 2px 10px rgba(0,0,0,0.07)",padding:"1.25rem",border:"1px solid #e2e8f0"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"0.5rem"},children:[(0,l.jsx)("div",{style:{fontSize:"1.5rem"},children:ae[e.subject]||"\ud83d\udcc4"}),(0,l.jsx)("span",{style:{padding:"0.2rem 0.65rem",borderRadius:"999px",fontSize:"0.72rem",fontWeight:"600",background:"#dcfce7",color:"#16a34a"},children:"Ready"})]}),(0,l.jsxs)("div",{style:{marginTop:"0.65rem"},children:[(0,l.jsx)("div",{style:{fontWeight:"700",color:"#0f172a",fontSize:"0.95rem",marginBottom:"0.2rem"},children:e.title}),e.topic&&(0,l.jsx)("div",{style:{fontSize:"0.78rem",color:"#64748b"},children:e.topic})]}),(0,l.jsx)("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.75rem",flexWrap:"wrap"},children:["".concat(e.totalQuestions," questions"),e.bandLevel&&"Band ".concat(e.bandLevel),"".concat(e.timeLimitMinutes," min")].filter(Boolean).map(e=>(0,l.jsx)("span",{style:{padding:"0.2rem 0.6rem",background:"#f1f5f9",color:"#475569",borderRadius:"999px",fontSize:"0.72rem",fontWeight:"500"},children:e},e))}),(0,l.jsx)("button",{onClick:()=>u(e),style:{marginTop:"1rem",width:"100%",padding:"0.55rem",background:"#002147",color:"#fff",border:"none",borderRadius:"8px",fontWeight:"600",fontSize:"0.875rem",cursor:"pointer"},onMouseEnter:e=>e.currentTarget.style.background="#001a39",onMouseLeave:e=>e.currentTarget.style.background="#002147",children:"Assign to Group"})]},e.id))}),x&&(0,l.jsx)(oe,{test:x,groups:d,onClose:()=>u(null),onAssigned:()=>{u(null)}})]})}function oe(e){var t;let{test:s,groups:a,onClose:o,onAssigned:i}=e;const[d,c]=(0,n.useState)((null===(t=a[0])||void 0===t?void 0:t.id)||""),[x,u]=(0,n.use
1State)(""),[m,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)("");return(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:e=>{e.target===e.currentTarget&&o()},children:(0,l.jsxs)("div",{style:{background:"#fff",borderRadius:"16px",padding:"2rem",width:"100%",maxWidth:"420px",boxShadow:"0 20px 60px rgba(0,0,0,0.2)"},children:[(0,l.jsx)("h2",{style:{margin:"0 0 0.25rem",fontSize:"1.1rem",fontWeight:"700",color:"#0f172a"},children:"Assign Test"}),(0,l.jsxs)("p",{style:{margin:"0 0 1.25rem",fontSize:"0.85rem",color:"#64748b"},children:[ae[s.subject]," ",s.title]}),(0,l.jsx)("label",{style:{display:"block",fontSize:"0.78rem",fontWeight:"600",color:"#374151",marginBottom:"0.3rem"},children:"Group"}),(0,l.jsx)("select",{value:d,onChange:e=>c(e.target.value),style:{width:"100%",padding:"0.55rem 0.75rem",border:"1.5px solid #e2e8f0",borderRadius:"8px",fontSize:"0.875rem",marginBottom:"1rem",outline:"none"},children:a.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))}),(0,l.jsx)("label",{style:{display:"block",fontSize:"0.78rem",fontWeight:"600",color:"#374151",marginBottom:"0.3rem"},children:"Due Date"}),(0,l.jsx)("input",{type:"date",value:x,onChange:e=>u(e.target.value),style:{width:"100%",padding:"0.55rem 0.75rem",border:"1.5px solid #e2e8f0",borderRadius:"8px",fontSize:"0.875rem",marginBottom:"1.25rem",outline:"none",boxSizing:"border-box"}}),h&&(0,l.jsx)("div",{style:{color:"#dc2626",fontSize:"0.8rem",marginBottom:"0.75rem"},children:h}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.75rem"},children:[(0,l.jsx)("button",{onClick:o,style:{flex:1,padding:"0.65rem",border:"1.5px solid #e2e8f0",borderRadius:"8px",background:"#fff",cursor:"pointer",fontWeight:"600",color:"#64748b"},children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{if(d&&x){p(!0);try{const e=await(0,r.n)("/test-bank/assign",{method:"POST",body:JSON.stringify({testBankId:s.id,groupId:d,dueDate:x})}),t=await e.json();t.success?i(t.data):g(t.message||"Failed to assign")}catch(e){g("Network error")}p(!1)}else g("Please select a group and due date.")},disabled:m,style:{flex:1,padding:"0.65rem",background:"#002147",color:"#fff",border:"none",borderRadius:"8px",fontWeight:"600",cursor:m?"not-allowed":"pointer",opacity:m?.7:1},children:m?"Assigning\u2026":"Assign"})]})]})})}const ie={A:"text-green-600",B:"text-blue-600",C:"text-yellow-600",D:"text-orange-600",F:"text-red-600"},de=[0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9];function ce(){var e;const[t,s]=(0,n.useState)([]),[o,i]=(0,n.useState)(""),[d,c]=(0,n.useState)([]),[x,u]=(0,n.use
1State)(!1),[m,p]=(0,n.useState)(null),[h,g]=(0,n.useState)(!1),[f,b]=(0,n.useState)({title:"",subject:"",date:"",maxScore:100,passingScore:60,type:"WRITTEN",gradingType:"PERCENTAGE",sections:[{name:"Section 1",weight:60,maxQuestions:30,includeInOverall:!0},{name:"Section 2",weight:40,maxQuestions:13,includeInOverall:!0}]}),[y,v]=(0,n.useState)(null),[j,S]=(0,n.useState)(!1),[w,k]=(0,n.useState)({text:"",ok:!0}),[A,C]=(0,n.useState)("group"),[T,E]=(0,n.useState)(""),[I,R]=(0,n.useState)([]),[D,L]=(0,n.useState)({}),[z,W]=(0,n.useState)(!1),[B,M]=(0,n.useState)(null),[P,O]=(0,n.useState)(null),[G,F]=(0,n.useState)(null),[_,U]=(0,n.useState)(null),[H,V]=(0,n.useState)(null),[Y,q]=(0,n.useState)(""),[J,K]=(0,n.useState)([]),[Q,X]=(0,n.useState)(!1),[Z,$]=(0,n.useState)(null),[ee,te]=(0,n.useState)({L:"",R:"",W:"",S:""}),[se,ne]=(0,n.useState)(!1),[re,ae]=(0,n.useState)(!1),[le,oe]=(0,n.useState)(""),[ie,ce]=(0,n.useState)(null),[ue,me]=(0,n.useState)(""),[pe,he]=(0,n.useState)(!1),[ge,fe]=(0,n.useState)(null),[be,ye]=(0,n.useState)([]),[ve,je]=(0,n.useState)({}),[Ne,Se]=(0,n.useState)({}),[we,ke]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(async e=>{if(e.success&&e.data.length>0){s(e.data),i(e.data[0].id);const t=await Promise.all(e.data.map(e=>(0,r.n)("/groups/".concat(e.id,"/roster")).then(e=>e.json()))),n=new Set;t.forEach(e=>{e.success&&e.data.forEach(e=>n.add(e.id))}),O(n)}else O(new Set)})},[]);const Ae=(0,n.useCallback)(e=>{e&&(u(!0),(0,r.n)("/exams?groupId=".concat(e)).then(e=>e.json()).then(e=>{e.success&&c(e.data||[])}).finally(()=>u(!1)))},[]);(0,n.useEffect)(()=>{Ae("mock"===A?"none":o)},[o,A,Ae]),(0,n.useEffect)(()=>{"mock"===A&&0!==d.length?(W(!0),Promise.all(d.map(e=>(0,r.n)("/exams/".concat(e.id)).then(e=>e.json()))).then(e=>{const t=[],s={};e.forEach(e=>{if(!e.success)return;const n=e.data;(n.students||[]).forEach(e=>{var r,a,l,o;const i="".concat(n.id,":").concat(e.studentId);t.push({key:i,examId:n.id,examTitle:n.title,examDate:n.date,studentId:e.studentId,name:e.name}),s[i]={L:null!==(r=e.listeningScore)&&void 0!==r?r:"",R:null!==(a=e.readingScore)&&void 0!==a?a:"",W:null!==(l=e.writingScore)&&void 0!==l?l:"",S:null!==(o=e.speakingScore)&&void 0!==o?o:""}})}),R(t),L(s)}).finally(()=>W(!1))):R([])},[d,A]);(0,n.useEffect)(()=>{if(!H||!Y.trim())return void K([]);const e=setTimeout(async()=>{X(!0);try{const e=await(0,r.n)("/students?search=".concat(encodeURIComponent(Y),"&limit=20")),t=await e.json();if(t.success){const e=new Set(I.filter(e=>e.examId===H).map(e=>e.studentId)),s=P&&P.size>0?(t.data||[]).filter(e=>P.has(e.id)):t.data||[];K(s.filter(t=>!e.has(t.id)))}}catch(e){console.error(e)}finally{X(!1)}},300);return()=>clearTimeout(e)},[Y,H,I]);if(m)return(0,l.jsx)(xe,{exam:m,myStudentIds:P,onBack:()=>{p(null),Ae("mock"===A?"none":o)}});const Ce={SCHEDULED:"bg-blue-100 text-blue-700",COMPLETED:"bg-green-100 text-green-700",CANCELLED:"bg-red-100 text-red-700"};return(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147]",children:"\ud83d\udccb Exams & Grades"}),"group"===A&&(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:()=>{ae(!0),oe(""),ce(null),fe(null),Se({}),0===be.length&&(0,r.n)("/students?limit=5000").then(e=>e.json()).then(e=>{if(e.success){var t;const s=((null===(t=e.data)||void 0===t?void 0:t.students)||e.data||[]).map(e=>{var t,s;return{id:e.id,firstName:e.firstName||(null===(t=e.user)||void 0===t?void 0:t.firstName)||"",lastName:e.lastName||(null===(s=e.user)||void 0===s?void 0:s.lastName)||""}});ye(s)}})},className:"px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 text-sm font-medium",children:"\ud83d\udce5 Import from Examy"}),(0,l.jsx)("button",{onClick:()=>g(!h),className:"px-4 py-2 bg-[#002147] text-white rounded-lg hover:bg-[#001a39] text-sm font-medium",children:h?"\u2715 Cancel":"+ Create Exam"})]})]}),(0,l.jsxs)("div",{className:"flex gap-1 mb-5 bg-gray-100 p-1 rounded-lg w-fit",children:[(0,l.jsx)("button",{onClick:()=>{C("group"),E("")},className:"px-4 py-1.5 rounded-md text-sm font-medium transition-colors ".concat("group"===A?"bg-white text-[#002147] shadow":"text-[#708090] hover:text-[#002147]"),children:"\ud83d\udccb Group Exams"}),(0,l.jsx)("button",{onClick:()=>{C("mock"),E("")},className:"px-4 py-1.5 rounded-md text-sm font-medium transition-colors ".concat("mock"===A?"bg-white text-[#002147] shadow":"text-[#708090] hover:text-[#002147]"),children:"\ud83d\udce5 Mock
1Exams (Examy)"})]}),(0,l.jsx)("div",{className:"mb-5",children:(0,l.jsx)("input",{type:"text",value:T,onChange:e=>E(e.target.value),placeholder:"mock"===A?"\ud83d\udd0d Search student...":"\ud83d\udd0d Search exam...",className:"border border-gray-300 rounded-lg px-3 py-2 text-sm w-64 focus:outline-none focus:border-[#002147]"})}),"group"===A&&(0,l.jsx)("div",{className:"mb-5",children:(0,l.jsx)("select",{value:o,onChange:e=>i(e.target.value),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:t.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))})}),h&&(0,l.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),S(!0),k({text:"",ok:!0});try{const e=new FormData;e.append("groupId",o),e.append("title",f.title),f.subject&&e.append("subject",f.subject),e.append("date",f.date),e.append("maxScore",f.maxScore),e.append("passingScore",f.passingScore),e.append("type",f.type),e.append("gradingType",f.gradingType),"SECTIONS"===f.gradingType&&e.append("sections",JSON.stringify(f.sections)),y&&e.append("file",y);const t=await(0,r.n)("/exams",{method:"POST",body:e}),s=await t.json();s.success?(Ae(o),g(!1),b({title:"",subject:"",date:"",maxScore:100,passingScore:60,type:"WRITTEN",gradingType:"PERCENTAGE",sections:[{name:"Section 1",weight:60,maxQuestions:30,includeInOverall:!0},{name:"Section 2",weight:40,maxQuestions:13,includeInOverall:!0}]}),v(null),k({text:"\u2705 Exam created!",ok:!0})):k({text:s.message||"Error creating exam",ok:!1})}catch(t){k({text:"Error creating exam",ok:!1})}finally{S(!1)}},className:"bg-white rounded-xl p-6 shadow border border-gray-100 mb-6 space-y-4",children:[(0,l.jsx)("h3",{className:"font-semibold text-[#002147]",children:"New Exam"}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsx)("input",{required:!0,value:f.title,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),placeholder:"Title *",className:"col-span-2 border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("input",{value:f.subject,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{subject:e.target.value})),placeholder:"Subject",className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("input",{required:!0,type:"date",value:f.date,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("input",{type:"number",value:f.maxScore,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{maxScore:e.target.value})),placeholder:"Max Score",className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("input",{type:"number",value:f.passingScore,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{passingScore:e.target.value})),placeholder:"Passing Score",className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"}),(0,l.jsx)("select",{value:f.type,onChange:e=>b(t=>(0,a.A)((0,a.A)({},t),{},{type:e.target.value})),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:["WRITTEN","ORAL","PRACTICAL","ONLINE","QUIZ"].map(e=>(0,l.jsx)("option",{children:e},e))}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-[#708090] mb-1",children:"Grading Format"}),(0,l.jsx)("div",{className:"flex gap-2",children:[["PERCENTAGE","% Score"],["IELTS","IELTS Band"],["SECTIONS","Sections"]].map(e=>{let[t,s]=e;return(0,l.jsx)("button",{type:"button",onClick:()=>b(e=>(0,a.A)((0,a.A)({},e),{},{gradingType:t})),className:"px-3 py-1.5 rounded-lg text-xs font-medium border ".concat(f.gradingType===t?"bg-[#002147] text-white border-[#002147]":"bg-white text-[#708090] border-gray-300 hover:border-[#002147]"),children:s},t)})})]}),"SECTIONS"===f.gradingType&&(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsx)("label",{className:"text-xs font-medium text-[#708090]",children:"Sections"}),(()=>{const e=f.sections.filter(e=>!1!==e.includeInOverall).reduce((e,t)=>
1e+Number(t.weight),0);return(0,l.jsxs)("span",{className:"text-xs font-semibold ".concat(100===e?"text-green-600":"text-red-500"),children:["Included: ",e,"%"]})})()]}),(0,l.jsx)("div",{className:"space-y-1.5",children:f.sections.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded-lg px-2 py-1.5 ".concat(!1===e.includeInOverall?"bg-gray-100 opacity-70":"bg-gray-50"),children:[(0,l.jsx)("input",{type:"text",value:e.name,onChange:e=>{const s=[...f.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{name:e.target.value}),b(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},placeholder:"Name",className:"border border-gray-300 rounded px-2 py-1 text-xs flex-1"}),(0,l.jsx)("input",{type:"number",value:e.weight,onChange:e=>{const s=[...f.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{weight:Number(e.target.value)}),b(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},disabled:!1===e.includeInOverall,className:"border border-gray-300 rounded px-1 py-1 text-xs w-12 text-center disabled:opacity-40",min:"1",max:"100"}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"%"}),(0,l.jsx)("input",{type:"number",value:e.maxQuestions,onChange:e=>{const s=[...f.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{maxQuestions:Number(e.target.value)}),b(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},className:"border border-gray-300 rounded px-1 py-1 text-xs w-12 text-center",min:"1"}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"Qs"}),(0,l.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",title:"Include in overall %",children:[(0,l.jsx)("input",{type:"checkbox",checked:!1!==e.includeInOverall,onChange:e=>{const s=[...f.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{includeInOverall:e.target.checked}),b(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},className:"w-3 h-3 accent-[#002147]"}),(0,l.jsx)("span",{className:"text-xs text-gray-500",children:"Overall"})]}),(0,l.jsx)("button",{type:"button",onClick:()=>b(e=>(0,a.A)((0,a.A)({},e),{},{sections:e.sections.filter((e,s)=>s!==t)})),className:"text-red-400 hover:text-red-600 text-xs",children:"\u2715"})]},t))}),(0,l.jsx)("button",{type:"button",onClick:()=>b(e=>(0,a.A)((0,a.A)({},e),{},{sections:[...e.sections,{name:"",weight:0,maxQuestions:10,includeInOverall:!0}]})),className:"mt-1 text-xs text-[#002147] font-medium hover:underline",children:"+ Add section"})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-[#708090] mb-1",children:"Attach file (optional)"}),(0,l.jsx)("input",{type:"file",onChange:e=>v(e.target.files[0]||null),className:"block w-full text-sm text-gray-600 file:mr-3 file:py-1.5 file:px-3 file:rounded file:border-0 file:text-sm file:font-medium file:bg-[#002147] file:text-white hover:file:bg-[#001a39] cursor-pointer"}),y&&(0,l.jsxs)("p",{className:"text-xs text-gray-500 mt-1",children:["\ud83d\udcce ",y.name]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("button",{type:"submit",disabled:j,className:"px-5 py-2 bg-[#002147] text-white rounded-lg text-sm font-medium disabled:opacity-60",children:j?"Creating...":"Create"}),w.text&&(0,l.jsx)("span",{className:"text-sm ".concat(w.ok?"text-green-600":"text-red-600"),children:w.text})]})]}),"mock"===A?z||x||null===P?(0,l.jsx)("p",{className:"text-[#708090]",children:"Loading students..."}):0===I.length?(0,l.jsx)("p",{className:"text-[#708090]",children:"No mock exam results yet. Import from Examy first."}):(()=>{const e=P&&P.size>0?I.filter(e=>P.has(e.studentId)):I,t=e.filter(e=>!T||e.name.toLowerCase().includes(T.toLowerCase()));return(0,l.jsxs)("div",{children:[0===e.length&&(0,l.jsx)("p",{className:"text-amber-600 bg-amber-50 border border-amber-200 rounded-lg px-4 py-2 text-sm mb-3",children:"None of your enrolled students appear in this Examy import. Check if their names matched during import."}),d.map(e=>(0,l.jsxs)("div",{className:"mb-2",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between bg-indigo-50 border border-indigo-100 rounded-lg px-4 py-2",children:[(0,l.jsxs)("span",{className:"text-sm font-medium text-[#002147]",children:[e.title,(0,l.jsx)("span",{className:"text-xs text-[#708090] ml-2",children:new Date(e.date).toLocaleDateString("en-GB")})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:()=>{H===e.id?V(null):(V(e.id),q(""),K([]),$(null),te({L:"",R:"",W:"",S:""}))},className:"flex items-center gap-1 px-3 py-1 bg-indigo-600 hover:bg-indigo-700 text-white text-xs font-medium rounded-lg",children:"+ Add Student"}),(0,l.jsx)("button",{onClick:()=>(async(e,t)=>{U(e);try{const s=await(0,r.n)("/exams/".concat(e,"/export")),n=await s.blob(),a=URL.createObjectURL(n),l=document.createElement("a");l.href=a,l.download="".concat(t||"exam-results",".xlsx"),l.click(),URL.revokeObjectURL(a)}catch(s){console.error(s),alert("Export failed")}finally{U(null)}})(e.id,e.title),disabled:_===e.id,className:"flex items-center gap-1 px-3 py-1 bg-green-600 hover:bg-green-700 text-white text-xs font-medium rounded-lg disabled:opacity-50",title:"Export results to Excel",children:_===e.id?"Exporting\u2026":"\ud83d\udce5 Export Excel"}),(0,l.jsx)("button",{onClick:()=>(async(e,t)=>{if(window.confirm('Send results for "'.concat(t,'" to parents via Telegram DM?'))){F(e);try{const t=await(0,r.n)("/exams/".concat(e,"/send-telegram"),{method:"POST"}),s=await t.json();s.success?alert(s.message||"Results sent to Telegram!"):alert(s.message||"Failed to send")}catch(s){alert("Error sending to Telegram")}finally{F(null)}}})(e.id,e.title),disabled:G===e.id,className:"flex items-center gap-1 px-3 py-1 bg-blue-500 hover:bg-blue-600 text-white text-xs font-medium rounded-lg disabled:opacity-50",children:G===e.id?"Sending...":"\u2708\ufe0f Send to Telegram"})]})]}),H===e.id&&(0,l.jsx)("div",{className:"border border-indigo-200 border-t-0 rounded-b-lg bg-indigo-50 px-4 py-3",children:Z?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsxs)("p",{className:"text-sm font-medium text-indigo-700",children:["Adding: ",(0,l.jsxs)("span",{className:"font-bold",children:[Z.user.firstName," ",Z.user.lastName]}),Z.isNew&&(0,l.jsx)("span",{className:"ml-2 text-xs bg-green-100 text-green-700 px-1.5 py-0.5 rounded",children:"New student"})]}),(0,l.jsx)("button",{onClick:()=>$(null),className:"text-xs text-gray-400 hover:text-gray-600",children:"\u21a9 Back"})]}),(0,l.jsx)("div",{className:"grid grid-cols-4 gap-3 mb-3",children:[["L","Listening"],["R","Reading"],["W","Writing"],["S","Speaking"]].map(e=>{let[t,s]=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:s}),(0,l.jsxs)("select",{value:ee[t]||"",onChange:e=>te(s=>(0,a.A)((0,a.A)({},s),{},{[t]:e.target.value})),className:"border rounded px-2 py-1.5 text-sm w-full",children:[(0,l.jsx)("option",{value:"",children:"\u2014"}),de.map(e=>(0,l.jsx)("option",{value:e,children:e},e))]})]},t)})}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:()=>(async e=>{if(!Z)return;ne(!0);const{L:t,R:s,W:n,S:l}=ee;try{let o=Z.id;const i="".concat(Z.user.firstName," ").concat(Z.user.lastName);if(Z.isNew){const e=await(0,r.n)("/students",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({firstName:Z.user.firstName,lastName:Z.user.lastName})}),t=await e.json();if(!t.success)return void alert(t.message||"Failed to create student");o=t.data.id}await(0,r.n)("/exams/".concat(e,"/results"),{method:"POST",body:JSON.stringify({results:[{studentId:o,absent:!1,listeningScore:""!==t?Number(t):null,readingScore:""!==s?Number(s):null,writingScore:""!==n?Number(n):null,speakingScore:""!==l?Number(l):null}]})});const c=d.find(t=>
1t.id===e),x="".concat(e,":").concat(o);R(t=>[...t,{key:x,examId:e,examTitle:(null===c||void 0===c?void 0:c.title)||"",examDate:(null===c||void 0===c?void 0:c.date)||"",studentId:o,name:i}]),L(e=>(0,a.A)((0,a.A)({},e),{},{[x]:{L:t,R:s,W:n,S:l}})),$(null),te({L:"",R:"",W:"",S:""}),V(null)}catch(o){console.error(o),alert("Error adding student")}finally{ne(!1)}})(e.id),disabled:se,className:"bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-1.5 rounded text-sm font-medium disabled:opacity-50",children:se?"Adding...":"+ Add to Exam"}),(0,l.jsx)("button",{onClick:()=>{V(null),$(null),te({L:"",R:"",W:"",S:""})},className:"bg-white border border-gray-200 hover:border-gray-300 text-gray-600 px-4 py-1.5 rounded text-sm",children:"Cancel"})]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{type:"text",value:Y,onChange:e=>q(e.target.value),placeholder:"Type student name...",autoFocus:!0,className:"w-full border border-indigo-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400"}),Q&&(0,l.jsx)("span",{className:"absolute right-3 top-2.5 text-xs text-gray-400",children:"Searching\u2026"})]}),J.length>0&&(0,l.jsx)("ul",{className:"mt-2 bg-white border border-gray-200 rounded-lg shadow max-h-48 overflow-y-auto text-sm",children:J.map(e=>{var t;const s=null===(t=e.enrollments)||void 0===t?void 0:t.map(e=>{var t;return null===(t=e.group)||void 0===t?void 0:t.name}).filter(Boolean).join(", ");return(0,l.jsxs)("li",{onClick:()=>{$(e),q(""),K([])},className:"px-4 py-2.5 hover:bg-indigo-50 cursor-pointer border-b border-gray-50 last:border-0",children:[(0,l.jsxs)("span",{className:"font-medium text-[#002147]",children:[e.user.firstName," ",e.user.lastName]}),s&&(0,l.jsx)("span",{className:"ml-2 text-xs text-gray-400",children:s})]},e.id)})}),Y.trim()&&!Q&&0===J.length&&(0,l.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Not found in your students."}),(0,l.jsxs)("button",{onClick:()=>{const e=Y.trim().split(/\s+/);$({id:null,user:{firstName:e[0],lastName:e.slice(1).join(" ")||e[0]},isNew:!0}),q(""),K([])},className:"text-xs bg-green-600 hover:bg-green-700 text-white px-2.5 py-1 rounded font-medium",children:['+ Add "',Y.trim(),'" as new student']})]})]})})]},e.id)),(0,l.jsxs)("p",{className:"text-xs text-[#708090] mb-3",children:[t.length," of ",e.length," students (your groups)"]}),(0,l.jsx)("div",{className:"bg-white rounded-xl shadow border border-gray-100 overflow-hidden",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-[#002147] text-white",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"Student"}),(0,l.jsx)("th",{className:"px-3 py-3 text-left",children:"Exam"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center text-blue-300",children:"L"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center text-blue-300",children:"R"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center text-blue-300",children:"W"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center text-purple-300",children:"S \u270f\ufe0f"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center text-green-300",children:"Overall"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center"})]})}),(0,l.jsx)("tbody",{children:t.map((e,t)=>{var s;const n=D[e.key]||{},o=(e=>{const t=[e.L,e.R,e.W,e.S].map(e=>""!==e&&null!=e?parseFloat(e):null).filter(e=>null!==e&&!isNaN(e));return t.length?Math.round(t.reduce((e,t)=>e+t,0)/t.length*2)/2:null})(n),i=B===e.key;return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsx)("td",{className:"px-4 py-2 font-medium text-[#002147]",children:e.name}),(0,l.jsxs)("td",{className:"px-3 py-2 text-xs",children:[(0,l.jsx)("button",{onClick:()=>{const t=d.find(t=>t.id===e.examId);t&&p(t)},className:"text-left hover:text-blue-600 hover:underline cursor-pointer text-[#002147] font-medium",children:e.examTitle}),(0,l.jsx)("br",{}),(0,l.jsx)("span",{className:"text-[#708090]",children:new Date(e.examDate).toLocaleDateString("en-GB")})]}),(0,l.jsx)("td",{className:"px-3 py-2 text-center text-[#708090]",children:""!==n.L&&null!=n.L?n.L:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-2 text-center text-[#708090]",children:""!==n.R&&null!=n.R?n.R:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-2 text-center text-[#708090]",children:""!==n.W&&null!=n.W?n.W:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-2 text-center",children:(0,l.jsx)("input",{type:"number",min:0,max:9,step:.5,value:null!==(s=n.S)&&void 0!==s?s:"",onCh
1ange:t=>{const s=t.target.value;L(t=>(0,a.A)((0,a.A)({},t),{},{[e.key]:(0,a.A)((0,a.A)({},t[e.key]),{},{S:s})}))},className:"w-16 border border-purple-400 rounded px-2 py-1 text-center text-sm focus:outline-none focus:border-purple-600",placeholder:"0\u20139"})}),(0,l.jsx)("td",{className:"px-3 py-2 text-center font-bold ".concat(null!==o?o>=5?"text-green-600":"text-red-500":"text-gray-400"),children:null!==o?o:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-2 text-center",children:(0,l.jsx)("button",{onClick:()=>(async e=>{const t=D[e.key]||{};M(e.key);try{await(0,r.n)("/exams/".concat(e.examId,"/results"),{method:"POST",body:JSON.stringify({results:[{studentId:e.studentId,absent:!1,listeningScore:""!==t.L?Number(t.L):null,readingScore:""!==t.R?Number(t.R):null,writingScore:""!==t.W?Number(t.W):null,speakingScore:""!==t.S?Number(t.S):null}]})})}finally{M(null)}})(e),disabled:i,className:"px-3 py-1 text-xs bg-[#002147] text-white rounded-lg disabled:opacity-50 hover:bg-[#001a39]",children:i?"...":"Save"})})]},e.key)})})]})})]})})():x?(0,l.jsx)("p",{className:"text-[#708090]",children:"Loading..."}):0===d.length?(0,l.jsx)("p",{className:"text-[#708090]",children:"No exams for this group yet."}):(0,l.jsx)("div",{className:"space-y-3",children:d.filter(e=>!T||e.title.toLowerCase().includes(T.toLowerCase())).map(e=>{var t,s;return(0,l.jsx)("div",{className:"bg-white rounded-xl p-5 shadow border border-gray-100",children:(0,l.jsxs)("div",{className:"flex items-start justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,l.jsx)("p",{className:"font-semibold text-[#002147]",children:e.title}),(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(Ce[e.status]||""),children:e.status})]}),(0,l.jsxs)("p",{className:"text-sm text-[#708090]",children:[new Date(e.date).toLocaleDateString("en-GB"),e.subject?" \xb7 ".concat(e.subject):""," \xb7 ",e.type]}),(0,l.jsxs)("p",{className:"text-xs text-[#708090] mt-1",children:["Max: ",e.maxScore," \xb7 Pass: ",e.passingScore,e.gradedCount>0?" \xb7 Avg: ".concat(e.avgScore," \xb7 Pass rate: ").concat(e.passRate,"%"):""," \xb7 ",null!==(t=null===(s=e._count)||void 0===s?void 0:s.results)&&void 0!==t?t:0," graded"]}),e.fileUrl&&(0,l.jsx)("a",{href:"".concat(N.H).concat(e.fileUrl),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:underline mt-1",children:"\ud83d\udcce Attached file"})]}),(0,l.jsx)("button",{onClick:()=>p(e),className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:"COMPLETED"===e.status?"View Grades":"Enter Grades"})]})},e.id)})}),re&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:50,padding:"1rem"},children:(0,l.jsxs)("div",{style:{background:"white",borderRadius:"12px",width:"100%",maxWidth:"900px",padding:"1.5rem",boxShadow:"0 20px 60px rgba(0,0,0,0.2)",maxHeight:"92vh",overflowY:"auto"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1rem"},children:[(0,l.jsx)("h3",{style:{margin:0,fontWeight:"800",color:"#002147",fontSize:"1.1rem"},children:"\ud83d\udce5 Import from Examy"}),(0,l.jsx)("button",{onClick:()=>ae(!1),style:{background:"none",border:"none",fontSize:"1.3rem",cursor:"pointer",color:"#6b7280"},children:"\u2715"})]}),ge?(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:"8px",padding:"1rem",marginBottom:"1rem"},children:[(0,l.jsx)("p",{style:{fontWeight:"700",color:"#065f46",marginBottom:"0.4rem"},children:"\u2705 Import complete"}),ge.exams.map(e=>(0,l.jsxs)("p",{style:{fontSize:"0.875rem",color:"#374151"},children:[(0,l.jsx)("strong",{children:e.title})," \u2014 ",e.imported," student",1!==e.imported?"s":""," imported",e.unmatched.length>0&&(0,l.jsxs)("span",{style:{color:"#dc2626"},children:[" \xb7 ",e.unmatched.length," not found: ",e.unmatched.join(", ")]})]},e.id))]}),(null===(e=ge.unmatched)||void 0===e?void 0:e.length)>0&&(()=>{const e=ge.unmatched,t=e.filter(e=>{var t;return null===(t=Ne[e])||void 0===t?void 0:t.studentId}).length;return(0,l.jsxs)("div",{style:{background:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px",padding:"1rem",marginBottom:"1rem"},children:[(0,l.jsxs)("p",{style:{fontWeight:"700",color:"#991b1b",marginBottom:"0.75rem",fontSize:"0.85rem"},children:["\u26a0\ufe0f ",e.length," name",1!==e.length?"s":""," not found \u2014 search and link them:"]}),e.map(e=>{const t=Ne[e]||{},s=t.pickerSearch||"",n=s.length>=2?be.filter(e=>"".concat(e.firstName," ").concat(e.lastName).toLowerCase().includes(s.toLowerCase())||"".concat(e.lastName," ").concat(e.firstName).toLowerCase().includes(s.toLowerCase())).slice(0,8):[];return(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",marginBottom:"0.6rem",flexWrap:"wrap"},children:[(0,l.jsx)("span",{style:{fontSize:"0.825rem",fontWeight:"600",color:"#7f1d1d",minWidth:"160px"},children:e}),(0,l.jsx)("span",{style:{color:"#9ca3af",fontSize:"0.8rem"},children:"\u2192"}),t.studentId?(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.4rem"},children:[(0,l.jsxs)("span",{style:{color:"#059669",fontWeight:"600",fontSize:"0.825rem"},children:["\u2713 ",t.matchedName]}),(0,l.jsx)("button",{onClick:()=>Se(t=>(0,a.A)((0,a.A)({},t),{},{[e]:{}})),style:{background:"none",border:"none",cursor:"pointer",color:"#9ca3af",fontSize:"0.75rem"},children:"\u2715"})]}):(0,l.jsxs)("div",{style:{position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search CRM student\u2026",value:s,onChange:t=>Se(s=>(0,a.A)((0,a.A)({},s),{},{[e]:(0,a.A)((0,a.A)({},s[e]),{},{pickerSearch:t.target.value})})),style:{border:"1.5px solid #f97316",borderRadius:"6px",padding:"0.3rem 0.6rem",fontSize:"0.8rem",width:"200px"}}),n.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,zIndex:100,background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.12)",minWidth:"200px",maxHeight:"180px",overflowY:"auto"},children:n.map(t=>(0,l.jsxs)("div",{onClick:()=>Se(s=>(0,a.A)((0,a.A)({},s),{},{[e]:{studentId:t.id,matchedName:"".concat(t.firstName," ").concat(t.lastName),pickerSearch:""}})),style:{padding:"0.45rem 0.75rem",cursor:"pointer",fontSize:"0.825rem",borderBottom:"1px solid #f3f4f6"},onMouseEnter:e=>e.currentTarget.style.background="#f0fdf4",onMouseLeave:e=>e.currentTarget.style.background="white",children:[t.firstName," ",t.lastName]},t.id))})]})]},e)}),t>0&&(0,l.jsx)("button",{disabled:we,onClick:async()=>{ke(!0);try{const e=(ie||[]).filter(e=>{var t;return null===(t=Ne[e.fullName])||void 0===t?void 0:t.studentId}).map(e=>(0,a.A)((0,a.A)({},e),{},{studentId:Ne[e.fullName].studentId}));if(!e.length)return;const t=await(0,r.n)("/exams/import-examy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rows:e,title:ue||void 0})}),s=await t.json();s.success&&(fe(s.data),Se({}),Ae("mock"===A?"none":o))}finally{ke(!1)}},style:{marginTop:"0.75rem",padding:"0.5rem 1.25rem",background:we?"#9ca3af":"#059669",color:"white",border:"none",borderRadius:"7px",fontWeight:"700",cursor:we?"not-allowed":"pointer",fontSize:"0.85rem"},children:we?"Saving\u2026":"\ud83d\udcbe Save ".concat(t," student").concat(1!==t?"s":"")})]})})(),(0,l.jsx)("button",{onClick:()=>ae(!1),style:{padding:"0.6rem 1.5rem",background:"#002147",color:"white",border:"none",borderRadius:"8px",fontWeight:"700",cursor:"pointer"},children:"Done"})]}):ie?(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{display:"flex",gap:"0.75rem",alignItems:"center",marginBottom:"1rem",flexWrap:"wrap"},children:[(0,l.jsxs)("div",{style:{flex:1,minWidth:"200px"},children:[(0,l.jsx)("label",{style:{fontSize:"0.8rem",fontWeight:"600",display:"block",marginBottom:"0.25rem"},children:"Exam Title"}),(0,l.jsx)("input",{type:"text",value:ue,onChange:e=>me(e.target.value),style:{width:"100%",border:"1.5px solid #e5e7eb",borderRadius:"7px",padding:"0.45rem 0.6rem",fontSize:"0.85rem",boxSizing:"border-box"}})]}),(0,l.jsxs)("p",{style:{fontSize:"0.8rem",color:"#6b7280",marginTop:"1.2rem"},children:[ie.length," rows \xb7 ",ie.filter(e=>e.studentId).length," matched \xb7 ",(0,l.jsxs)("span",{style:{color:"#dc2626",fontWeight:"600"},children:[ie.filter(e=>!e.studentId).length," unmatched"]})]})]}),(0,l.jsx)("div",{style:{overflowX:"auto",border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"1rem"},children:(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"0.825rem"},children:[(0,l.jsx)("thead",{style:{background:"#f3f4f6"},children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"left",fontWeight:"600",whiteSpace:"nowrap"},children:"Examy Name"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"left",fontWeight:"600",whiteSpace:"nowrap"},children:"CRM Student"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600"},children:"Date"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600",color:"#2563eb"},children:"L"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600",color:"#2563eb"},children:"R"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600",color:"#2563eb"},children:"W"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600",color:"#7c3aed"},children:"S \u270f\ufe0f"}),(0,l.jsx)("th",{style:{padding:"0.6rem",textAlign:"center",fontWeight:"600",color:"#059669"},children:"Overall \u270f\ufe0f"})]})}),(0,l.jsx)("tbody",{children:ie.map((e,t)=>{var s;const n=ve[t]||"",r=n.length>=2?be.filter(e=>"".concat(e.firstName," ").concat(e.lastName).toLowerCase().includes(n.toLowerCase())||"".concat(e.lastName," ").concat(e.firstName).toLowerCase().includes(n.toLowerCase())).slice(0,8):[];return(0,l.jsxs)("tr",{style:{borderTop:"1px solid #e5e7eb",background:e.studentId?"white":"#fff7ed"},children:[(0,l.jsx)("td",{style:{padding:"0.5rem 0.6rem",fontWeight:"500",color:e.studentId?"#111827":"#92400e"},children:e.fullName}),(0,l.jsx)("td",{style:{padding:"0.4rem 0.6rem",minWidth:"180px"},children:e.studentId?(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.4rem"},children:[(0,l.jsxs)("span",{style:{color:"#059669",fontWeight:"600",fontSize:"0.8rem"},children:["\u2713 ",e.matchedName]}),(0,l.jsx)("button",{onClick:()=>{const e=[...ie];e[t]=(0,a.A)((0,a.A)({},e[t]),{},{studentId:null,matchedName:null}),ce(e),je(e=>(0,a.A)((0,a.A)({},e),{},{[t]:""}))},style:{background:"none",border:"none",cursor:"pointer",color:"#9ca3af",fontSize:"0.75rem",padding:"0"},children:"\u2715"})]}):(0,l.jsxs)("div",{style:{position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search student\u2026",value:n,onChange:e=>je(s=>(0,a.A)((0,a.A)({},s),{},{[t]:e.target.value})),style:{width:"100%",border:"1.5px solid #f97316",borderRadius:"5px",padding:"0.3rem 0.5rem",fontSize:"0.8rem",boxSizing:"border-box",background:"#fff7ed"}}),r.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,zIndex:100,background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",maxHeight:"200px",overflowY:"auto"},children:r.map(e=>(0,l.jsxs)("div",{onClick:()=>{const s=[...ie];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{studentId:e.id,matchedName:"".concat(e.firstName," ").concat(e.lastName)}),ce(s),je(e=>(0,a.A)((0,a.A)({},e),{},{[t]:""}))},style:{padding:"0.5rem 0.75rem",cursor:"pointer",fontSize:"0.825rem",borderBottom:"1px solid #f3f4f6"},onMouseEnter:e=>e.currentTarget.style.background="#f0fdf4",onMouseLeave:e=>e.currentTarget.style.background="white",children:[e.firstName," ",e.lastName]},e.id))})]})}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.6rem",textAlign:"center",color:"#6b7280"},children:null===(s=e.date)||void 0===s?void 0:s.split(" ")[0]}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.6rem",textAlign:"center"},children:e.L||"\u2014"}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.6rem",textAlign:"center"},children:e.R||"\u2014"}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.6rem",textAlign:"center"},children:e.W||"\u2014"}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.3rem",textAlign:"center"},children:(0,l.jsx)("input",{type:"number",min:"0",max:"9",step:"0.5",value:e.S,onChange:e=>{const s=[...ie];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{S:e.target.value});const n=[s[t].L,s[t].R,s[t].W,s[t].S].map(e=>""===e||null==e?null:parseFloat(e)).filter(e=>null!==e);s[t].overall=n.length>0?String(Math.round(n.reduce((e,t)=>
1e+t,0)/n.length*2)/2):"",ce(s)},style:{width:"56px",border:"1.5px solid #7c3aed",borderRadius:"5px",padding:"0.3rem",textAlign:"center",fontSize:"0.825rem"}})}),(0,l.jsx)("td",{style:{padding:"0.5rem 0.3rem",textAlign:"center"},children:(0,l.jsx)("input",{type:"number",min:"0",max:"9",step:"0.5",value:e.overall,onChange:e=>{const s=[...ie];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{overall:e.target.value}),ce(s)},style:{width:"56px",border:"1.5px solid #059669",borderRadius:"5px",padding:"0.3rem",textAlign:"center",fontSize:"0.825rem",fontWeight:"700"}})})]},t)})})]})}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem"},children:[(0,l.jsx)("button",{onClick:()=>ce(null),style:{padding:"0.55rem 1.25rem",background:"#f3f4f6",border:"none",borderRadius:"8px",fontSize:"0.875rem",fontWeight:"600",cursor:"pointer"},children:"\u2190 Back"}),(0,l.jsx)("button",{onClick:async()=>{if(ie&&ie.length){he(!0);try{const e=await(0,r.n)("/exams/import-examy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rows:ie,title:ue||void 0})}),t=await e.json();t.success?(fe(t.data),Ae(o)):alert(t.message||"Import failed")}catch(e){alert("Import error")}finally{he(!1)}}},disabled:pe,style:{padding:"0.55rem 1.5rem",background:pe?"#9ca3af":"#002147",color:"white",border:"none",borderRadius:"8px",fontSize:"0.875rem",fontWeight:"700",cursor:pe?"not-allowed":"pointer"},children:pe?"Importing\u2026":"\u2705 Import Results"})]})]}):(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{style:{fontSize:"0.875rem",color:"#6b7280",marginBottom:"0.75rem"},children:"In Examy, select all rows in the results table, copy (Ctrl+C), then paste below:"}),(0,l.jsx)("textarea",{value:le,onChange:e=>oe(e.target.value),rows:10,placeholder:"Name\tFull name\tExam ID\tType\tDate\tOverall\tL\tR\tW\tS\nPC Two\tAziza Kadirova\t2323e4b\tFull\t2026-05-04 16:52\t4\t5.5\t5\t5.5\t0\n...",style:{width:"100%",border:"1.5px solid #e5e7eb",borderRadius:"8px",padding:"0.75rem",fontSize:"0.8rem",fontFamily:"monospace",boxSizing:"border-box",resize:"vertical"}}),(0,l.jsxs)("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.75rem"},children:[(0,l.jsx)("button",{onClick:()=>ae(!1),style:{padding:"0.55rem 1.25rem",background:"#f3f4f6",border:"none",borderRadius:"8px",fontSize:"0.875rem",fontWeight:"600",cursor:"pointer"},children:"Cancel"}),(0,l.jsx)("button",{onClick:()=>{var e,t;const s=le.trim().split("\n").filter(e=>e.trim());if(s.length<2)return void alert("No data found \u2014 paste the full table including header row");const n=s.slice(1).map(e=>{const t=e.split("\t"),s=(t[6]||"").trim(),n=(t[7]||"").trim(),r=(t[8]||"").trim(),a=[s,n,r].map(e=>"-"===e||""===e?null:parseFloat(e)).filter(e=>null!==e),l=a.length>0?String(Math.round(a.reduce((e,t)=>e+t,0)/a.length*2)/2):"",o=(t[1]||"").trim(),i=(e=>{const t=e.trim().toLowerCase();return be.find(e=>{const s="".concat(e.firstName," ").concat(e.lastName).toLowerCase(),n="".concat(e.lastName," ").concat(e.firstName).toLowerCase();return s===t||n===t})||null})(o);return{fullName:o,date:(t[4]||"").trim(),type:(t[3]||"").trim(),L:"-"===s?"":s,R:"-"===n?"":n,W:"-"===r?"":r,S:"",overall:l,studentId:i?i.id:null,matchedName:i?"".concat(i.firstName," ").concat(i.lastName):null}}).filter(e=>e.fullName);if(!n.length)return void alert("Could not parse any rows");ce(n),je({});const r=(null===(e=n[0])||void 0===e||null===(t=e.date)||void 0===t?void 0:t.split(" ")[0])||"";me("Mock Exam \u2014 ".concat(r))},disabled:!le.trim(),style:{padding:"0.55rem 1.5rem",background:le.trim()?"#4f46e5":"#9ca3af",color:"white",border:"none",borderRadius:"8px",fontSize:"0.875rem",fontWeight:"700",cursor:le.trim()?"pointer":"not-allowed"},children:"Parse \u2192"})]})]})]})})]})}function xe(e){var t;let{exam:s,onBack:o,myStudentIds:i}=e;
1const[d,c]=(0,n.useState)(s),[x,u]=(0,n.useState)([]),[m,p]=(0,n.useState)({}),[h,g]=(0,n.useState)(!0),[f,b]=(0,n.useState)(!1),[y,v]=(0,n.useState)(""),[j,N]=(0,n.useState)(s.status),[S,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)(!1),[C,T]=(0,n.useState)(""),[E,I]=(0,n.useState)(!1),[R,D]=(0,n.useState)({}),[L,z]=(0,n.useState)(!1),[W,B]=(0,n.useState)(!1),[M,P]=(0,n.useState)(""),[O,G]=(0,n.useState)([]),[F,_]=(0,n.useState)(!1),[U,H]=(0,n.useState)(null),[V,Y]=(0,n.useState)({}),q="IELTS"===d.gradingType,J="SECTIONS"===d.gradingType,K=d.sections||[],Q=!d.groupId&&!d.group,X=e=>{const t=[e.listeningScore,e.readingScore,e.writingScore,e.speakingScore].map(e=>""!==e&&null!=e?parseFloat(e):null).filter(e=>null!==e&&!isNaN(e));return t.length?Math.round(t.reduce((e,t)=>e+t,0)/t.length*2)/2:null},Z=e=>e.absent?null:function(e,t){if(!t||!e)return null;let s=0,n=0;for(const r of t){if(!1===r.includeInOverall)continue;const t=e.find(e=>e.name===r.name),a=null!=(null===t||void 0===t?void 0:t.correct)&&""!==t.correct?parseFloat(t.correct):null;null!=a&&r.maxQuestions>0&&(s+=a/r.maxQuestions*100*(r.weight/100),n+=r.weight)}return n>0?Math.round(10*s)/10:null}(e.sectionScores||[],K);(0,n.useEffect)(()=>{const e=s.sections||[];(0,r.n)("/exams/".concat(s.id)).then(e=>e.json()).then(t=>{if(t.success){u(t.data.students||[]);const s={};(t.data.students||[]).forEach(t=>{var n,r,a,l,o;s[t.studentId]={score:null!==(n=t.score)&&void 0!==n?n:"",listeningScore:null!==(r=t.listeningScore)&&void 0!==r?r:"",readingScore:null!==(a=t.readingScore)&&void 0!==a?a:"",writingScore:null!==(l=t.writingScore)&&void 0!==l?l:"",speakingScore:null!==(o=t.speakingScore)&&void 0!==o?o:"",sectionScores:e.map(e=>{var s;const n=null===(s=t.sectionScores)||void 0===s?void 0:s.find(t=>t.name===e.name);return{name:e.name,correct:null!=(null===n||void 0===n?void 0:n.correct)?String(n.correct):""}}),absent:t.absent,notes:t.notes||""}}),p(s)}}).finally(()=>g(!1))},[s.id]),(0,n.useEffect)(()=>{if(!W||!M.trim())return void G([]);const e=setTimeout(async()=>{_(!0);try{const e=await(0,r.n)("/students?search=".concat(encodeURIComponent(M),"&limit=20")),t=await e.json();if(t.success){const e=new Set(x.map(e=>e.studentId)),s=i&&i.size>0?(t.data||[]).filter(e=>i.has(e.id)):t.data||[];G(s.filter(t=>!e.has(t.id)))}}catch(e){console.error(e)}finally{_(!1)}},300);return()=>clearTimeout(e)},[M,W,x]);const $=e=>{H(e),P(""),G([]),Y(q?{listeningScore:"",readingScore:"",writingScore:"",speakingScore:""}:J?{sectionScores:K.map(e=>({name:e.name,correct:""}))}:{score:""})},ee=(()=>{if(J){const e=x.filter(e=>{var t;return!(null!==(t=m[e.studentId])&&void 0!==t&&t.absent)}).map(e=>Z(m[e.studentId]||{})).filter(e=>null!==e),t=e.length?(e.reduce((e,t)=>e+t,0)/e.length).toFixed(1):"\u2014",s=e.filter(e=>e>=Number(d.passingScore)).length;return{avg:t,rate:e.length?Math.round(s/e.length*100):"\u2014",total:e.length}}if(q){const e=x.filter(e=>{var t;return!(null!==(t=m[e.studentId])&&void 0!==t&&t.absent)}).map(e=>X(m[e.studentId]||{})).filter(e=>null!==e),t=e.length?(e.reduce((e,t)=>e+t,0)/e.length).toFixed(1):"\u2014",s=e.filter(e=>e>=Number(d.passingScore)).length;return{avg:t,rate:e.length?Math.round(s/e.length*100):"\u2014",total:e.length}}const e=x.filter(e=>{var t,s,n,r;return!(null!==(t=m[e.studentId])&&void 0!==t&&t.absent)&&""!==(null===(s=m[e.studentId])||void 0===s?void 0:s.score)&&null!==(null===(n=m[e.studentId])||void 0===n?void 0:n.score)&&void 0!==(null===(r=m[e.studentId])||void 0===r?void 0:r.score)}).map(e=>{var t;return Number(null===(t=m[e.studentId])||void 0===t?void 0:t.score)}),t=e.length?(e.reduce((e,t)=>e+t,0)/e.length).toFixed(1):"\u2014",s=e.filter(e=>e>=Number(d.passingScore)).length;return{avg:t,rate:e.length?Math.round(s/e.length*100):"\u2014",total:e.length}})();return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,l.jsx)("button",{onClick:o,className:"flex items-center gap-2 text-[#708090] hover:text-[#002147] text-sm",children:"\u2190 Back to Exams"}),(0,l.jsx)("button",{onClick:()=>{var e;D({title:d.title,subject:d.subject||"",date:new Date(d.date).toISOString().slice(0,10),maxScore:String(d.maxScore),passingScore:String(d.passingScore),type:d.type,gradingType:d.gradingType||"PERCENTAGE",sections:null!==(e=d.sections)&&void 0!==e&&e.length?d.sections.map(e=>(0,a.A)((0,a.A)({},e),{},{includeInOverall:!1!==e.includeInOverall})):[{name:"Section 1",weight:60,maxQuestions:30,includeInOverall:!0},{name:"Section 2",weight:40,maxQuestions:13,includeInOverall:!0}]}),I(!0)},className:"flex items-center gap-2 bg-white border border-gray-300 hover:border-[#002147] text-[#002147] px-4 py-2 rounded-lg text-sm font-medium",children:"\u270f\ufe0f Edit Exam"})]}),(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147] mb-1",children:d.title}),(0,l.jsxs)("p",{className:"text-[#708090] mb-6",children:[null!==(t=d.group)&&void 0!==t&&t.name?"".concat(d.group.name," \xb7 "):"",new Date(d.date).toLocaleDateString("en-GB")," \xb7 ",q?"IELTS Band (max 9)":J?"Sections grading":"Max: ".concat(d.maxScore)," \xb7 Pass: ",d.passingScore,J?"%":""]}),(0,l.jsxs)("div",{className:"flex gap-4 mb-6",children:[(0,l.jsxs)("div",{className:"bg-white rounded-lg px-5 py-3 shadow text-center border border-gray-100",children:[(0,l.jsx)("p",{className:"text-xs text-[#708090] uppercase font-semibold",children:"Avg Score"}),(0,l.jsx)("p",{className:"text-2xl font-bold text-[#002147]",children:ee.avg})]}),(0,l.jsxs)("div",{className:"bg-white rounded-lg px-5 py-3 shadow text-center border border-gray-100",children:[(0,l.jsx)("p",{className:"text-xs text-[#708090] uppercase font-semibold",children:"Pass Rate"}),(0,l.jsxs)("p",{className:"text-2xl font-bold text-green-600",children:[ee.rate,"\u2014"!==ee.rate?"%":""]})]}),(0,l.jsxs)("div",{className:"bg-white rounded-lg px-5 py-3 shadow text-center border border-gray-100",children:[(0,l.jsx)("p",{className:"text-xs text-[#708090] uppercase font-semibold",children:"Graded"}),(0,l.jsx)("p",{className:"text-2xl font-bold text-blue-600",children:ee.total})]})]}),!h&&(0,l.jsxs)("div",{className:"mb-4 flex items-center justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("input",{type:"text",value:C,onChange:e=>T(e.target.value),placeholder:"\ud83d\udd0d Search student...",className:"border border-gray-300 rounded-lg px-3 py-2 text-sm w-64 focus:outline-none focus:border-[#002147]"}),C&&(0,l.jsxs)("span",{className:"text-sm text-[#708090]",children:[x.filter(e=>e.name.toLowerCase().includes(C.toLowerCase())).length," of ",x.length]})]}),Q&&(0,l.jsx)("button",{onClick:()=>{B(e=>!e),P(""),G([]),H(null),Y({})},className:"flex items-center gap-1.5 bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium",children:"+ Add Student"})]}),Q&&W&&(0,l.jsx)("div",{className:"mb-4 rounded-xl border border-indigo-200 bg-indigo-50 px-5 py-4",children:U?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsxs)("p",{className:"text-sm font-medium text-indigo-700",children:["Adding: ",(0,l.jsxs)("span",{className:"font-bold",children:[U.user.firstName," ",U.user.lastName]}),U.isNew&&(0,l.jsx)("span",{className:"ml-2 text-xs bg-green-100 text-green-700 px-1.5 py-0.5 rounded",children:"New student"})]}),(0,l.jsx)("button",{onClick:()=>{H(null),Y({})},className:"text-xs text-gray-400 hover:text-gray-600",children:"\u21a9 Back to search"})]}),q?(0,l.jsx)("div",{className:"grid grid-cols-4 gap-3 mb-3",children:[{field:"listeningScore",label:"Listening"},{field:"readingScore",label:"Reading"},{field:"writingScore",label:"Writing"},{field:"speakingScore",label:"Speaking"}].map(e=>{let{field:t,label:s}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:s}),(0,l.jsxs)("select",{value:V[t]||"",onChange:e=>Y(s=>(0,a.A)((0,a.A)({},s),{},{[t]:e.target.value})),className:"border rounded px-2 py-1.5 text-sm w-full",children:[(0,l.jsx)("option",{value:"",children:"\u2014"}),de.map(e=>(0,l.jsx)("option",{value:e,children:e},e))]})]},t)})}):J?(0,l.jsx)("div",{className:"grid grid-cols-2 gap-3 mb-3",children:K.map(e=>{const t=(V.sectionScores||[]).find(t=>t.name===e.name)||{correct:""};return(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-xs text-gray-500 mb-1",children:[e.name," ",(0,l.jsxs)("span",{className:"text-gray-400",children:["/ ",e.maxQuestions]})]}),(0,l.jsx)("input",{type:"number",value:t.correct,onChange:t=>{const s=(V.sectionScores||K.map(e=>({name:e.name,correct:""}))).map(s=>s.name===e.name?(0,a.A)((0,a.A)({},s),{},{correct:t.target.value}):s);Y(e=>(0,a.A)((0,a.A)({},e),{},{sectionScores:s}))},className:"border rounded px-2 py-1.5 text-sm w-full",min:"0",max:e.maxQuestions,placeholder:"\u2014"})]},e.name)})}):(0,l.jsxs)("div",{className:"mb-3",children:[(0,l.jsxs)("label",{className:"block text-xs text-gray-500 mb-1",children:["Score / ",d.maxScore]}),(0,l.jsx)("input",{type:"number",value:V.score||"",onChange:e=>Y(t=>(0,a.A)((0,a.A)({},t),{},{score:e.target.value})),className:"border rounded px-2 py-1.5 text-sm w-32",min:"0",max:d.maxScore,placeholder:"\u2014"})]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:async()=>
1{if(!U)return;const e="".concat(U.user.firstName," ").concat(U.user.lastName);let t=U.id;if(U.isNew)try{const e=await(0,r.n)("/students",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({firstName:U.user.firstName,lastName:U.user.lastName})}),s=await e.json();if(!s.success)return void alert(s.message||"Failed to create student");t=s.data.id}catch(n){return void alert("Error creating student")}const s={studentId:t,name:e};u(e=>[...e,s]),p(e=>{var s,n,r,l,o,i;return(0,a.A)((0,a.A)({},e),{},{[t]:{score:null!==(s=V.score)&&void 0!==s?s:"",listeningScore:null!==(n=V.listeningScore)&&void 0!==n?n:"",readingScore:null!==(r=V.readingScore)&&void 0!==r?r:"",writingScore:null!==(l=V.writingScore)&&void 0!==l?l:"",speakingScore:null!==(o=V.speakingScore)&&void 0!==o?o:"",sectionScores:null!==(i=V.sectionScores)&&void 0!==i?i:K.map(e=>({name:e.name,correct:""})),absent:!1,notes:""}})}),H(null),Y({}),B(!1)},className:"bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-1.5 rounded text-sm font-medium",children:"+ Add to Exam"}),(0,l.jsx)("button",{onClick:()=>{H(null),Y({}),B(!1)},className:"bg-white border border-gray-200 hover:border-gray-300 text-gray-600 px-4 py-1.5 rounded text-sm",children:"Cancel"})]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"text-sm font-medium text-indigo-700 mb-2",children:"Search and add a student to this mock exam:"}),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{type:"text",value:M,onChange:e=>P(e.target.value),placeholder:"Type student name...",autoFocus:!0,className:"w-full border border-indigo-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400"}),F&&(0,l.jsx)("span",{className:"absolute right-3 top-2.5 text-xs text-gray-400",children:"Searching\u2026"})]}),O.length>0&&(0,l.jsx)("ul",{className:"mt-2 bg-white border border-gray-200 rounded-lg shadow max-h-48 overflow-y-auto text-sm",children:O.map(e=>{var t;const s=null===(t=e.enrollments)||void 0===t?void 0:t.map(e=>{var t;return null===(t=e.group)||void 0===t?void 0:t.name}).filter(Boolean).join(", ");return(0,l.jsxs)("li",{onClick:()=>$(e),className:"px-4 py-2.5 hover:bg-indigo-50 cursor-pointer border-b border-gray-50 last:border-0",children:[(0,l.jsxs)("span",{className:"font-medium text-[#002147]",children:[e.user.firstName," ",e.user.lastName]}),s&&(0,l.jsx)("span",{className:"ml-2 text-xs text-gray-400",children:s})]},e.id)})}),M.trim()&&!F&&0===O.length&&(0,l.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Not found in your students."}),(0,l.jsxs)("button",{onClick:()=>{const e=M.trim().split(/\s+/);$({id:null,user:{firstName:e[0],lastName:e.slice(1).join(" ")||e[0]},isNew:!0,enrollments:[]})},className:"text-xs bg-green-600 hover:bg-green-700 text-white px-2.5 py-1 rounded font-medium",children:['+ Add "',M.trim(),'" as new student']})]})]})}),h?(0,l.jsx)("p",{className:"text-[#708090]",children:"Loading students..."}):(0,l.jsx)("div",{className:"bg-white rounded-xl shadow border border-gray-100 overflow-hidden mb-5",style:{overflowX:"auto"},children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-[#002147] text-white",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"#"}),(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"Student"}),q?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#93c5fd"},children:"L"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#93c5fd"},children:"R"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#93c5fd"},children:"W"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#d8b4fe"},children:"S \u270f\ufe0f"}),(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#6ee7b7"},children:"Overall"})]}):J?(0,l.jsxs)(l.Fragment,{children:[K.map(e=>(0,l.jsxs)("th",{className:"px-3 py-3 text-center",style:{whiteSpace:"nowrap",color:"#93c5fd"},children:[(0,l.jsx)("div",{children:e.name}),(0,l.jsxs)("div",{style:{fontSize:"0.7rem",fontWeight:"normal",color:"#bfdbfe"},children:["/",e.maxQuestions,!1!==e.includeInOverall?" \xb7 ".concat(e.weight,"%"):" \xb7 info"]})]},e.name)),(0,l.jsx)("th",{className:"px-3 py-3 text-center",style:{color:"#6ee7b7"},children:"Overall %"})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Score"}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Grade"}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Status"})]}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Absent"}),(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"Notes"})]})}),(0,l.jsx)("tbody",{children:x.filter(e=>!C||e.name.toLowerCase().includes(C.toLowerCase())).map((e,t)=>{var s,n;const r=m[e.studentId]||{};if(q){var o,i;const s=r.absent?null:X(r),n=null!==s&&s>=Number(d.passingScore);return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsx)("td",{className:"px-4 py-3 text-[#708090]",children:t+1}),(0,l.jsx)("td",{className:"px-4 py-3 font-medium text-[#002147]",children:e.name}),(0,l.jsx)("td",{className:"px-3 py-3 text-center text-[#708090]",children:r.absent?"\u2014":""!==r.listeningScore&&null!=r.listeningScore?r.listeningScore:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-3 text-center text-[#708090]",children:r.absent?"\u2014":""!==r.readingScore&&null!=r.readingScore?r.readingScore:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-3 text-center text-[#708090]",children:r.absent?"\u2014":""!==r.writingScore&&null!=r.writingScore?r.writingScore:"\u2014"}),(0,l.jsx)("td",{className:"px-3 py-2 text-center",children:(0,l.jsx)("input",{type:"number",min:0,max:9,step:.5,disabled:r.absent,value:r.absent?"":null!==(o=r.speakingScore)&&void 0!==o?o:"",onCh
1ange:t=>{const s=t.target.value,n=(0,a.A)((0,a.A)({},r),{},{speakingScore:s}),l=X(n);p(t=>(0,a.A)((0,a.A)({},t),{},{[e.studentId]:(0,a.A)((0,a.A)({},n),{},{score:null!==l?l:""})}))},className:"w-16 border border-purple-400 rounded px-2 py-1 text-center text-sm disabled:bg-gray-100 focus:outline-none focus:border-purple-600",placeholder:"0\u20139"})}),(0,l.jsx)("td",{className:"px-3 py-3 text-center font-bold text-base ".concat(null!==s?n?"text-green-600":"text-red-600":"text-gray-400"),children:r.absent?"\u2014":null!==s?s:"\u2014"}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:(0,l.jsx)("input",{type:"checkbox",checked:null!==(i=r.absent)&&void 0!==i&&i,onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{absent:t.target.checked})})),className:"w-4 h-4 accent-red-500"})}),(0,l.jsx)("td",{className:"px-4 py-3",children:(0,l.jsx)("input",{value:r.notes||"",onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{notes:t.target.value})})),placeholder:"Notes...",className:"w-full border border-gray-200 rounded px-2 py-1 text-xs focus:outline-none focus:border-[#002147]"})})]},e.studentId)}if(J){var c;const s=Z(r),n=null!==s&&s>=Number(d.passingScore);return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsx)("td",{className:"px-4 py-3 text-[#708090]",children:t+1}),(0,l.jsx)("td",{className:"px-4 py-3 font-medium text-[#002147]",children:e.name}),r.absent?(0,l.jsx)("td",{colSpan:K.length+1,className:"px-4 py-3 text-center text-red-400 text-xs",children:"Absent"}):(0,l.jsxs)(l.Fragment,{children:[K.map(t=>{const s=(r.sectionScores||[]).find(e=>e.name===t.name)||{name:t.name,correct:""},n=""!==s.correct&&null!=s.correct&&t.maxQuestions>0?Math.round(parseFloat(s.correct)/t.maxQuestions*100*10)/10:null;return(0,l.jsxs)("td",{className:"px-3 py-3 text-center",children:[(0,l.jsxs)("div",{className:"flex items-center justify-center gap-1",children:[(0,l.jsx)("input",{type:"number",value:s.correct,onChange:s=>{return n=e.studentId,r=t.name,l=s.target.value,void p(e=>(0,a.A)((0,a.A)({},e),{},{[n]:(0,a.A)((0,a.A)({},e[n]),{},{sectionScores:(e[n].sectionScores||[]).map(e=>e.name===r?(0,a.A)((0,a.A)({},e),{},{correct:l}):e)})}));var n,r,l},className:"border border-gray-300 rounded px-1 py-1 w-14 text-center text-sm focus:outline-none focus:border-[#002147]",min:"0",max:t.maxQuestions,placeholder:"\u2014"}),(0,l.jsxs)("span",{className:"text-xs text-gray-400",children:["/",t.maxQuestions]})]}),null!=n&&(0,l.jsxs)("div",{className:"text-xs text-gray-500 mt-0.5",children:[n,"%",!1===t.includeInOverall?" \u2139":""]})]},t.name)}),(0,l.jsx)("td",{className:"px-3 py-3 text-center font-bold ".concat(null!==s?n?"text-green-600":"text-red-600":"text-gray-400"),children:null!==s?"".concat(s,"%"):"\u2014"})]}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:(0,l.jsx)("input",{type:"checkbox",checked:null!==(c=r.absent)&&void 0!==c&&c,onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{absent:t.target.checked})})),className:"w-4 h-4 accent-red-500"})}),(0,l.jsx)("td",{className:"px-4 py-3",children:(0,l.jsx)("input",{value:r.notes||"",onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{notes:t.target.value})})),placeholder:"Notes...",className:"w-full border border-gray-200 rounded px-2 py-1 text-xs focus:outline-none focus:border-[#002147]"})})]},e.studentId)}const x=r.absent?null:""!==r.score&&void 0!==r.score?Number(r.score):null,u=null!==x?function(e,t){const s=e/t*100;return s>=80?"A":s>=65?"B":s>=50?"C":s>=40?"D":"F"}(x,Number(d.maxScore),Number(d.passingScore)):null,h=null!==x&&x>=Number(d.passingScore);return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsx)("td",{className:"px-4 py-3 text-[#708090]",children:t+1}),(0,l.jsx)("td",{className:"px-4 py-3 font-medium text-[#002147]",children:e.name}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:(0,l.jsx)("input",{type:"number",min:0,max:d.maxScore,disabled:r.absent,value:r.absent?"":null!==(s=r.score)&&void 0!==s?s:"",onCh
1ange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{score:t.target.value})})),className:"w-20 border border-gray-300 rounded px-2 py-1 text-center text-sm disabled:bg-gray-100 focus:outline-none focus:border-[#002147]",placeholder:"0"})}),(0,l.jsx)("td",{className:"px-4 py-3 text-center font-bold text-lg ".concat(ie[u]||"text-gray-400"),children:r.absent?"\u2014":u||"\u2014"}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:r.absent?(0,l.jsx)("span",{className:"text-xs text-gray-500",children:"Absent"}):null===x?(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"\u2014"}):h?(0,l.jsx)("span",{className:"text-xs font-semibold text-green-600",children:"Pass"}):(0,l.jsx)("span",{className:"text-xs font-semibold text-red-600",children:"Fail"})}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:(0,l.jsx)("input",{type:"checkbox",checked:null!==(n=r.absent)&&void 0!==n&&n,onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{absent:t.target.checked,score:""})})),className:"w-4 h-4 accent-red-500"})}),(0,l.jsx)("td",{className:"px-4 py-3",children:(0,l.jsx)("input",{value:r.notes||"",onChange:t=>p(s=>(0,a.A)((0,a.A)({},s),{},{[e.studentId]:(0,a.A)((0,a.A)({},s[e.studentId]),{},{notes:t.target.value})})),placeholder:"Notes...",className:"w-full border border-gray-200 rounded px-2 py-1 text-xs focus:outline-none focus:border-[#002147]"})})]},e.studentId)})})]})}),(0,l.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,l.jsx)("button",{onClick:async()=>{b(!0),v("");const e=x.map(e=>{var t;const s=m[e.studentId]||{};var n,r;return q?{studentId:e.studentId,absent:null!==(n=s.absent)&&void 0!==n&&n,notes:s.notes||"",listeningScore:s.absent?null:""!==s.listeningScore&&null!=s.listeningScore?Number(s.listeningScore):null,readingScore:s.absent?null:""!==s.readingScore&&null!=s.readingScore?Number(s.readingScore):null,writingScore:s.absent?null:""!==s.writingScore&&null!=s.writingScore?Number(s.writingScore):null,speakingScore:s.absent?null:""!==s.speakingScore&&null!=s.speakingScore?Number(s.speakingScore):null}:J?{studentId:e.studentId,absent:null!==(r=s.absent)&&void 0!==r&&r,notes:s.notes||"",sectionScores:s.absent?[]:(s.sectionScores||[]).map(e=>({name:e.name,correct:""!==e.correct?parseFloat(e.correct):null}))}:{studentId:e.studentId,score:s.absent?null:""!==s.score?Number(s.score):null,absent:null!==(t=s.absent)&&void 0!==t&&t,notes:s.notes||""}});try{const t=await(0,r.n)("/exams/".concat(d.id,"/results"),{method:"POST",body:JSON.stringify({results:e})}),s=await t.json();s.success?(v("\u2705 Grades saved!"),N("COMPLETED")):v(s.message||"Error")}catch(t){v("Error saving")}finally{b(!1)}},disabled:f||h,className:"px-6 py-2.5 bg-[#002147] text-white rounded-lg hover:bg-[#001a39] font-medium disabled:opacity-60",children:f?"Saving...":"\ud83d\udcbe Save Grades"}),(0,l.jsx)("button",{onClick:async()=>{A(!0);try{const e=await(0,r.n)("/exams/".concat(d.id,"/export")),t=await e.blob(),s=URL.createObjectURL(t),n=document.createElement("a");n.href=s,n.download="".concat(d.title||"exam-results",".xlsx"),n.click(),URL.revokeObjectURL(s)}catch(e){console.error(e),v("\u274c Export failed")}finally{A(!1)}},disabled:k,className:"px-6 py-2.5 bg-green-600 text-white rounded-lg hover:bg-green-700 font-medium disabled:opacity-50",children:k?"Exporting\u2026":"\ud83d\udce5 Export Excel"}),!q&&!J&&(0,l.jsx)("button",{onClick:async()=>{w(!0),v("");try{const e=await(0,r.n)("/exams/".concat(d.id,"/send-telegram"),{method:"POST"}),t=await e.json();v(t.success?"\ud83d\udce4 Sent to Telegram!":"\u274c "+(t.message||"Failed"))}catch(e){v("\u274c Error sending to Telegram")}finally{w(!1)}},disabled:S||"COMPLETED"!==j,title:"COMPLETED"!==j?"Save grades first":"Send results to group Telegram chat",className:"px-6 py-2.5 bg-blue-500 text-white rounded-lg hover:bg-blue-600 font-medium disabled:opacity-40",children:S?"Sending...":"\u2708\ufe0f Send to Telegram"}),y&&(0,l.jsx)("span",{className:"text-sm font-medium ".concat(y.startsWith("\u274c")?"text-red-600":"text-green-600"),children:y})]})]}),E&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",style:{padding:"1rem"},children:(0,l.jsxs)("div",{className:"bg-white rounded-xl p-6 w-full shadow-xl",style:{maxWidth:"520px",maxHeight:"90vh",overflowY:"auto"},children:[(0,l.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,l.jsx)("h3",{className:"text-xl font-bold text-[#002147]",children:"\u270f\ufe0f Edit Exam"}),(0,l.jsx)("button",{onClick:()=>I(!1),className:"text-gray-400 hover:text-gray-600 text-xl",children:"\u2715"})]}),(0,l.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),z(!0);try{const e=await(0,r.n)("/exams/".concat(d.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)}
1),t=await e.json();if(t.success){const e=await(0,r.n)("/exams/".concat(d.id)),t=await e.json();if(t.success){c(t.data);const e=t.data.sections||[];p(t=>{const s={};return Object.keys(t).forEach(n=>{const r=t[n];s[n]=(0,a.A)((0,a.A)({},r),{},{sectionScores:e.map(e=>{var t;const s=(r.sectionScores||[]).find(t=>t.name===e.name);return{name:e.name,correct:null!==(t=null===s||void 0===s?void 0:s.correct)&&void 0!==t?t:""}})})}),s})}I(!1)}else alert(t.message||"Failed to save")}catch(t){alert("Error saving exam")}finally{z(!1)}},className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Title *"}),(0,l.jsx)("input",{type:"text",value:R.title,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",required:!0})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Subject"}),(0,l.jsx)("input",{type:"text",value:R.subject,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{subject:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Date *"}),(0,l.jsx)("input",{type:"date",value:R.date,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",required:!0})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Grading Format"}),(0,l.jsx)("div",{className:"flex gap-2",children:[["PERCENTAGE","% Score"],["IELTS","IELTS Band"],["SECTIONS","Sections"]].map(e=>{let[t,s]=e;return(0,l.jsx)("button",{type:"button",onClick:()=>D(e=>(0,a.A)((0,a.A)({},e),{},{gradingType:t})),className:"px-3 py-1.5 rounded-lg text-xs font-medium border ".concat(R.gradingType===t?"bg-[#002147] text-white border-[#002147]":"bg-white text-[#708090] border-gray-300 hover:border-[#002147]"),children:s},t)})})]}),"SECTIONS"===R.gradingType&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"Sections"}),(()=>{const e=(R.sections||[]).filter(e=>!1!==e.includeInOverall).reduce((e,t)=>e+Number(t.weight),0);return(0,l.jsxs)("span",{className:"text-xs font-semibold ".concat(100===e?"text-green-600":"text-red-500"),children:["Included: ",e,"%"]})})()]}),(0,l.jsx)("div",{className:"space-y-2",children:(R.sections||[]).map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded-lg px-2 py-1.5 ".concat(!1===e.includeInOverall?"bg-gray-100 opacity-70":"bg-gray-50"),children:[(0,l.jsx)("input",{type:"text",value:e.name,onChange:e=>{const s=[...R.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{name:e.target.value}),D(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},placeholder:"Name",className:"border border-gray-300 rounded px-2 py-1 text-sm flex-1"}),(0,l.jsx)("input",{type:"number",value:e.weight,onChange:e=>{const s=[...R.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{weight:Number(e.target.value)}),D(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},disabled:!1===e.includeInOverall,className:"border border-gray-300 rounded px-2 py-1 text-sm w-14 text-center disabled:opacity-40",min:"1",max:"100"}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"%"}),(0,l.jsx)("input",{type:"number",value:e.maxQuestions,onChange:e=>{const s=[...R.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{maxQuestions:Number(e.target.value)}),D(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},className:"border border-gray-300 rounded px-2 py-1 text-sm w-14 text-center",min:"1"}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"Qs"}),(0,l.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:!1!==e.includeInOverall,onChange:e=>{const s=[...R.sections];s[t]=(0,a.A)((0,a.A)({},s[t]),{},{includeInOverall:e.target.checked}),D(e=>(0,a.A)((0,a.A)({},e),{},{sections:s}))},className:"w-3.5 h-3.5 accent-[#002147]"}),(0,l.jsx)("span",{className:"text-xs text-gray-500",children:"Overall"})]}),(0,l.jsx)("button",{type:"button",onClick:()=>D(e=>(0,a.A)((0,a.A)({},e),{},{sections:e.sections.filter((e,s)=>s!==t)})),className:"text-red-400 hover:text-red-600",children:"\u2715"})]},t))}),(0,l.jsx)("button",{type:"button",onClick:()=>D(e=>(0,a.A)((0,a.A)({},e),{},{sections:[...e.sections||[],{name:"",weight:0,maxQuestions:10,includeInOverall:!0}]})),className:"mt-2 text-sm text-[#002147] font-medium hover:underline",children:"+ Add section"})]}),"SECTIONS"!==R.gradingType&&"IELTS"!==R.gradingType&&(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Max Score"}),(0,l.jsx)("input",{type:"number",value:R.maxScore,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{maxScore:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",min:"1"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Passing Score"}),(0,l.jsx)("input",{type:"number",value:R.passingScore,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{passingScore:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",min:"0"})]})]}),"SECTIONS"===R.gradingType&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Passing Overall %"}),(0,l.jsx)("input",{type:"number",value:R.passingScore,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{passingScore:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",min:"0",max:"100"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Type"}
1),(0,l.jsx)("select",{value:R.type,onChange:e=>D(t=>(0,a.A)((0,a.A)({},t),{},{type:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:["WRITTEN","ORAL","PRACTICAL","ONLINE","QUIZ"].map(e=>(0,l.jsx)("option",{children:e},e))})]}),(0,l.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,l.jsx)("button",{type:"submit",disabled:L,className:"flex-1 bg-[#002147] hover:bg-[#001a39] text-white py-2 rounded-lg font-medium text-sm disabled:opacity-60",children:L?"Saving...":"Update Exam"}),(0,l.jsx)("button",{type:"button",onClick:()=>I(!1),className:"flex-1 bg-gray-100 hover:bg-gray-200 text-gray-700 py-2 rounded-lg font-medium text-sm",children:"Cancel"})]})]})]})})]})}function ue(){return(new Date).toISOString().split("T")[0]}function me(e){return e?new Date(e).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):""}const pe={DRAFT:{bg:"#f3f4f6",text:"#6b7280"},ACTIVE:{bg:"#dbeafe",text:"#1d4ed8"},COMPLETED:{bg:"#dcfce7",text:"#15803d"}};function he(){const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!1),[c,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!1),[p,h]=(0,n.useState)(""),[g,f]=(0,n.useState)({title:"",date:ue(),startTime:"09:00",slotDurationMins:15,groupId:"",autoPopulate:!0}),[b,y]=(0,n.useState)(!1),[v,j]=(0,n.useState)(""),[N,S]=(0,n.useState)(!1),[w,k]=(0,n.useState)(""),[A,C]=(0,n.useState)([]),[T,E]=(0,n.useState)(!1),[I,R]=(0,n.useState)("end"),[D,L]=(0,n.useState)(!1),[z,W]=(0,n.useState)("Lunch Break"),[B,M]=(0,n.useState)(30),[P,O]=(0,n.useState)("end"),[G,F]=(0,n.useState)(!1),[_,U]=(0,n.useState)({}
1),[H,V]=(0,n.useState)(!1),[Y,q]=(0,n.useState)({}),[J,K]=(0,n.useState)(null),[Q,X]=(0,n.useState)(null),Z=(0,n.useRef)(null),[$,ee]=(0,n.useState)(null);(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&t(e.data||[])})},[]);const te=(0,n.useCallback)(async()=>{d(!0);try{const e=p?"/speaking-schedules?groupId=".concat(p):"/speaking-schedules",t=await(0,r.n)(e),s=await t.json();s.success&&o(s.data||[])}finally{d(!1)}},[p]);(0,n.useEffect)(()=>{te()},[te]);const se=async()=>{if(!c)return;const e=await(0,r.n)("/speaking-schedules/".concat(c.id)),t=await e.json();t.success&&x(t.data),te()},ne=async e=>{e.preventDefault(),V(!0);try{const e=await(0,r.n)("/speaking-schedules/".concat(c.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,a.A)((0,a.A)({},_),{},{slotDurationMins:_.slotDurationMins?Number(_.slotDurationMins):void 0}))});(await e.json()).success&&(F(!1),se())}finally{V(!1)}};(0,n.useEffect)(()=>{if(!w.trim()||w.length<2)return void C([]);E(!0);const e=setTimeout(async()=>{try{var e;const t=await(0,r.n)("/students?search=".concat(encodeURIComponent(w),"&limit=20")),s=await t.json();s.success&&C((null===(e=s.data)||void 0===e?void 0:e.students)||s.data||[])}finally{E(!1)}},300);return()=>clearTimeout(e)},[w]);const re=(e,t)=>"start"===e?0:"end"===e?t:Number(e),ae=async e=>{e.preventDefault();const t=re(P,c.slots.length),s=await(0,r.n)("/speaking-schedules/".concat(c.id,"/slots"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"BREAK",breakLabel:z,slotDurationMins:Number(B),insertAt:t})}),n=await s.json();n.success&&(x(n.data),L(!1),W("Lunch Break"),M(30),O("end"))};if(c){var le,oe;const e=c.slots||[],t=c;return(0,l.jsxs)("div",{style:{padding:24,maxWidth:900,margin:"0 auto"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:8},children:[(0,l.jsx)("button",{onClick:()=>x(null),style:{background:"none",border:"none",cursor:"pointer",fontSize:20,color:"#6b7280"},children:"\u2190"}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("h2",{style:{margin:0,fontSize:20,fontWeight:700},children:t.title}),(0,l.jsxs)("div",{style:{fontSize:13,color:"#6b7280",marginTop:2},children:[me(t.date)," \xb7 Start: ",t.startTime," \xb7 ",t.slotDurationMins," min/student",t.group&&" \xb7 ".concat(t.group.name)]})]}),(0,l.jsx)("span",{onClick:()=>(async(e,t)=>{const s="DRAFT"===t?"ACTIVE":"ACTIVE"===t?"COMPLETED":"DRAFT";await(0,r.n)("/speaking-schedules/".concat(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:s})}),se()})(t.id,t.status),style:{cursor:"pointer",padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:600,background:null===(le=pe[t.status])||void 0===le?void 0:le.bg,color:null===(oe=pe[t.status])||void 0===oe?void 0:oe.text,userSelect:"none"},title:"Click to change status",children:t.status}),(0,l.jsx)("button",{onClick:()=>{var e;U({title:t.title,date:null===(e=t.date)||void 0===e?void 0:e.split("T")[0],startTime:t.startTime,slotDurationMins:t.slotDurationMins,status:t.status}),F(!0)},style:{padding:"6px 14px",borderRadius:8,border:"1px solid #d1d5db",background:"#fff",cursor:"pointer",fontSize:13},children:"Edit"}),(0,l.jsx)("button",{onClick:()=>(async e=>{window.confirm("Delete this schedule? This cannot be undone.")&&(await(0,r.n)("/speaking-schedules/".concat(e),{method:"DELETE"}),(null===c||void 0===c?void 0:c.id)===e&&x(null),te())})(t.id),style:{padding:"6px 14px",borderRadius:8,border:"1px solid #fca5a5",background:"#fff",color:"#dc2626",cursor:"pointer",fontSize:13},children:"Delete"})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:16,flexWrap:"wrap"},children:[(0,l.jsx)("button",{onClick:()=>{R("end"),S(!0)},style:{padding:"7px 16px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontSize:13,fontWeight:600},children:"+ Add Student"}),(0,l.jsx)("button",{onClick:()=>{O("end"),L(!0)},style:{padding:"7px 16px",borderRadius:8,background:"#f59e0b",color:"#fff",border:"none",cursor:"pointer",fontSize:13,fontWeight:600},children:"\u2615 Add Break"}),(0,l.jsxs)("span",{style:{fontSize:12,color:"#9ca3af",alignSelf:"center",marginLeft:4},children:[e.filter(e=>"STUDENT"===e.type).length," student",1!==e.filter(e=>"STUDENT"===e.type).length?"s":""]}),(0,l.jsx)("div",{style:{flex:1}}),(0,l.jsx)("button",{onClick:()=>(async(e,t)=>{K(e);try{const s=await(0,r.n)("/speaking-schedules/".concat(e,"/export")),n=await s.blob(),a=URL.createObjectURL(n),l=document.createElement("a");l.href=a,l.download="".concat(t,".xlsx"),l.click(),URL.revokeObjectURL(a)}catch(s){alert("Export failed")}finally{K(null)}})(t.id,t.title),disabled:J===t.id,style:{padding:"7px 16px",borderRadius:8,background:"#16a34a",color:"#fff",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,opacity:J===t.id?.6:1},children:J===t.id?"Exporting\u2026":"\ud83d\udce5 Export Excel"}),(0,l.jsx)("button",{onClick:()=>(async e=>{X(e);try{const t=await(0,r.n)("/speaking-schedules/".concat(e,"/send-telegram"),{method:"POST"}),s=await t.json();alert(s.message||(s.success?"Sent!":"Failed"))}catch(t){alert("Failed to send")}finally{X(null)}})(t.id),disabled:Q===t.id,style:{padding:"7px 16px",borderRadius:8,background:"#3b82f6",color:"#fff",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,opacity:Q===t.id?.6:1},children:Q===t.id?"Sending\u2026":"\u2708\ufe0f Send to Telegram"})]}),0===e.length?(0,l.jsx)("div",{style:{textAlign:"center",color:"#9ca3af",padding:"48px 0",border:"2px dashed #e5e7eb",borderRadius:12},children:'No students yet. Click "Add Student" to get started.'}):(0,l.jsx)("div",{style:{border:"1px solid #e5e7eb",borderRadius:12,overflow:"hidden"},children:(0,l.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse"},children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{style:{background:"#f9fafb",fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase",letterSpacing:"0.05em"},children:[(0,l.jsx)("th",{style:{padding:"10px 8px",width:32}}),(0,l.jsx)("th",{style:{padding:"10px 16px",textAlign:"left",width:50},children:"#"}),(0,l.jsx)("th",{style:{padding:"10px 16px",textAlign:"left",width:80},children:"Time"}),(0,l.jsx)("th",{style:{padding:"10px 16px",textAlign:"left"},children:"Student / Break"}),(0,l.jsx)("th",{style:{padding:"10px 16px",textAlign:"center",width:90},children:"Duration"}),(0,l.jsx)("th",{style:{padding:"10px 16px",textAlign:"center",width:60}})]})}),(0,l.jsx)("tbody",{children:e.map((s,n)=>{var o;const i="BREAK"===s.type,d=!!Y[s.id],u=$===n;return(0,l.jsxs)("tr",{draggable:!0,onDragStart:()=>{Z.current=s.id},onDragOver:e=>{e.preventDefault(),ee(n)},onDragLeave:()=>ee(null),onDrop:()=>{ee(null),Z.current&&Z.current!==s.id&&(async(e,t)=>{q(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!0}));try{const s=await(0,r.n)("/speaking-schedules/".concat(c.id,"/slots/").concat(e,"/move"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({newOrder:t})}),n=await s.json();n.success&&x(n.data)}finally{q(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!1}))}})(Z.current,n),Z.current=null},onDragEnd:()=>{ee(null),Z.current=null},style:{borderTop:u?"2px solid #2563eb":"1px solid #f3f4f6",background:i?"#fffbeb":n%2===0?"#fff":"#fafafa",opacity:d?.5:1,transition:"border-top 0.1s"},children:[(0,l.jsx)("td",{style:{padding:"10px 8px",textAlign:"center",cursor:"grab",color:"#9ca3af",fontSize:16,userSelect:"none"},title:"Drag to reorder",children:"\u283f"}),(0,l.jsx)("td",{style:{padding:"10px 16px",color:"#9ca3af",fontSize:13},children:i?"\u2014":e.slice(0,n).filter(e=>"STUDENT"===e.type).length+1}),(0,l.jsx)("td",{style:{padding:"10px 16px",fontWeight:700,fontSize:15,color:i?"#b45309":"#111827"},children:s.computedTime}),(0,l.jsx)("td",{style:{padding:"10px 16px"},children:i?(0,l.jsxs)("span",{style:{color:"#b45309",fontWeight:600},children:["\u2615 ",s.breakLabel||"Break"]}):(0,l.jsxs)("span",{style:{fontWeight:500},children:[s.studentName,!s.studentId&&s.externalStudentName&&(0,l.jsx)("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:6},children:"(external)"})]})}),(0,l.jsxs)("td",{style:{padding:"10px 16px",textAlign:"center",fontSize:13,color:"#6b7280"},children:[null!==(o=s.slotDurationMins)&&void 0!==o?o:t.slotDurationMins," min"]}),(0,l.jsx)("td",{style:{padding:"10px 16px",textAlign:"center"},children:(0,l.jsx)("button",{disabled:d,onClick:()=>(async e=>{q(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!0}));try{const t=await(0,r.n)("/speaking-schedules/".concat(c.id,"/slots/").concat(e),{method:"DELETE"}),s=await t.json();s.success&&x(s.data)}finally{q(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!1}))}})(s.id),style:{padding:"3px 8px",borderRadius:6,border:"1px solid #fca5a5",background:"#fff",color:"#dc2626",cursor:"pointer",fontSize:14},title:"Remove",children:"\u2715"})})]},s.id)})})]})}),G&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,l.jsxs)("form",{onSubmit:ne,style:{background:"#fff",borderRadius:16,padding:32,minWidth:380,maxWidth:480,width:"90%"},children:[(0,l.jsx)("h3",{style:{margin:"0 0 20px",fontSize:18},children:"Edit Schedule"}),(0,l.jsx)("label",{style:ge,children:"Title"}),(0,l.jsx)("input",{style:fe,value:_.title||"",onChange:e=>U(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Date"}),(0,l.jsx)("input",{type:"date",style:fe,value:_.date||"",onChange:e=>U(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Start Time"}),(0,l.jsx)("input",{type:"time",style:fe,value:_.startTime||"",onChange:e=>U(t=>(0,a.A)((0,a.A)({},t),{},{startTime:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Default slot duration (min)"}),(0,l.jsx)("input",{type:"number",min:1,max:120,style:fe,value:_.slotDurationMins||15,onChange:e=>U(t=>(0,a.A)((0,a.A)({},t),{},{slotDurationMins:e.target.value}))}),(0,l.jsx)("label",{style:ge,children:"Status"}),(0,l.jsxs)("select",{style:fe,value:_.status||"DRAFT",onChange:e=>U(t=>(0,a.A)((0,a.A)({},t),{},{status:e.target.value})),children:[(0,l.jsx)("option",{value:"DRAFT",children:"Draft"}),(0,l.jsx)("option",{value:"ACTIVE",children:"Active"}),(0,l.jsx)("option",{value:"COMPLETED",children:"Completed"})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginTop:20,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>F(!1),style:be,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",disabled:H,style:ye,children:H?"Saving\u2026":"Save"})]})]})}),N&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,l.jsxs)("div",{style:{background:"#fff",borderRadius:16,padding:28,minWidth:380,maxWidth:460,width:"90%"},children:[(0,l.jsx)("h3",{style:{margin:"0 0 16px",fontSize:18},children:"Add Student"}),(0,l.jsx)("label",{style:ge,children:"Insert position"}),(0,l.jsxs)("select",{style:fe,value:I,onChange:e=>R(e.target.value),children:[(0,l.jsx)("option",{value:"start",children:"Beginning"}),(0,l.jsx)("option",{value:"end",children:"End"}),e.map((e,t)=>(0,l.jsxs)("option",{value:t+1,children:["After slot ",t+1," (",e.computedTime,")"]},e.id))]}),(0,l.jsx)("label",{style:ge,children:"Search enrolled student"}),(0,l.jsx)("input",{style:fe,placeholder:"Type name\u2026",value:w,autoFocus:!0,onChange:e=>k(e.target.value)}),T&&(0,l.jsx)("div",{style:{fontSize:12,color:"#9ca3af",marginBottom:8},children:"Searching\u2026"}),A.length>0&&(0,l.jsx)("div",{style:{maxHeight:180,overflowY:"auto",border:"1px solid #e5e7eb",borderRadius:8,marginBottom:12},children:A.map(e=>{var t,s;return(0,l.jsxs)("div",{onClick:()=>(async e=>{const t=re(I,c.slots.length),s=await(0,r.n)("/speaking-schedules/".concat(c.id,"/slots"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"STUDENT",studentId:e.id,insertAt:t})}),n=await s.json();n.success&&(x(n.data),k(""),C([]),S(!1))})(e),style:{padding:"8px 14px",cursor:"pointer",fontSize:14,borderBottom:"1px solid #f3f4f6"},onMouseEnter:e=>e.currentTarget.style.background="#f0f9ff",onMouseLeave:e=>e.currentTarget.style.background="",children:[null===(t=e.user)||void 0===t?void 0:t.firstName," ",null===(s=e.user)||void 0===s?void 0:s.lastName,e.studentId&&(0,l.jsxs)("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:6},children:["#",e.studentId]})]},e.id)})}),(0,l.jsxs)("div",{style:{borderTop:"1px solid #f3f4f6",paddingTop:12,marginTop:4},children:[(0,l.jsx)("label",{style:ge,children:"Or add external student (not in system)"}),(0,l.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,l.jsx)("input",{style:(0,a.A)((0,a.A)({},fe),{},{flex:1,marginBottom:0}),placeholder:"Full name",value:w.includes(" ")||0===A.length?w:"",onCh
1ange:e=>k(e.target.value)}),(0,l.jsx)("button",{onClick:()=>(async e=>{if(!e.trim())return;const t=re(I,c.slots.length),s=await(0,r.n)("/speaking-schedules/".concat(c.id,"/slots"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"STUDENT",externalStudentName:e.trim(),insertAt:t})}),n=await s.json();n.success&&(x(n.data),k(""),S(!1))})(w),style:{padding:"8px 16px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:13},children:"Add"})]})]}),(0,l.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:16},children:(0,l.jsx)("button",{onClick:()=>{S(!1),k(""),C([])},style:be,children:"Close"})})]})}),D&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,l.jsxs)("form",{onSubmit:ae,style:{background:"#fff",borderRadius:16,padding:28,minWidth:340,maxWidth:400,width:"90%"},children:[(0,l.jsx)("h3",{style:{margin:"0 0 16px",fontSize:18},children:"\u2615 Add Break"}),(0,l.jsx)("label",{style:ge,children:"Label"}),(0,l.jsx)("input",{style:fe,value:z,onChange:e=>W(e.target.value),required:!0}),(0,l.jsx)("label",{style:ge,children:"Duration (minutes)"}),(0,l.jsx)("input",{type:"number",min:1,max:180,style:fe,value:B,onChange:e=>M(e.target.value),required:!0}),(0,l.jsx)("label",{style:ge,children:"Insert position"}),(0,l.jsxs)("select",{style:fe,value:P,onChange:e=>O(e.target.value),children:[(0,l.jsx)("option",{value:"start",children:"Beginning"}),(0,l.jsx)("option",{value:"end",children:"End"}),e.map((e,t)=>(0,l.jsxs)("option",{value:t+1,children:["After slot ",t+1," (",e.computedTime,")"]},e.id))]}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginTop:20,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>L(!1),style:be,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",style:(0,a.A)((0,a.A)({},ye),{},{background:"#f59e0b"}),children:"Add Break"})]})]})})]})}return(0,l.jsxs)("div",{style:{padding:24,maxWidth:900,margin:"0 auto"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[(0,l.jsx)("h2",{style:{margin:0,fontSize:20,fontWeight:700,flex:1},children:"Speaking Exam Schedules"}),(0,l.jsxs)("select",{style:{padding:"7px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:14,minWidth:160},value:p,onChange:e=>h(e.target.value),children:[(0,l.jsx)("option",{value:"",children:"All groups"}),e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,l.jsx)("button",{onClick:()=>m(!0),style:{padding:"8px 18px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:14},children:"+ New Schedule"})]}),i?(0,l.jsx)("div",{style:{textAlign:"center",color:"#9ca3af",padding:48},children:"Loading\u2026"}):0===s.length?(0,l.jsxs)("div",{style:{textAlign:"center",color:"#9ca3af",padding:"64px 0",border:"2px dashed #e5e7eb",borderRadius:16},children:[(0,l.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\ud83d\udde3\ufe0f"}),(0,l.jsx)("div",{style:{fontSize:16,fontWeight:600,marginBottom:4},children:"No speaking schedules yet"}),(0,l.jsx)("div",{style:{fontSize:13},children:"Create one to schedule speaking exams with timed slots."})]}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:s.map(e=>{var t,s,n,a;const o=pe[e.status]||pe.DRAFT;return(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:12,padding:"14px 20px",background:"#fff",display:"flex",alignItems:"center",gap:16,cursor:"pointer"},onClick:()=>(async e=>{const t=await(0,r.n)("/speaking-schedules/".concat(e)),s=await t.json();s.success&&x(s.data)})(e.id),onMouseEnter:e=>e.currentTarget.style.borderColor="#93c5fd",onMouseLeave:e=>e.currentTarget.style.borderColor="#e5e7eb",children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontWeight:700,fontSize:15},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:12,color:"#6b7280",marginTop:3},children:[me(e.date)," \xb7 ",e.startTime," \xb7 ",e.slotDurationMins," min/slot",e.group&&" \xb7 ".concat(e.group.name)]})]}),(0,l.jsxs)("div",{style:{fontSize:13,color:"#6b7280"},children:[null!==(t=null===(s=e._count)||void 0===s?void 0:s.slots)&&void 0!==t?t:0," slot",1!==(null!==(n=null===(a=e._count)||void 0===a?void 0:a.slots)&&void 0!==n?n:0)?"s":""]}),(0,l.jsx)("span",{style:{padding:"2px 10px",borderRadius:12,fontSize:12,fontWeight:600,background:o.bg,color:o.text},children:e.status})]},e.id)})}),u&&(0,l.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),j(""),g.title&&g.date&&g.startTime){y(!0);try{const e=await(0,r.n)("/speaking-schedules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,a.A)((0,a.A)({},g),{},{groupId:g.groupId||void 0,slotDurationMins:Number(g.slotDurationMins)}))}),t=await e.json();t.success?(m(!1),f({title:"",date:ue(),startTime:"09:00",slotDurationMins:15,groupId:"",autoPopulate:!0}),te(),x(t.data)):j(t.message||"Error creating schedule")}finally{y(!1)}}else j("Title, date and start time are required.")},style:{background:"#fff",borderRadius:16,padding:32,minWidth:380,maxWidth:480,width:"90%"},children:[(0,l.jsx)("h3",{style:{margin:"0 0 20px",fontSize:18},children:"New Speaking Schedule"}),v&&(0,l.jsx)("div",{style:{background:"#fee2e2",color:"#dc2626",padding:"8px 14px",borderRadius:8,marginBottom:14,fontSize:13},children:v}),(0,l.jsx)("label",{style:ge,children:"Title"}),(0,l.jsx)("input",{style:fe,placeholder:"e.g. Intermediate B Speaking \u2014 April",value:g.title,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Date"}),(0,l.jsx)("input",{type:"date",style:fe,value:g.date,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Start Time"}),(0,l.jsx)("input",{type:"time",style:fe,value:g.startTime,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{startTime:e.target.value})),required:!0}),(0,l.jsx)("label",{style:ge,children:"Minutes per student"}),(0,l.jsx)("input",{type:"number",min:1,max:120,style:fe,value:g.slotDurationMins,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{slotDurationMins:e.target.value}))}),(0,l.jsx)("label",{style:ge,children:"Group (optional)"}),(0,l.jsxs)("select",{style:fe,value:g.groupId,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{groupId:e.target.value})),children:[(0,l.jsx)("option",{value:"",children:"\u2014 No group \u2014"}),e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),g.groupId&&(0,l.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"#374151",marginBottom:16,cursor:"pointer"},children:[(0,l.jsx)("input",{type:"checkbox",checked:g.autoPopulate,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{autoPopulate:e.target.checked}))}),"Auto-populate students from group"]}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginTop:4,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>{m(!1),j("")},style:be,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",disabled:b,style:ye,children:b?"Creating\u2026":"Create"})]})]})})]})}const ge={display:"block",fontSize:12,fontWeight:600,color:"#374151",marginBottom:4,marginTop:12,textTransform:"uppercase",letterSpacing:"0.04em"},fe={width:"100%",padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:14,boxSizing:"border-box",marginBottom:4},be={padding:"8px 18px",borderRadius:8,border:"1px solid #d1d5db",background:"#fff",cursor:"pointer",fontSize:14},ye={padding:"8px 20px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:14};function ve(){return(new Date).toISOString().split("T")[0]}function je(e){return e?new Date(e).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):""}function Ne(e){const t=Math.floor(e/60),s=e%60;return 0===s?"".concat(t,"h"):"".concat(t,"h ").concat(s,"m")}const Se={DRAFT:{bg:"#f3f4f6",text:"#6b7280"},SUBMITTED:{bg:"#fef9c3",text:"#92400e"},CONFIRMED:{bg:"#dcfce7",text:"#15803d"},COMPLETED:{bg:"#ede9fe",text:"#6d28d9"}};function we(e){let{schedule:t,isDraft:s,onUpdate:o,maxStudents:i}=e;
1const[d,c]=(0,n.useState)(null),[x,u]=(0,n.useState)(null),[m,p]=(0,n.useState)({}),h=(e,t,s)=>{c({studentId:t.studentId,name:t.name,fromSessionId:s}),e.dataTransfer.effectAllowed="move"},g=()=>{c(null),u(null)},f=[{id:"unassigned",label:"Unassigned",time:null,students:t.unassigned||[]},...(t.sessions||[]).map(e=>({id:e.id,label:"Session ".concat(e.sessionNumber),time:e.startTime,students:e.students}))];return(0,l.jsx)("div",{style:{overflowX:"auto",paddingBottom:8},children:(0,l.jsx)("div",{style:{display:"flex",gap:14,alignItems:"flex-start",minWidth:"max-content"},children:f.map(e=>{const n="unassigned"===e.id,f=!n&&e.students.length>=i,b=x===e.id;return(0,l.jsx)(ke,{col:e,isUnassigned:n,isFull:f,isOver:b,isDraft:s,maxStudents:i,dragInfo:d,busy:m,schedule:t,onDragStart:h,onDragEnd:g,onDragOver:()=>u(e.id),onDragLeave:()=>u(t=>t===e.id?null:t),onDrop:()=>(async e=>{if(!d)return;const{studentId:s,fromSessionId:n}=d;if(c(null),u(null),e===n)return;const l="drag_".concat(s);p(e=>(0,a.A)((0,a.A)({},e),{},{[l]:!0}));try{let a;a="unassigned"===e?await(0,r.n)("/exam-schedules/".concat(t.id,"/sessions/").concat(n,"/students/").concat(s),{method:"DELETE"}):await(0,r.n)("/exam-schedules/".concat(t.id,"/sessions/").concat(e,"/students"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({studentId:s})});const l=await a.json();l.success?o(l.data):alert(l.message||"Error moving student")}finally{p(e=>(0,a.A)((0,a.A)({},e),{},{[l]:!1}))}})(e.id),onUpdate:o,setBusy:p},e.id)})})})}function ke(e){let{col:t,isUnassigned:s,isFull:o,isOver:i,isDraft:d,maxStudents:c,dragInfo:x,busy:u,schedule:m,onDragStart:p,onDragEnd:h,onDragOver:g,onDragLeave:f,onDrop:b,onUpdate:y,setBusy:v}=e;const[j,N]=(0,n.useState)(!1),[S,w]=(0,n.useState)(t.time||"09:00"),[k,A]=(0,n.use
1State)(!1),[C,T]=(0,n.useState)(""),[E,I]=(0,n.useState)([]),[R,D]=(0,n.useState)(!1),L=(0,n.useRef)(null);(0,n.useEffect)(()=>{C.length<2?I([]):(D(!0),clearTimeout(L.current),L.current=setTimeout(async()=>{try{var e;const t=await(0,r.n)("/students?search=".concat(encodeURIComponent(C),"&limit=30")),s=await t.json();s.success&&I((null===(e=s.data)||void 0===e?void 0:e.students)||s.data||[])}finally{D(!1)}},300))},[C]);const z=[...m.sessions||[]].flatMap(e=>e.students.map(e=>e.studentId)),W=(m.unassigned||[]).map(e=>e.studentId),B=new Set([...z,...W]),M=i?o?"#f87171":"#2563eb":s?"#d97706":"#e5e7eb",P=i?o?"#fef2f2":"#eff6ff":"#fff";return(0,l.jsxs)("div",{style:{width:220,flexShrink:0,display:"flex",flexDirection:"column",gap:0},onDragOver:e=>{e.preventDefault(),g()},onDragLeave:f,onDrop:e=>{e.preventDefault(),b()},children:[(0,l.jsxs)("div",{style:{background:s?"#fffbeb":"#f3f4f6",border:"1px solid ".concat(M),borderBottom:"none",borderRadius:"10px 10px 0 0",padding:"10px 12px",transition:"border-color 0.15s"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[(0,l.jsx)("span",{style:{fontWeight:700,fontSize:13,flex:1},children:s?"\u23f3 Unassigned":t.label}),(0,l.jsxs)("span",{style:{fontSize:11,fontWeight:600,color:o?"#dc2626":"#6b7280",background:o?"#fee2e2":"#e5e7eb",padding:"1px 6px",borderRadius:8},children:[t.students.length,!s&&"/".concat(c)]})]}),!s&&(j?(0,l.jsxs)("div",{style:{display:"flex",gap:4,marginTop:4},children:[(0,l.jsx)("input",{type:"time",value:S,onChange:e=>w(e.target.value),style:{flex:1,padding:"2px 6px",borderRadius:5,border:"1px solid #d1d5db",fontSize:12},autoFocus:!0}),(0,l.jsx)("button",{onClick:async()=>{v(e=>(0,a.A)((0,a.A)({},e),{},{["time_".concat(t.id)]:!0}));try{const e=await(0,r.n)("/exam-schedules/".concat(m.id,"/sessions/").concat(t.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({startTime:S})}),s=await e.json();s.success&&(N(!1),y(s.data))}finally{v(e=>(0,a.A)((0,a.A)({},e),{},{["time_".concat(t.id)]:!1}))}},style:{padding:"2px 7px",borderRadius:5,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontSize:11,fontWeight:600},children:"\u2713"}),(0,l.jsx)("button",{onClick:()=>N(!1),style:{padding:"2px 6px",borderRadius:5,border:"1px solid #d1d5db",background:"#fff",cursor:"pointer",fontSize:11},children:"\u2715"})]}):(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginTop:2},children:[(0,l.jsxs)("span",{style:{fontSize:12,color:"#1d4ed8",fontWeight:600,cursor:d?"pointer":"default"},onClick:()=>d&&N(!0),title:d?"Click to edit time":"",children:["\ud83d\udd50 ",t.time]}),d&&(0,l.jsx)("button",{onClick:async()=>{if(window.confirm("Remove this session? Its students will move to Unassigned.")){v(e=>(0,a.A)((0,a.A)({},e),{},{["sess_".concat(t.id)]:!0}));try{const e=await(0,r.n)("/exam-schedules/".concat(m.id,"/sessions/").concat(t.id),{method:"DELETE"}),s=await e.json();s.success&&y(s.data)}finally{v(e=>(0,a.A)((0,a.A)({},e),{},{["sess_".concat(t.id)]:!1}))}}},disabled:!!u["sess_".concat(t.id)],style:{marginLeft:"auto",padding:"1px 5px",borderRadius:4,border:"1px solid #fca5a5",background:"#fff",color:"#dc2626",cursor:"pointer",fontSize:10},title:"Remove session",children:"\u2715 Session"})]}))]}),(0,l.jsxs)("div",{style:{border:"1px solid ".concat(M),borderTop:"none",borderRadius:"0 0 10px 10px",minHeight:120,background:P,transition:"background 0.15s, border-color 0.15s",display:"flex",flexDirection:"column"},children:[0===t.students.length&&(0,l.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"#d1d5db",fontSize:12,padding:"16px 8px",textAlign:"center"},children:x?"Drop here":s?"No unassigned students":"Empty session"}),t.students.map(e=>{const n=(null===x||void 0===x?void 0:x.studentId)===e.studentId,o=!!u["rm_".concat(e.studentId)]||!!u["drag_".concat(e.studentId)];return(0,l.jsxs)("div",{draggable:d&&!o,onDragStart:n=>p(n,e,s?"unassigned":t.id),onDragEnd:h,style:{margin:"6px 8px 0",padding:"7px 10px",background:n?"#dbeafe":"#fff",border:"1px solid ".concat(n?"#93c5fd":"#e5e7eb"),borderRadius:8,display:"flex",alignItems:"center",gap:6,cursor:d?"grab":"default",opacity:n?.5:1,transition:"opacity 0.15s",boxShadow:n?"0 2px 8px rgba(37,99,235,0.15)":void 0,userSelect:"none"},children:[(0,l.jsx)("div",{style:{width:26,height:26,borderRadius:"50%",background:s?"#fef3c7":"#dbeafe",color:s?"#92400e":"#1e40af",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:e.name.split(" ").map(e=>e[0]).join("").slice(0,2).toUpperCase()}),(0,l.jsx)("span",{style:{fontSize:12,fontWeight:500,flex:1,lineHeight:1.3},children:e.name}),d&&(0,l.jsx)("button",{onClick:()=>(async e=>{v(t=>(0,a.A)((0,a.A)({},t),{},{["rm_".concat(e.studentId)]:!0}));try{let n;n=s?await(0,r.n)("/exam-schedules/".concat(m.id,"/students/").concat(e.studentId),{method:"DELETE"}):await(0,r.n)("/exam-schedules/".concat(m.id,"/sessions/").concat(t.id,"/students/").concat(e.studentId),{method:"DELETE"});const a=await n.json();a.success&&y(a.data)}finally{v(t=>(0,a.A)((0,a.A)({},t),{},{["rm_".concat(e.studentId)]:!1}))}})(e),disabled:o,title:s?"Remove from schedule":"Move to Unassigned",style:{padding:"1px 5px",borderRadius:4,border:"1px solid #fca5a5",background:"#fff",color:"#dc2626",cursor:"pointer",fontSize:10,flexShrink:0},children:"\u2715"})]},e.studentId)}),(0,l.jsx)("div",{style:{flex:1,minHeight:8}}),d&&(0,l.jsx)("div",{style:{padding:"6px 8px 8px"},children:(0,l.jsx)("button",{onClick:()=>{A(!0),T(""),I([])},disabled:!s&&o,title:!s&&o?"Session is full":"Add student",style:{width:"100%",padding:"5px 0",borderRadius:7,border:"1px dashed ".concat(!s&&o?"#d1d5db":"#93c5fd"),background:"transparent",color:!s&&o?"#d1d5db":"#2563eb",cursor:!s&&o?"not-allowed":"pointer",fontSize:12,fontWeight:600},children:"+ Add Student"})})]}
1),k&&(0,l.jsx)("div",{style:Ce,onClick:e=>e.target===e.currentTarget&&A(!1),children:(0,l.jsxs)("div",{style:Te,children:[(0,l.jsxs)("h3",{style:{margin:"0 0 14px",fontSize:16},children:["Add Student \u2014 ",s?"Unassigned":t.label]}),(0,l.jsx)("input",{style:Ie,placeholder:"Search by name\u2026",value:C,autoFocus:!0,onChange:e=>T(e.target.value)}),R&&(0,l.jsx)("div",{style:{fontSize:12,color:"#9ca3af",marginBottom:6},children:"Searching\u2026"}),E.length>0&&(0,l.jsx)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid #e5e7eb",borderRadius:8,marginBottom:8},children:E.map(e=>{var n,a;const o=B.has(e.id);return(0,l.jsxs)("div",{onClick:()=>!o&&(async e=>{const n=s?"/exam-schedules/".concat(m.id,"/students"):"/exam-schedules/".concat(m.id,"/sessions/").concat(t.id,"/students"),a=await(0,r.n)(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({studentId:e.id})}),l=await a.json();l.success?(y(l.data),T(""),I([]),A(!1)):alert(l.message||"Error adding student")})(e),style:{padding:"9px 14px",cursor:o?"default":"pointer",fontSize:13,borderBottom:"1px solid #f3f4f6",color:o?"#9ca3af":"#111827",background:o?"#f9fafb":void 0},onMouseEnter:e=>{o||(e.currentTarget.style.background="#f0f9ff")},onMouseLeave:e=>{o||(e.currentTarget.style.background="")},children:[null===(n=e.user)||void 0===n?void 0:n.firstName," ",null===(a=e.user)||void 0===a?void 0:a.lastName,e.studentId&&(0,l.jsxs)("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:6},children:["#",e.studentId]}),o&&(0,l.jsx)("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:6},children:"(in schedule)"})]},e.id)})}),C.length>=2&&!R&&0===E.length&&(0,l.jsx)("div",{style:{fontSize:13,color:"#9ca3af",marginBottom:8},children:"No students found."}),(0,l.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:10},children:(0,l.jsx)("button",{onClick:()=>{A(!1),T(""),I([])},style:Re,children:"Close"})})]})})]})}function Ae(){const[e,t]=(0,n.useState)("exam"),[s,o]=(0,n.useState)([]),[i,d]=(0,n.useState)([]),[c,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(null),[p,h]=(0,n.useState)(!1),[g,f]=(0,n.useState)({title:"",date:ve(),durationMins:180,maxStudentsPerSession:20,notes:"",groupIds:[]}),[b,y]=(0,n.useState)(!1),[v,j]=(0,n.useState)(""),[N,S]=(0,n.useState)(!1),[w,k]=(0,n.useState)({}),[A,C]=(0,n.useState)(!1),[T,E]=(0,n.useState)(!1),[I,R]=(0,n.useState)("09:00"),[D,L]=(0,n.useState)(!1),[z,W]=(0,n.useState)({}),[B,M]=(0,n.useState)(null),[P,O]=(0,n.useState)(null),[G,F]=(0,n.useState)("");(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&o(e.data||[])})},[]);const _=(0,n.useCallback)(async()=>{x(!0),F("");try{const e=await(0,r.n)("/exam-schedules"),t=await e.json();t.success?d(t.data||[]):F(t.message||"Failed to load exam schedules")}catch(e){F("Network error \u2014 could not load exam schedules")}finally{x(!1)}},[]);(0,n.useEffect)(()=>{_()},[_]);const U=async()=>{if(!u)return;const e=await(0,r.n)("/exam-schedules/".concat(u.id)),t=await e.json();t.success&&m(t.data),_()},H=async()=>
1{if(window.confirm("Send this schedule to admin for review? You will not be able to edit it after submitting.")){W(e=>(0,a.A)((0,a.A)({},e),{},{submit:!0}));try{const e=await(0,r.n)("/exam-schedules/".concat(u.id,"/submit"),{method:"POST"}),t=await e.json();t.success?U():alert(t.message||"Error submitting")}finally{W(e=>(0,a.A)((0,a.A)({},e),{},{submit:!1}))}}},V=async()=>{if(window.confirm("Recall this schedule? It will go back to Draft so you can edit and resend.")){W(e=>(0,a.A)((0,a.A)({},e),{},{recall:!0}));try{const e=await(0,r.n)("/exam-schedules/".concat(u.id,"/recall"),{method:"POST"}),t=await e.json();t.success?U():alert(t.message||"Error recalling schedule")}finally{W(e=>(0,a.A)((0,a.A)({},e),{},{recall:!1}))}}},Y=async e=>{e.preventDefault(),C(!0);try{const e=await(0,r.n)("/exam-schedules/".concat(u.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,a.A)((0,a.A)({},w),{},{durationMins:w.durationMins?Number(w.durationMins):void 0,maxStudentsPerSession:w.maxStudentsPerSession?Number(w.maxStudentsPerSession):void 0}))});(await e.json()).success&&(S(!1),U())}finally{C(!1)}},q=async e=>{e.preventDefault(),L(!0);try{const e=await(0,r.n)("/exam-schedules/".concat(u.id,"/sessions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({startTime:I})}),t=await e.json();t.success?(E(!1),R("09:00"),m(t.data)):alert(t.message||"Error adding session")}finally{L(!1)}};if(u){var J,K,Q,X,Z,$,ee,te,se,ne,re,ae;const e=u,t="DRAFT"===e.status,s=(e.sessions||[]).reduce((e,t)=>e+t.students.length,0),n=(e.unassigned||[]).length,o=s+n,i=Se[e.status]||Se.DRAFT;return(0,l.jsxs)("div",{style:{padding:24,maxWidth:"100%"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:12,marginBottom:16},children:[(0,l.jsx)("button",{onClick:()=>m(null),style:{background:"none",border:"none",cursor:"pointer",fontSize:20,color:"#6b7280",paddingTop:2},children:"\u2190"}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("h2",{style:{margin:0,fontSize:20,fontWeight:700},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:13,color:"#6b7280",marginTop:3},children:[je(e.date)," \xb7 Duration: ",Ne(e.durationMins)," \xb7 Max ",e.maxStudentsPerSession,"/session"]}),e.notes&&(0,l.jsxs)("div",{style:{fontSize:13,color:"#6b7280",marginTop:2},children:["\ud83d\udcdd ",e.notes]})]}),(0,l.jsx)("span",{style:{padding:"3px 12px",borderRadius:12,fontSize:12,fontWeight:700,background:i.bg,color:i.text},children:e.status}),t&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{onClick:()=>{var t;k({title:e.title,date:null===(t=e.date)||void 0===t?void 0:t.split("T")[0],durationMins:e.durationMins,maxStudentsPerSession:e.maxStudentsPerSession,notes:e.notes||""}),S(!0)},style:Le,children:"Edit"}),(0,l.jsx)("button",{onClick:()=>(async e=>{window.confirm("Delete this exam schedule? This cannot be undone.")&&(await(0,r.n)("/exam-schedules/".concat(e),{method:"DELETE"}),(null===u||void 0===u?void 0:u.id)===e&&m(null),_())})(e.id),style:(0,a.A)((0,a.A)({},Le),{},{color:"#dc2626",borderColor:"#fca5a5"}),children:"Delete"})]})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:20,marginBottom:16,padding:"10px 16px",background:"#f9fafb",borderRadius:10,flexWrap:"wrap"},children:[(0,l.jsxs)("span",{style:{fontSize:13,color:"#374151"},children:[(0,l.jsx)("strong",{children:null!==(J=null===(K=e.sessions)||void 0===K?void 0:K.length)&&void 0!==J?J:0})," session",1!==(null!==(Q=null===(X=e.sessions)||void 0===X?void 0:X.length)&&void 0!==Q?Q:0)?"s":""]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#374151"},children:[(0,l.jsx)("strong",{children:s})," assigned"]}),n>0&&(0,l.jsxs)("span",{style:{fontSize:13,color:"#92400e",fontWeight:600},children:["\u23f3 ",n," unassigned"]}),(0,l.jsxs)("span",{style:{fontSize:13,color:"#6b7280"},children:[o," total in schedule"]})]}),(0,l.jsx)(we,{schedule:e,isDraft:t,maxStudents:e.maxStudentsPerSession,onUpdate:e=>m(e)}),t&&(0,l.jsx)("div",{style:{marginTop:14},children:(0,l.jsx)("button",{onClick:()=>E(!0),style:{padding:"7px 16px",borderRadius:8,background:"#0f766e",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:13},children:"+ Add Session"})}),(0,l.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",marginTop:20,flexWrap:"wrap"},children:[(0,l.jsx)("button",{onClick:()=>(async(e,t)=>{M(e);try{const s=await(0,r.n)("/exam-schedules/".concat(e,"/export")),n=await s.blob(),a=URL.createObjectURL(n),l=document.createElement("a");l.href=a,l.download="".concat(t,".xlsx"),l.click(),URL.revokeObjectURL(a)}catch(s){alert("Export failed")}finally{M(null)}})(e.id,e.title),disabled:B===e.id,style:{padding:"7px 16px",borderRadius:8,background:"#16a34a",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:13,opacity:B===e.id?.6:1},children:B===e.id?"Exporting\u2026":"\ud83d\udce5 Export Excel"}),(0,l.jsx)("button",{onClick:()=>(async e=>{O(e);try{const t=await(0,r.n)("/exam-schedules/".concat(e,"/send-telegram"),{method:"POST"}),s=await t.json();alert(s.message||(s.success?"Sent!":"Failed"))}catch(t){alert("Failed to send")}finally{O(null)}})(e.id),disabled:P===e.id,style:{padding:"7px 16px",borderRadius:8,background:"#3b82f6",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:13,opacity:P===e.id?.6:1},children:P===e.id?"Sending\u2026":"\u2708\ufe0f Send to Telegram"}),(0,l.jsx)("div",{style:{flex:1}}),t&&(0,l.jsx)("button",{onClick:H,disabled:!!z.submit||0===(null!==(Z=null===($=e.sessions)||void 0===$?void 0:$.length)&&void 0!==Z?Z:0),style:{padding:"9px 22px",borderRadius:8,background:0===(null!==(ee=null===(te=e.sessions)||void 0===te?void 0:te.length)&&void 0!==ee?ee:0)?"#d1d5db":"#16a34a",color:"#fff",border:"none",cursor:0===(null!==(se=null===(ne=e.sessions)||void 0===ne?void 0:ne.length)&&void 0!==se?se:0)?"not-allowed":"pointer",fontWeight:700,fontSize:14},title:0===(null!==(re=null===(ae=e.sessions)||void 0===ae?void 0:ae.length)&&void 0!==re?re:0)?"Add at least one session first":"Send to admin for review",children:z.submit?"Sending\u2026":"\ud83d\udce4 Send to Admin"})]}),"SUBMITTED"===e.status&&(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 18px",background:"#fef9c3",borderRadius:10,marginTop:12},children:[(0,l.jsx)("span",{style:{fontSize:14,color:"#92400e",fontWeight:600,flex:1},children:"\u23f3 Submitted \u2014 waiting for admin to confirm."}),(0,l.jsx)("button",{onClick:V,disabled:!!z.recall,style:{padding:"6px 16px",borderRadius:8,background:"#fff",border:"1px solid #d97706",color:"#92400e",cursor:"pointer",fontWeight:600,fontSize:13},children:z.recall?"Recalling\u2026":"\u21a9 Resend"})]}),"CONFIRMED"===e.status&&(0,l.jsx)("div",{style:{padding:"12px 18px",background:"#dcfce7",borderRadius:10,marginTop:12,fontSize:14,color:"#15803d",fontWeight:600},children:"\u2705 Confirmed by admin."}),T&&(0,l.jsx)("div",{style:Ce,children:(0,l.jsxs)("form",{onSubmit:q,style:Te,children:[(0,l.jsx)("h3",{style:{margin:"0 0 18px",fontSize:17},children:"Add Session"}),(0,l.jsx)("label",{style:Ee,children:"Start Time"}),(0,l.jsx)("input",{type:"time",style:Ie,value:I,onChange:e=>R(e.target.value),required:!0,autoFocus:!0}),(0,l.jsxs)("p",{style:{fontSize:12,color:"#6b7280",marginTop:4,marginBottom:16},children:["All students in this session will take the exam at this time for ",Ne(e.durationMins),"."]}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>E(!1),style:Re,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",disabled:D,style:De,children:D?"Adding\u2026":"Add Session"})]})]})}),N&&(0,l.jsx)("div",{style:Ce,children:(0,l.jsxs)("form",{onSubmit:Y,style:Te,children:[(0,l.jsx)("h3",{style:{margin:"0 0 18px",fontSize:17},children:"Edit Schedule"}),(0,l.jsx)("label",{style:Ee,children:"Title"}),(0,l.jsx)("input",{style:Ie,value:w.title||"",onChange:e=>k(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),required:!0}),(0,l.jsx)("label",{style:Ee,children:"Exam Date"}),(0,l.jsx)("input",{type:"date",style:Ie,value:w.date||"",onChange:e=>k(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),required:!0}),(0,l.jsx)("label",{style:Ee,children:"Duration (minutes)"}),(0,l.jsx)("input",{type:"number",min:30,max:480,style:Ie,value:w.durationMins||180,onChange:e=>k(t=>(0,a.A)((0,a.A)({},t),{},{durationMins:e.target.value}))}),(0,l.jsx)("label",{style:Ee,children:"Max students per session"}),(0,l.jsx)("input",{type:"number",min:1,max:200,style:Ie,value:w.maxStudentsPerSession||20,onChange:e=>k(t=>(0,a.A)((0,a.A)({},t),{},{maxStudentsPerSession:e.target.value}))}),(0,l.jsx)("label",{style:Ee,children:"Notes (optional)"}),(0,l.jsx)("textarea",{style:(0,a.A)((0,a.A)({},Ie),{},{minHeight:60,resize:"vertical"}),value:w.notes||"",onChange:e=>k(t=>(0,a.A)((0,a.A)({},t),{},{notes:e.target.value}))}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginTop:16,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>S(!1),style:Re,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",disabled:A,style:De,children:A?"Saving\u2026":"Save"})]})]})})]})}return(0,l.jsxs)("div",{style:{padding:24,maxWidth:960,margin:"0 auto"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[(0,l.jsx)("h2",{style:{margin:0,fontSize:20,fontWeight:700,flex:1},children:"Exam Scheduling"}),"exam"===e&&(0,l.jsx)("button",{onClick:()=>h(!0),style:{padding:"8px 18px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:14},children:"+ New Schedule"})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:4,marginBottom:24,background:"#f3f4f6",padding:4,borderRadius:10,width:"fit-content"},children:[(0,l.jsx)("button",{onClick:()=>t("exam"),style:{padding:"6px 16px",borderRadius:7,border:"none",cursor:"pointer",fontSize:13,fontWeight:600,background:"exam"===e?"#fff":"transparent",color:"exam"===e?"#002147":"#708090",boxShadow:"exam"===e?"0 1px 4px rgba(0,0,0,0.1)":"none"},children:"\ud83d\udccb Exam Schedules"}),(0,l.jsx)("button",{onClick:()=>t("speaking"),style:{padding:"6px 16px",borderRadius:7,border:"none",cursor:"pointer",fontSize:13,fontWeight:600,background:"speaking"===e?"#fff":"transparent",color:"speaking"===e?"#002147":"#708090",boxShadow:"speaking"===e?"0 1px 4px rgba(0,0,0,0.1)":"none"},children:"\ud83d\udde3\ufe0f Speaking Schedule"})]}),"speaking"===e&&(0,l.jsx)(he,{}),"speaking"!==e&&(0,l.jsxs)(l.Fragment,{children:[c?(0,l.jsx)("div",{style:{textAlign:"center",color:"#9ca3af",padding:48},children:"Loading\u2026"}):G?(0,l.jsxs)("div",{style:{textAlign:"center",color:"#dc2626",padding:"64px 0",border:"2px dashed #fca5a5",borderRadius:16,background:"#fff1f2"},children:[(0,l.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\u26a0\ufe0f"}),(0,l.jsx)("div",{style:{fontSize:16,fontWeight:600,marginBottom:4},children:"Could not load schedules"}),(0,l.jsx)("div",{style:{fontSize:13,marginBottom:12},children:G}),(0,l.jsx)("button",{onClick:_,style:{padding:"6px 16px",borderRadius:8,background:"#002147",color:"#fff",border:"none",cursor:"pointer",fontSize:13},children:"Retry"})]}):0===i.length?(0,l.jsxs)("div",{style:{textAlign:"center",color:"#9ca3af",padding:"64px 0",border:"2px dashed #e5e7eb",borderRadius:16},children:[(0,l.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\ud83d\udccb"}),(0,l.jsx)("div",{style:{fontSize:16,fontWeight:600,marginBottom:4}
1,children:"No exam schedules yet"}),(0,l.jsx)("div",{style:{fontSize:13},children:"Create a schedule to organize students into exam sessions."})]}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:i.map(e=>{var t,s,n,a;const o=Se[e.status]||Se.DRAFT;return(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:12,padding:"14px 20px",background:"#fff",display:"flex",alignItems:"center",gap:16,cursor:"pointer"},onClick:()=>(async e=>{const t=await(0,r.n)("/exam-schedules/".concat(e)),s=await t.json();s.success&&m(s.data)})(e.id),onMouseEnter:e=>e.currentTarget.style.borderColor="#93c5fd",onMouseLeave:e=>e.currentTarget.style.borderColor="#e5e7eb",children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontWeight:700,fontSize:15},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:12,color:"#6b7280",marginTop:3},children:[je(e.date)," \xb7 ",Ne(e.durationMins)," \xb7 Max ",e.maxStudentsPerSession,"/session"]})]}),(0,l.jsxs)("div",{style:{fontSize:13,color:"#6b7280"},children:[null!==(t=null===(s=e._count)||void 0===s?void 0:s.sessions)&&void 0!==t?t:0," session",1!==(null!==(n=null===(a=e._count)||void 0===a?void 0:a.sessions)&&void 0!==n?n:0)?"s":""]}),(0,l.jsx)("span",{style:{padding:"2px 10px",borderRadius:12,fontSize:12,fontWeight:600,background:o.bg,color:o.text},children:e.status}),"SUBMITTED"===e.status&&(0,l.jsx)("button",{onClick:async t=>{if(t.stopPropagation(),!window.confirm("Recall this schedule back to Draft?"))return;const s=await(0,r.n)("/exam-schedules/".concat(e.id,"/recall"),{method:"POST"}),n=await s.json();n.success?_():alert(n.message||"Error")},style:{padding:"4px 12px",borderRadius:8,background:"#fff",border:"1px solid #d97706",color:"#92400e",cursor:"pointer",fontWeight:600,fontSize:12},children:"\u21a9 Resend"})]},e.id)})}),p&&(0,l.jsx)("div",{style:Ce,children:(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),j(""),g.title&&g.date){y(!0);try{const e=await(0,r.n)("/exam-schedules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,a.A)((0,a.A)({},g),{},{durationMins:Number(g.durationMins),maxStudentsPerSession:Number(g.maxStudentsPerSession),groupIds:g.groupIds.length>0?g.groupIds:void 0}))}),t=await e.json();t.success?(h(!1),f({title:"",date:ve(),durationMins:180,maxStudentsPerSession:20,notes:"",groupIds:[]}),_(),m(t.data)):j(t.message||"Error creating schedule")}finally{y(!1)}}else j("Title and date are required.")},style:Te,children:[(0,l.jsx)("h3",{style:{margin:"0 0 18px",fontSize:17},children:"New Exam Schedule"}),v&&(0,l.jsx)("div",{style:{background:"#fee2e2",color:"#dc2626",padding:"8px 14px",borderRadius:8,marginBottom:12,fontSize:13},children:v}),(0,l.jsx)("label",{style:Ee,children:"Title"}),(0,l.jsx)("input",{style:Ie,placeholder:"e.g. Intermediate B \u2014 May 2025 Exam",value:g.title,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),required:!0}),(0,l.jsx)("label",{style:Ee,children:"Exam Date"}),(0,l.jsx)("input",{type:"date",style:Ie,value:g.date,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{date:e.target.value})),required:!0}),(0,l.jsxs)("div",{style:{display:"flex",gap:12},children:[(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("label",{style:Ee,children:"Duration (minutes)"}),(0,l.jsx)("input",{type:"number",min:30,max:480,style:Ie,value:g.durationMins,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{durationMins:e.target.value}))})]}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("label",{style:Ee,children:"Max students / session"}),(0,l.jsx)("input",{type:"number",min:1,max:200,style:Ie,value:g.maxStudentsPerSession,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{maxStudentsPerSession:e.target.value}))})]})]}),(0,l.jsx)("label",{style:Ee,children:"Auto-distribute from groups (optional)"}),(0,l.jsxs)("div",{style:{maxHeight:160,overflowY:"auto",border:"1px solid #e5e7eb",borderRadius:8,padding:"6px 10px",marginBottom:8},children:[0===s.length&&(0,l.jsx)("div",{style:{fontSize:13,color:"#9ca3af"},children:"No groups found."}),[...s].sort((e,t)=>e.startTime||t.startTime?e.startTime?t.startTime?e.startTime.localeCompare(t.startTime):-1:1:0).map(e=>(0,l.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 0",cursor:"pointer",fontSize:13,borderBottom:"1px solid #f3f4f6"},children:[(0,l.jsx)("input",{type:"checkbox",checked:g.groupIds.includes(e.id),onChange:t=>f(s=>(0,a.A)((0,a.A)({},s),{},{groupIds:t.target.checked?[...s.groupIds,e.id]:s.groupIds.filter(t=>t!==e.id)}
1))}),(0,l.jsx)("span",{style:{flex:1},children:e.name}),e.startTime&&(0,l.jsxs)("span",{style:{fontSize:11,color:"#6b7280",background:"#f3f4f6",padding:"1px 6px",borderRadius:6,fontWeight:600},children:["\ud83d\udd50 ",e.startTime]})]},e.id))]}),(0,l.jsx)("p",{style:{fontSize:11,color:"#6b7280",marginBottom:8,marginTop:0},children:"Groups are ordered by class time. Each group fills its own session(s) before moving to the next."}),(0,l.jsx)("label",{style:Ee,children:"Notes (optional)"}),(0,l.jsx)("textarea",{style:(0,a.A)((0,a.A)({},Ie),{},{minHeight:56,resize:"vertical"}),value:g.notes,onChange:e=>f(t=>(0,a.A)((0,a.A)({},t),{},{notes:e.target.value})),placeholder:"Room, instructions, etc."}),(0,l.jsxs)("div",{style:{display:"flex",gap:8,marginTop:16,justifyContent:"flex-end"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>{h(!1),j("")},style:Re,children:"Cancel"}),(0,l.jsx)("button",{type:"submit",disabled:b,style:De,children:b?"Creating\u2026":"Create"})]})]})})]})]})}const Ce={position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},Te={background:"#fff",borderRadius:16,padding:28,minWidth:360,maxWidth:500,width:"90%",maxHeight:"90vh",overflowY:"auto"},Ee={display:"block",fontSize:11,fontWeight:700,color:"#374151",marginBottom:4,marginTop:12,textTransform:"uppercase",letterSpacing:"0.04em"},Ie={width:"100%",padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:14,boxSizing:"border-box",marginBottom:4},Re={padding:"8px 18px",borderRadius:8,border:"1px solid #d1d5db",background:"#fff",cursor:"pointer",fontSize:14},De={padding:"8px 20px",borderRadius:8,background:"#2563eb",color:"#fff",border:"none",cursor:"pointer",fontWeight:600,fontSize:14},Le={padding:"6px 14px",borderRadius:8,border:"1px solid #d1d5db",background:"#fff",cursor:"pointer",fontSize:13};var ze=s(1238),We=s(1087);function Be(e,t,s){if("WRITING"===s||"SPEAKING"===s)return e;const n=e/t*40,r="READING"===s?[[39,9],[37,8.5],[35,8],[33,7.5],[30,7],[27,6.5],[23,6],[19,5.5],[15,5],[13,4.5],[10,4],[8,3.5],[6,3],[4,2.5],[2,2],[1,1.5]]:[[39,9],[37,8.5],[35,8],[33,7.5],[30,7],[27,6.5],[23,6],[20,5.5],[16,5],[13,4.5],[10,4],[8,3.5],[6,3],[4,2.5],[2,2],[1,1.5]];for(const[a,l]of r)if(n>=a)return l;return 0}function Me(e){return e>=7?"#16a34a":e>=5.5?"#d97706":e>=4?"#ea580c":"#dc2626"}const Pe={LISTENING:"\ud83c\udfa7 Listening",READING:"\ud83d\udcd6 Reading",WRITING:"\u270d\ufe0f Writing",SPEAKING:"\ud83d\udde3\ufe0f Speaking"},Oe=["LISTENING","READING","WRITING","SPEAKING"];function Ge(){JSON.parse(localStorage.getItem("user")||"{}");const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)(""),[i,d]=(0,n.useState)(()=>{const e=new Date;return"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0"))}),[c,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!1),[p,h]=(0,n.useState)(!1),[g,f]=(0,n.useState)(null),[b,y]=(0,n.useState)([]),[v,j]=(0,n.useState)(()=>(new Date).toISOString().split("T")[0]),[N,S]=(0,n.useState)("LISTENING"),[w,k]=(0,n.useState)(40),[A,C]=(0,n.useState)(""),[T,E]=(0,n.useState)({}),[I,R]=(0,n.useState)(!1),[D,L]=(0,n.useState)("list");(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&t(e.data||[])})},[]);const z=(0,n.useCallback)(async()=>{if(s){m(!0);try{const e=await(0,r.n)("/grades/sessions?groupId=".concat(s,"&month=").concat(i)),t=await e.json();t.success&&x(t.data)}finally{m(!1)}}},[s,i]);(0,n.useEffect)(()=>{z()},[z]);const W=async(e,t)=>{const s=await(0,r.n)("/groups/".concat(e,"/roster")),n=await s.json(),a=n.success?(n.data||[]).filter(Boolean):[];y(a);const l={};a.forEach(e=>{var s;l[e.id]=null!==(s=null===t||void 0===t?void 0:t[e.id])&&void 0!==s?s:""}),E(l)};return(0,l.jsxs)("div",{className:"p-4 md:p-6",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-5",children:[(0,l.jsx)("h2",{className:"text-xl font-bold text-[#002147]",children:"\ud83c\udfaf Grade Sheets"}),(0,l.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[(0,l.jsxs)("div",{className:"flex rounded-lg overflow-hidden border border-gray-200 text-sm font-medium",children:[(0,l.jsx)("button",{onClick:()=>L("list"),className:"px-3 py-1.5 ".concat("list"===D?"bg-[#002147] text-white":"bg-white text-gray-600 hover:bg-gray-50"),children:"\ud83d\udccb List"}),(0,l.jsx)("button",{onClick:()=>L("matrix"),className:"px-3 py-1.5 ".concat("matrix"===D?"bg-[#002147] text-white":"bg-white text-gray-600 hover:bg-gray-50"),children:"\ud83d\udcca Matrix"})]}),"list"===D&&c.length>0&&(0,l.jsx)("button",{onClick:()=>
1{if(!c.length)return;const e=ze.Wp.book_new(),t=[["Date","Type","Max","Student","Score","Band"]];c.forEach(e=>e.grades.forEach(s=>{var n,r,a,l,o;return t.push([e.date.split("T")[0],e.type,e.maxScore,"".concat(null===(n=s.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.firstName," ").concat(null===(a=s.student)||void 0===a||null===(l=a.user)||void 0===l?void 0:l.lastName).trim(),s.score,null!==(o=s.band)&&void 0!==o?o:Be(s.score,e.maxScore,e.type)])}));const s=ze.Wp.aoa_to_sheet(t);s["!cols"]=[{wch:12},{wch:12},{wch:6},{wch:26},{wch:8},{wch:8}],ze.Wp.book_append_sheet(e,s,i.slice(0,31)),ze._h(e,"grades_".concat(i,".xlsx"))},className:"bg-green-600 hover:bg-green-700 text-white px-3 py-2 rounded-lg text-sm font-medium",children:"\ud83d\udce5 Export Month"}),s&&(0,l.jsx)("button",{onClick:async()=>{f(null),j((new Date).toISOString().split("T")[0]),S("LISTENING"),k(40),C(""),await W(s),h(!0)},className:"bg-[#002147] hover:bg-[#001a39] text-white px-4 py-2 rounded-lg text-sm font-medium",children:"\u2795 New Sheet"})]})]}),(0,l.jsxs)("div",{className:"bg-white p-4 rounded-lg shadow mb-4 flex flex-wrap gap-3",children:[(0,l.jsxs)("select",{value:s,onChange:e=>o(e.target.value),className:"border rounded px-3 py-2 text-sm flex-1 min-w-[160px]",children:[(0,l.jsx)("option",{value:"",children:"\u2014 Select Group \u2014"}),e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,l.jsx)("input",{type:"month",value:i,onChange:e=>d(e.target.value),className:"border rounded px-3 py-2 text-sm"})]}),"matrix"===D&&s&&(0,l.jsx)("div",{className:"bg-white rounded-lg shadow p-4",children:(0,l.jsx)(We.A,{groupId:s,month:i})}),"list"===D&&(u?(0,l.jsx)("p",{className:"text-center text-gray-400 py-8",children:"Loading..."}):0===c.length?(0,l.jsx)("p",{className:"text-center text-gray-400 py-8",children:s?"No grade sheets for this period.":"Select a group."}):(0,l.jsx)("div",{className:"space-y-4",children:c.map(e=>{const t=e.grades.length?(e.grades.reduce((t,s)=>{var n;return t+(null!==(n=s.band)&&void 0!==n?n:Be(s.score,e.maxScore,e.type))},0)/e.grades.length).toFixed(1):"\u2014";return(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-3 border-b bg-gray-50",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,l.jsx)("span",{className:"font-bold text-sm text-[#002147]",children:new Date(e.date).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"})}),(0,l.jsx)("span",{className:"px-2 py-0.5 bg-indigo-100 text-indigo-700 rounded text-xs font-semibold",children:Pe[e.type]||e.type}),"WRITING"!==e.type&&"SPEAKING"!==e.type&&(0,l.jsxs)("span",{className:"text-xs text-gray-500",children:["Max: ",e.maxScore]}),(0,l.jsxs)("span",{className:"text-xs text-gray-500",children:["Avg: ",(0,l.jsx)("b",{style:{color:Me(parseFloat(t))},children:t})]})]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:()=>(async e=>{f(e),j(e.date.split("T")[0]),S(e.type),k(e.maxScore),C(e.notes||"");const t={};e.grades.forEach(e=>{t[e.studentId]=e.score}),await W(e.groupId,t),h(!0)})(e),className:"text-xs text-blue-600 hover:text-blue-800 font-medium",children:"\u270f\ufe0f"}),(0,l.jsx)("button",{onClick:()=>(e=>{const t=ze.Wp.book_new(),s=[["Student","Score","Max","Band","Notes"]];e.grades.forEach(t=>{var n,r,a,l,o;return s.push(["".concat(null===(n=t.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.firstName," ").concat(null===(a=t.student)||void 0===a||null===(l=a.user)||void 0===l?void 0:l.lastName).trim(),t.score,e.maxScore,null!==(o=t.band)&&void 0!==o?o:Be(t.score,e.maxScore,e.type),t.notes||""])});const n=ze.Wp.aoa_to_sheet(s);n["!cols"]=[{wch:26},{wch:8},{wch:6},{wch:8},{wch:20}],ze.Wp.book_append_sheet(t,n,"".concat(e.date.split("T")[0]).slice(0,31)),ze._h(t,"grades_".concat(e.date.split("T")[0],".xlsx"))})(e),className:"text-xs text-green-600 hover:text-green-800 font-medium",children:"\ud83d\udce5"}),(0,l.jsx)("button",{onClick:()=>(async e=>{const t=await(0,r.n)("/grades/sessions/".concat(e.id,"/telegram"),{method:"POST"}),s=await t.json();alert(s.success?"\u2705 Sent to Telegram!":"\u274c "+(s.message||"Failed"))})(e),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:"\ud83d\udcf1 Telegram"}),(0,l.jsx)("button",{onClick:()=>(async e=>{window.confirm("Delete this grade sheet?")&&(await(0,r.n)("/grades/sessions/".concat(e),{method:"DELETE"}),z())})(e.id),className:"text-xs text-red-500 hover:text-red-700 font-medium",children:"\ud83d\uddd1\ufe0f"})]})]}),(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-gray-50 text-xs text-gray-500 uppercase",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"px-4 py-2 text-left",children:"Student"}),(0,l.jsxs)("th",{className:"px-4 py-2 text-center",children:["Score/",e.maxScore]}),(0,l.jsx)("th",{className:"px-4 py-2 text-center",children:"Band"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-100",children:e.grades.map(t=>{var s,n,r,a,o;const i=null!==(s=t.band)&&void 0!==s?s:Be(t.score,e.maxScore,e.type);return(0,l.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,l.jsxs)("td",{className:"px-4 py-2 font-medium",children:[null===(n=t.student)||void 0===n||null===(r=n.user)||void 0===r?void 0:r.firstName," ",null===(a=t.student)||void 0===a||null===(o=a.user)||void 0===o?void 0:o.lastName]}),(0,l.jsx)("td",{className:"px-4 py-2 text-center",children:t.score}),(0,l.jsx)("td",{className:"px-4 py-2 text-center",children:(0,l.jsx)("span",{className:"font-bold text-base",style:{color:Me(i)},children:i})})]},t.id)})})]})})]},e.id)})})),p&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 p-4 overflow-y-auto",children:(0,l.jsxs)("div",{className:"bg-white rounded-xl w-full max-w-2xl my-4 shadow-xl",children:[(0,l.jsxs)("div",{className:"p-5 border-b flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-bold text-[#002147]",children:g?"\u270f\ufe0f Edit Grade Sheet":"\u2795 New Grade Sheet"}),(0,l.jsx)("button",{onClick:()=>h(!1),className:"text-gray-400 hover:text-gray-600 text-xl",children:"\u2715"})]}),(0,l.jsxs)("div",{className:"p-5",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Date"}
1),(0,l.jsx)("input",{type:"date",value:v,onChange:e=>j(e.target.value),className:"w-full border rounded px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Type"}),(0,l.jsx)("select",{value:N,onChange:e=>{S(e.target.value),"WRITING"!==e.target.value&&"SPEAKING"!==e.target.value||k(9)},className:"w-full border rounded px-3 py-2 text-sm",children:Oe.map(e=>(0,l.jsx)("option",{value:e,children:Pe[e]},e))})]}),"WRITING"!==N&&"SPEAKING"!==N&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Max Score"}),(0,l.jsx)("input",{type:"number",min:"1",max:"100",value:w,onChange:e=>k(e.target.value),className:"w-full border rounded px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",children:"Notes"}),(0,l.jsx)("input",{type:"text",value:A,onChange:e=>C(e.target.value),placeholder:"e.g. Unit 5",className:"w-full border rounded px-3 py-2 text-sm"})]})]}),(0,l.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-gray-50",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"px-3 py-2 text-left text-xs font-semibold text-gray-500 uppercase",children:"Student"}),(0,l.jsx)("th",{className:"px-3 py-2 text-center text-xs font-semibold text-gray-500 uppercase",children:"WRITING"===N||"SPEAKING"===N?"Band (0\u20139)":"Score / ".concat(w)}),"WRITING"!==N&&"SPEAKING"!==N&&(0,l.jsx)("th",{className:"px-3 py-2 text-center text-xs font-semibold text-gray-500 uppercase",children:"Band"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-100",children:b.map(e=>{var t,s;const n=T[e.id],r=""===n||isNaN(Number(n))?null:Be(Number(n),Number(w),N);return(0,l.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,l.jsxs)("td",{className:"px-3 py-2 font-medium",children:[e.firstName||(null===(t=e.user)||void 0===t?void 0:t.firstName)," ",e.lastName||(null===(s=e.user)||void 0===s?void 0:s.lastName)]}),(0,l.jsx)("td",{className:"px-3 py-2",children:(0,l.jsx)("input",{type:"number",min:"0",max:"WRITING"===N||"SPEAKING"===N?9:w,step:"WRITING"===N||"SPEAKING"===N?.5:1,value:null!==n&&void 0!==n?n:"",onChange:t=>E(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t.target.value})),className:"w-20 border rounded px-2 py-1 text-sm text-center mx-auto block",placeholder:"\u2014"})}),"WRITING"!==N&&"SPEAKING"!==N&&(0,l.jsx)("td",{className:"px-3 py-2 text-center",children:null!==r?(0,l.jsx)("span",{className:"font-bold text-base",style:{color:Me(r)},children:r}):(0,l.jsx)("span",{className:"text-gray-300",children:"\u2014"})})]},e.id)})})]})}),(0,l.jsxs)("div",{className:"flex gap-3 mt-5",children:[(0,l.jsx)("button",{onClick:()=>h(!1),className:"flex-1 bg-gray-100 text-gray-600 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{const e=b.filter(e=>""!==T[e.id]&&!isNaN(Number(T[e.id]))).map(e=>({studentId:e.id,score:Number(T[e.id])}));if(e.length){R(!0);try{const t={groupId:s,date:v,type:N,maxScore:Number(w),notes:A,grades:e},n=g?await(0,r.n)("/grades/sessions/".concat(g.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}):await(0,r.n)("/grades/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await n.json();a.success?(h(!1),z()):alert(a.message||"Failed to save")}finally{R(!1)}}else alert("Enter at least one score")},disabled:I,className:"flex-1 bg-[#002147] text-white px-4 py-2 rounded-lg text-sm font-bold disabled:opacity-50",children:I?"Saving\u2026":g?"Update":"Save"})]})]})]})})]})}function Fe(){const[e,t]=(0,n.useState)([]),[s,a]=(0,n.useState)(""),[o,i]=(0,n.useState)([]),[d,c]=(0,n.useState)(""),[x,u]=(0,n.use
1State)([]),[m,p]=(0,n.useState)(""),[h,g]=(0,n.useState)("GENERAL"),[f,b]=(0,n.useState)(!1),[y,v]=(0,n.useState)(!1),[j,N]=(0,n.useState)(""),[S,w]=(0,n.useState)("all"),[k,A]=(0,n.useState)([]),[C,T]=(0,n.useState)(""),[E,I]=(0,n.useState)(!1),[R,D]=(0,n.useState)("");(0,n.useEffect)(()=>{(0,r.n)("/groups").then(e=>e.json()).then(e=>{e.success&&e.data.length>0&&(t(e.data),a(e.data[0].id))})},[]);(0,n.useEffect)(()=>{s&&(0,r.n)("/groups/".concat(s,"/roster")).then(e=>e.json()).then(e=>{e.success&&e.data.length>0?(i(e.data),c(e.data[0].id)):(i([]),c(""))})},[s]),(0,n.useEffect)(()=>{d&&(b(!0),(0,r.n)("/comments?studentId=".concat(d)).then(e=>e.json()).then(e=>{e.success&&u(e.data||[])}).finally(()=>b(!1)))},[d]);const L={GENERAL:"bg-gray-100 text-gray-700",ACADEMIC:"bg-blue-100 text-blue-700",BEHAVIORAL:"bg-yellow-100 text-yellow-700",ATTENDANCE:"bg-red-100 text-red-700",ACHIEVEMENT:"bg-green-100 text-green-700"};return(0,l.jsxs)("div",{className:"p-8",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold text-[#002147] mb-6",children:"\ud83d\udcac Student Comments"}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-4 mb-6",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] uppercase mb-1",children:"Group"}),(0,l.jsx)("select",{value:s,onChange:e=>a(e.target.value),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-[#708090] uppercase mb-1",children:"Student"}),(0,l.jsx)("select",{value:d,onChange:e=>c(e.target.value),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:o.map(e=>(0,l.jsxs)("option",{value:e.id,children:[e.firstName," ",e.lastName]},e.id))})]})]}),d&&(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),m.trim()&&d){v(!0),N("");try{const e=await(0,r.n)("/comments",{method:"POST",body:JSON.stringify({studentId:d,commentText:m,type:h})}),t=await e.json();t.success?(u(e=>[t.data,...e]),p(""),N("\u2705 Comment added!")):N(t.message||"Error")}catch(t){N("Error")}finally{v(!1)}}},className:"bg-white rounded-xl p-5 shadow border border-gray-100 mb-6",children:[(0,l.jsx)("div",{className:"flex gap-3 mb-3",children:(0,l.jsx)("select",{value:h,onChange:e=>g(e.target.value),className:"border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147]",children:Object.keys(L).map(e=>(0,l.jsx)("option",{value:e,children:e},e))})}),(0,l.jsx)("textarea",{value:m,onChange:e=>p(e.target.value),required:!0,placeholder:"Write a comment about this student...",rows:3,className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#002147] mb-3"}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("button",{type:"submit",disabled:y,className:"px-5 py-2 bg-[#002147] text-white rounded-lg text-sm font-medium disabled:opacity-60",children:y?"Saving...":"Add Comment"}),j&&(0,l.jsx)("span",{className:"text-sm text-green-600",children:j})]})]}),f?(0,l.jsx)("p",{className:"text-[#708090]",children:"Loading..."}):0===x.length?(0,l.jsx)("p",{className:"text-[#708090]",children:"No comments yet for this student."}):(0,l.jsx)("div",{className:"space-y-3",children:x.map(e=>(0,l.jsxs)("div",{className:"bg-white rounded-xl p-4 shadow border border-gray-100",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium ".concat(L[e.type]||"bg-gray-100 text-gray-600"),children:e.type}),(0,l.jsx)("span",{className:"text-xs text-[#708090]",children:new Date(e.createdAt).toLocaleDateString("en-GB")})]}),(0,l.jsx)("p",{className:"text-sm text-[#002147]",children:e.displayText||e.customText}),e.createdBy&&(0,l.jsxs)("p",{className:"text-xs text-[#708090] mt-1",children:["\u2014 ",e.createdBy.firstName," ",e.createdBy.lastName]})]},e.id))}),e.length>0&&(0,l.jsxs)("div",{className:"mt-8 bg-white rounded-xl p-5 shadow border-2 border-purple-400",children:[(0,l.jsx)("h3",{className:"font-bold text-[#002147] mb-4",children:"\ud83d\udce2 Send Message to Telegram Groups"}),(0,l.jsx)("div",{className:"flex gap-2 mb-3",children:["all","select"].map(e=>(0,l.jsx)("button",{onClick:()=>w(e),className:"px-3 py-1.5 rounded-lg text-sm font-semibold border-2 transition-colors ".concat(S===e?"bg-purple-600 border-purple-600 text-white":"bg-white border-gray-300 text-gray-700"),children:"all"===e?"All My Groups":"Select Groups"},e))}),"select"===S&&(0,l.jsx)("div",{className:"flex flex-wrap gap-2 mb-3 p-3 bg-gray-50 rounded-lg border border-gray-200",children:e.map(e=>(0,l.jsxs)("label",{className:"flex items-center gap-1.5 px-3 py-1 rounded-full text-sm cursor-pointer border select-none transition-colors ".concat(k.includes(e.id)?"bg-purple-100 border-purple-400 text-purple-800":"bg-white border-gray-300 text-gray-700"),children:[(0,l.jsx)("input",{type:"checkbox",checked:k.includes(e.id),onChange:()=>A(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]),className:"cursor-pointer"}),e.name]},e.id))}),(0,l.jsx)("textarea",{value:C,onChange:e=>T(e.target.value),placeholder:"Type your message... (supports *bold*, _italic_)",rows:3,className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-purple-400 mb-3 resize-y"}),(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-xs ".concat(R.includes("\u2705")?"text-green-600":R.includes("\u274c")?"text-red-500":"text-[#708090]"),children:R||("all"===S?"".concat(e.length," group").concat(1!==e.length?"s":""):"".concat(k.length," selected"))}),(0,l.jsx)("button",{onClick:async()=>
1{if(C.trim())if("select"!==S||0!==k.length){I(!0),D("");try{const t="all"===S?e.map(e=>e.id):k,s=await(0,r.n)("/telegram/teacher-broadcast",{method:"POST",body:JSON.stringify({message:C.trim(),targetGroupIds:t})}),n=await s.json();s.ok&&n.success?(D("\u2705 Sent to ".concat(n.sent," group").concat(1!==n.sent?"s":"").concat(n.failed?" (".concat(n.failed," failed)"):"")),T(""),A([])):D("\u274c "+(n.message||"Failed"))}catch(t){D("\u274c Network error")}finally{I(!1)}}else D("Select at least one group");else D("Please enter a message")},disabled:E||!C.trim(),className:"px-5 py-2 bg-purple-600 text-white rounded-lg text-sm font-semibold disabled:opacity-50 disabled:cursor-not-allowed hover:bg-purple-700 transition-colors",children:E?"Sending\u2026":"\ud83d\udce2 Send"})]})]})]})}function _e(e){var t,s,o,i,d,c,x,u,m;let{currentUserId:p}=e;const[h,g]=(0,n.useState)([]),[f,b]=(0,n.useState)(null),[y,v]=(0,n.useState)([]),[j,N]=(0,n.useState)(""),[S,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)(!0),C=n.useRef(null);(0,n.useEffect)(()=>{T()},[]);const T=async()=>{A(!0);try{const e=await(0,r.n)("/chat/threads"),t=await e.json();t.success&&g(t.data)}catch(e){}finally{A(!1)}};(0,n.useEffect)(()=>{if(!f)return;const e=setInterval(async()=>{const e=await(0,r.n)("/chat/threads/".concat(f.id,"/messages")),t=await e.json();t.success&&v(t.data)},1e4);return()=>clearInterval(e)},[f]),(0,n.useEffect)(()=>{var e;null===(e=C.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[y]);const E=async()=>{if(j.trim()&&f){w(!0);try{const e=await(0,r.n)("/chat/threads/".concat(f.id,"/messages"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:j.trim()})}),t=await e.json();t.success&&(v(e=>[...e,t.data]),N(""),g(e=>e.map(e=>e.id===f.id?(0,a.A)((0,a.A)({},e),{},{lastMessage:t.data,lastMessageAt:t.data.createdAt}):e)))}catch(e){}finally{w(!1)}}},I=h.reduce((e,t)=>e+(t.unreadCount||0),0);return(0,l.jsxs)("div",{className:"p-6 max-w-5xl mx-auto",children:[(0,l.jsxs)("h2",{className:"text-2xl font-bold text-[#002147] mb-5",children:["Messages from Parents",I>0&&(0,l.jsx)("span",{className:"ml-2 bg-red-500 text-white text-xs font-bold px-2 py-0.5 rounded-full",children:I})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:"1rem",height:"520px"},children:[(0,l.jsxs)("div",{style:{width:"260px",flexShrink:0,overflowY:"auto",display:"flex",flexDirection:"column",gap:"0.4rem"},children:[k&&(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:"0.85rem",padding:"1rem"},children:"Loading\u2026"}),!k&&0===h.length&&(0,l.jsx)("p",{style:{color:"#9ca3af",fontSize:"0.85rem",padding:"1rem"},children:"No conversations yet."}),h.map(e=>{var t,s,n,o,i,d,c,x,u;return(0,l.jsxs)("button",{onClick:()=>(async e=>{b(e);const t=await(0,r.n)("/chat/threads/".concat(e.id,"/messages")),s=await t.json();s.success&&(v(s.data),g(t=>t.map(t=>t.id===e.id?(0,a.A)((0,a.A)({},t),{},{unreadCount:0}):t)))})(e),style:{textAlign:"left",padding:"0.75rem",borderRadius:"8px",border:"1.5px solid ".concat((null===f||void 0===f?void 0:f.id)===e.id?"#002147":"#e5e7eb"),background:(null===f||void 0===f?void 0:f.id)===e.id?"#f0f4ff":"white",cursor:"pointer",transition:"all 0.15s"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,l.jsxs)("div",{style:{fontWeight:"700",fontSize:"0.85rem",color:"#111827"},children:[null===(t=e.student)||void 0===t||null===(s=t.user)||void 0===s?void 0:s.firstName," ",null===(n=e.student)||void 0===n||null===(o=n.user)||void 0===o?void 0:o.lastName]}),e.unreadCount>0&&(0,l.jsx)("span",{style:{background:"#dc2626",color:"white",borderRadius:"9999px",fontSize:"0.65rem",fontWeight:"700",padding:"1px 6px",flexShrink:0},children:e.unreadCount})]}),(0,l.jsxs)("div",{style:{fontSize:"0.75rem",color:"#6b7280",marginTop:"2px"},children:[null===(i=e.parent)||void 0===i||null===(d=i.user)||void 0===d?void 0:d.firstName," ",null===(c=e.parent)||void 0===c||null===(x=c.user)||void 0===x?void 0:x.lastName," \xb7 ",null===(u=e.group)||void 0===u?void 0:u.name]}),e.lastMessage&&(0,l.jsx)("div",{style:{fontSize:"0.72rem",color:"#9ca3af",marginTop:"4px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.lastMessage.body})]},e.id)})]}),(0,l.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",background:"#f9fafb",borderRadius:"10px",border:"1px solid #e5e7eb",overflow:"hidden"},children:f?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{style:{padding:"0.75rem 1rem",background:"#002147",color:"white"},children:[(0,l.jsxs)("div",{style:{fontWeight:"700",fontSize:"0.9rem"},children:[null===(t=f.student)||void 0===t||null===(s=t.user)||void 0===s?void 0:s.firstName," ",null===(o=f.student)||void 0===o||null===(i=o.user)||void 0===i?void 0:i.lastName]}),(0,l.jsxs)("div",{style:{fontSize:"0.75rem",opacity:.7},children:[null===(d=f.parent)||void 0===d||null===(c=d.user)||void 0===c?void 0:c.firstName," ",null===(x=f.parent)||void 0===x||null===(u=x.user)||void 0===u?void 0:u.lastName," \xb7 ",null===(m=f.group)||void 0===m?void 0:m.name]})]}),(0,l.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"1rem",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[0===y.length&&(0,l.jsx)("p",{style:{color:"#9ca3af",textAlign:"center",fontSize:"0.82rem",marginTop:"2rem"},children:"No messages yet."}),y.map(e=>{const t=e.senderUserId===p;return(0,l.jsx)("div",{style:{display:"flex",justifyContent:t?"flex-end":"flex-start"},children:(0,l.jsxs)("div",{style:{maxWidth:"75%",padding:"0.5rem 0.75rem",borderRadius:t?"12px 12px 2px 12px":"12px 12px 12px 2px",background:t?"#002147":"white",color:t?"white":"#111827",fontSize:"0.85rem",boxShadow:"0 1px 2px rgba(0,0,0,0.08)"},children:[!t&&(0,l.jsxs)("div",{style:{fontSize:"0.68rem",fontWeight:"700",color:"#6b7280",marginBottom:"2px"},children:[e.sender.firstName," ",e.sender.lastName]}),(0,l.jsx)("div",{children:e.body}),(0,l.jsxs)("div",{style:{fontSize:"0.65rem",opacity:.6,marginTop:"3px",textAlign:"right"},children:[new Date(e.createdAt).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),t&&e.readAt&&" \xb7 \u2713"]})]})},e.id)}),(0,l.jsx)("div",{ref:C})]}),(0,l.jsxs)("div",{style:{padding:"0.75rem",borderTop:"1px solid #e5e7eb",display:"flex",gap:"0.5rem"},children:[(0,l.jsx)("input",{value:j,onChange:e=>N(e.target.value),onKeyDown:e=>"Enter"===e.key&&!e.shiftKey&&E(),placeholder:"Type a reply\u2026",style:{flex:1,padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:"8px",fontSize:"0.85rem"}}),(0,l.jsx)("button",{onClick:E,disabled:!j.trim()||S,style:{padding:"0.5rem 1rem",background:j.trim()?"#002147":"#e5e7eb",color:j.trim()?"white":"#9ca3af",border:"none",borderRadius:"8px",cursor:j.trim()?"pointer":"default",fontWeight:"600",fontSize:"0.85rem"},children:"Send"})]})]}):(0,l.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"#9ca3af",fontSize:"0.85rem"},children:"Select a conversation"})})]})]})}const Ue=e=>e?new Date(e).toLocaleDateString("ru-RU"):"",He=e=>
1e?new Date(e).toLocaleString("ru-RU",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"";function Ve(){const{theme:e}=(0,i.DP)(),[t,s]=(0,n.useState)([]),[o,d]=(0,n.useState)([]),[c,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(""),[p,h]=(0,n.useState)(""),[g,f]=(0,n.useState)(""),[b,y]=(0,n.useState)(""),[v,j]=(0,n.useState)(null),[S,w]=(0,n.useState)(""),[k,A]=(0,n.useState)(1),[C,T]=(0,n.useState)("none"),[E,I]=(0,n.useState)(!1),[R,D]=(0,n.useState)(""),[L,z]=(0,n.useState)(null),[W,B]=(0,n.useState)({}),M=(0,n.useCallback)(async()=>{try{const[e,t,n]=await Promise.all([(0,r.n)("/groups"),(0,r.n)("/print-requests?limit=200"),(0,r.n)("/library?limit=200")]),[a,l,o]=await Promise.all([e.json(),t.json(),n.json()]);a.success&&s(a.data||[]),l.success&&d(l.data||[]),o.success&&x(o.data||[])}catch(e){console.error("Failed to fetch data:",e)}},[]);(0,n.useEffect)(()=>{M()},[M]);const P=()=>{h(""),f(""),y(""),j(null),w(""),A(1),T("none"),D(""),z(null)},O=e=>{if(e.fileUrl){const t=e.fileUrl.split("/").pop();return{url:"".concat(N.H,"/api/v1/print-requests/files/").concat(t),label:e.fileName||t}}if(e.libraryItem){if(e.libraryItem.fileUrl){const t=e.libraryItem.fileUrl.split("/").pop();return{url:"".concat(N.H,"/api/v1/library/files/").concat(t),label:e.libraryItem.title||e.libraryItem.originalName}}return{url:null,label:e.libraryItem.title}}return null},G=c.filter(e=>!u||e.title.toLowerCase().includes(u.toLowerCase())),F=o.filter(e=>"PENDING"===e.status),_=o.filter(e=>"PRINTED"===e.status);return(0,l.jsxs)("div",{className:"p-4 lg:p-6 max-w-5xl mx-auto",children:[(0,l.jsx)("h2",{className:"text-xl font-bold mb-6",style:{color:e.text},children:"Print Requests"}),(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow-sm border p-5 mb-8",children:[(0,l.jsx)("h3",{className:"text-base font-semibold mb-4",style:{color:e.text},children:L?"Edit Request":"New Print Request"}),(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),D(""),!p)return D("Please select a group");if(!g)return D("Please select a date");if(!b.trim())return D("Please enter a description");I(!0);try{const e=new FormData;e.append("groupId",p),e.append("sessionDate",g),e.append("description",b.trim()),e.append("copies",String(k)),"upload"===C&&v&&e.append("file",v),"library"===C&&S&&e.append("libraryItemId",S);const t=L?"/print-requests/".concat(L):"/print-requests",s=L?"PATCH":"POST",n=await(0,r.n)(t,{method:s,body:e}),a=await n.json();a.success?(P(),M()):D(a.message||"Something went wrong")}catch(t){D("Failed to submit request")}finally{I(!1)}},className:"space-y-4",children:[(0,l.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",style:{color:e.secondary},children:"Group *"}),(0,l.jsxs)("select",{value:p,onChange:e=>h(e.target.value),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm",children:[(0,l.jsx)("option",{value:"",children:"-- Select group --"}),t.map(e=>(0,l.jsxs)("option",{value:e.id,children:[e.name," (",e.groupCode,")"]},e.id))]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",style:{color:e.secondary},children:"Session Date *"}),(0,l.jsx)("input",{type:"date",value:g,onChange:e=>f(e.target.value),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",style:{color:e.secondary},children:"What to print *"}),(0,l.jsx)("textarea",{value:b,onChange:e=>y(e.target.value),placeholder:"e.g. Unit 7 worksheet, pages 3-5 from Headway Intermediate",rows:3,className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm resize-none"})]}),(0,l.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",style:{color:e.secondary},children:"Number of copies"}),(0,l.jsx)("input",{type:"number",min:"1",max:"100",value:k,onChange:e=>A(Math.max(1,parseInt(e.target.value)||1)),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-1",style:{color:e.secondary},children:"Attach material"}),(0,l.jsx)("div",{className:"flex gap-2",children:[{key:"none",label:"None"},{key:"upload",label:"Upload File"},{key:"library",label:"From Library"}].map(t=>{let{key:s,label:n}=t;return(0,l.jsx)("button",{type:"button",onClick:()=>{T(s),"upload"!==s&&j(null),"library"!==s&&w("")},className:"px-3 py-1.5 rounded-lg text-xs font-medium transition-colors border",style:C===s?{backgroundColor:e.primary,color:"white",borderColor:e.primary}:{borderColor:"#d1d5db",color:e.secondary},children:n},s)})})]})]}),"upload"===C&&(0,l.jsxs)("div",{children:[(0,l.jsx)("input",{type:"file",onChange:e=>
1j(e.target.files[0]||null),className:"w-full text-sm file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"}),v&&(0,l.jsxs)("p",{className:"text-xs mt-1",style:{color:e.secondary},children:["Selected: ",v.name," (",(v.size/1024).toFixed(1)," KB)"]})]}),"library"===C&&(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg p-3 max-h-48 overflow-y-auto",children:[(0,l.jsx)("input",{type:"text",value:u,onChange:e=>m(e.target.value),placeholder:"Search library...",className:"w-full border border-gray-200 rounded px-2 py-1 text-sm mb-2"}),0===G.length?(0,l.jsx)("p",{className:"text-xs text-gray-400 text-center py-2",children:"No items found"}):(0,l.jsx)("div",{className:"space-y-1",children:G.map(t=>(0,l.jsxs)("label",{className:"flex items-center gap-2 px-2 py-1.5 rounded hover:bg-gray-50 cursor-pointer",children:[(0,l.jsx)("input",{type:"radio",name:"libraryItem",checked:S===t.id,onChange:()=>w(t.id),className:"text-blue-600"}),(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("p",{className:"text-sm font-medium truncate",style:{color:e.text},children:t.title}),(0,l.jsxs)("p",{className:"text-xs",style:{color:e.secondary},children:[t.skillType," ",t.level?"- ".concat(t.level):""," - ",t.originalName]})]})]},t.id))})]}),R&&(0,l.jsx)("p",{className:"text-sm text-red-600",children:R}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{type:"submit",disabled:E,className:"px-5 py-2 rounded-lg text-sm font-medium text-white transition-colors disabled:opacity-50",style:{backgroundColor:e.primary},children:E?"Submitting...":L?"Update Request":"Submit Request"}),L&&(0,l.jsx)("button",{type:"button",onClick:P,className:"px-4 py-2 rounded-lg text-sm font-medium border border-gray-300 hover:bg-gray-50",style:{color:e.secondary},children:"Cancel"})]})]})]}),F.length>0&&(0,l.jsxs)("div",{className:"mb-8",children:[(0,l.jsxs)("h3",{className:"text-base font-semibold mb-3 flex items-center gap-2",style:{color:e.text},children:[(0,l.jsx)("span",{className:"w-2.5 h-2.5 rounded-full bg-amber-400"}),"Pending (",F.length,")"]}),(0,l.jsx)("div",{className:"space-y-3",children:F.map(t=>{var s;const n=O(t);return(0,l.jsx)("div",{className:"bg-white rounded-xl shadow-sm border p-4",children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,l.jsx)("span",{className:"font-medium text-sm",style:{color:e.primary},children:null===(s=t.group)||void 0===s?void 0:s.name}),(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100",style:{color:e.secondary},children:Ue(t.sessionDate)}),t.copies>1&&(0,l.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-700",children:["x",t.copies]})]}),(0,l.jsx)("p",{className:"text-sm",style:{color:e.text},children:t.description}),n&&(0,l.jsx)("p",{className:"text-xs mt-1",children:n.url?(0,l.jsxs)("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:["\ud83d\udcce ",n.label]}):(0,l.jsxs)("span",{style:{color:e.secondary},children:["\ud83d\udcda ",n.label]})}),(0,l.jsxs)("p",{className:"text-xs mt-1",style:{color:e.secondary},children:["Created ",He(t.createdAt)]})]}),(0,l.jsxs)("div",{className:"flex gap-1 flex-shrink-0",children:[(0,l.jsx)("button",{onClick:()=>(e=>{z(e.id),h(e.groupId),f(new Date(e.sessionDate).toISOString().split("T")[0]),y(e.description),A(e.copies),e.libraryItemId?(T("library"),w(e.libraryItemId)):e.fileUrl?T("upload"):T("none"),j(null),D(""),window.scrollTo({top:0,behavior:"smooth"})})(t),className:"px-2.5 py-1 rounded text-xs font-medium border border-gray-300 hover:bg-gray-50",style:{color:e.secondary},children:"Edit"}),(0,l.jsx)("button",{onClick:()=>(async e=>{if(window.confirm("Delete this print request?")){B(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!0}));try{const t=await(0,r.n)("/print-requests/".concat(e),{method:"DELETE"});(await t.json()).success&&d(t=>t.filter(t=>t.id!==e))}catch(t){console.error("Failed to delete:",t)}finally{B(t=>(0,a.A)((0,a.A)({},t),{},{[e]:!1}))}}})(t.id),disabled:W[t.id],className:"px-2.5 py-1 rounded text-xs font-medium text-red-600 border border-red-200 hover:bg-red-50 disabled:opacity-50",children:W[t.id]?"...":"Delete"})]})]})},t.id)})})]}),_.length>0&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("h3",{className:"text-base font-semibold mb-3 flex items-center gap-2",style:{color:e.text},children:[(0,l.jsx)("span",{className:"w-2.5 h-2.5 rounded-full bg-green-400"}),"Printed (",_.length,")"]}),(0,l.jsx)("div",{className:"space-y-2",children:_.map(t=>{var s;const n=O(t);return(0,l.jsx)("div",{className:"bg-white rounded-xl shadow-sm border p-4 opacity-70",children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,l.jsx)("span",{className:"font-medium text-sm",style:{color:e.primary},children:null===(s=t.group)||void 0===s?void 0:s.name}),(0,l.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100",style:{color:e.secondary},children:Ue(t.sessionDate)})]}),(0,l.jsx)("p",{className:"text-sm line-through",style:{color:e.secondary},children:t.description}),n&&(0,l.jsx)("p",{className:"text-xs mt-1",children:n.url?(0,l.jsxs)("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:["\ud83d\udcce ",n.label]}):(0,l.jsxs)("span",{style:{color:e.secondary},children:["\ud83d\udcda ",n.label]})})]}),(0,l.jsxs)("div",{className:"text-right flex-shrink-0",children:[(0,l.jsx)("span",{className:"inline-block px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800",children:"Printed"}),t.printedBy&&(0,l.jsxs)("p",{className:"text-xs mt-1",style:{color:e.secondary},children:["by ",t.printedBy.firstName," ",t.printedBy.lastName]}),t.printedAt&&(0,l.jsx)("p",{className:"text-xs",style:{color:e.secondary},children:He(t.printedAt)})]})]})},t.id)})})]}),0===o.length&&(0,l.jsxs)("div",{className:"text-center py-8",children:[(0,l.jsx)("p",{className:"text-lg",style:{color:e.secondary},children:"No print requests yet"}),(0,l.jsx)("p",{className:"text-sm mt-1",style:{color:e.secondary},children:"Use the form above to request materials for your classes"})]})]})}const Ye=["CELTA","DELTA","TESOL","TEFL","IELTS","CEFR","CUSTOM"],qe={APPROVED:"bg-green-100 text-green-700",PENDING:"bg-yellow-100 text-yellow-700",REJECTED:"bg-red-100 text-red-700"},Je={IELTS:"bg-blue-100 text-blue-700",CEFR:"bg-green-100 text-green-700",CUSTOM:"bg-purple-100 text-purple-700"};function Ke(){const{theme:e}
1=(0,i.DP)(),[t,s]=(0,n.useState)([]),[o,d]=(0,n.useState)(!0),[c,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[p,h]=(0,n.useState)(!1),[g,f]=(0,n.useState)({type:"CUSTOM",name:"",issuingBody:"",result:"",certificateNumber:"",issueDate:"",expiryDate:"",notes:"",file:null}),[b,y]=(0,n.useState)(!1),[v,j]=(0,n.useState)(""),[N,S]=(0,n.useState)("my"),w=(0,n.useCallback)(async()=>{d(!0);try{const e=await(0,r.n)("/teacher-certificates/my"),t=await e.json();t.success&&s(t.data||[])}catch(e){console.error("Failed to fetch my certificates:",e)}finally{d(!1)}},[]),k=(0,n.useCallback)(async()=>{m(!0);try{var e;const t=await(0,r.n)("/certificates?status=APPROVED&groupStudents=true&limit=200"),s=await t.json();s.success&&x((null===(e=s.data)||void 0===e?void 0:e.certificates)||[])}catch(t){console.error("Failed to fetch student certificates:",t)}finally{m(!1)}},[]);(0,n.useEffect)(()=>{w(),k()},[w,k]);const A=e=>{if("IELTS"===e.type){const t=null!=e.ieltsListening?Number(e.ieltsListening).toFixed(1):"-",s=null!=e.ieltsReading?Number(e.ieltsReading).toFixed(1):"-",n=null!=e.ieltsWriting?Number(e.ieltsWriting).toFixed(1):"-",r=null!=e.ieltsSpeaking?Number(e.ieltsSpeaking).toFixed(1):"-",a=null!=e.ieltsOverall?Number(e.ieltsOverall).toFixed(1):"-";return"L:".concat(t," R:").concat(s," W:").concat(n," S:").concat(r," = ").concat(a)}return"CEFR"===e.type?e.cefrLevel||"-":[e.customName,e.customResult].filter(Boolean).join(": ")||"-"};return(0,l.jsxs)("div",{className:"p-4 md:p-6 max-w-6xl mx-auto",children:[(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-6",children:[(0,l.jsx)("h1",{className:"text-2xl font-bold",style:{color:e.primary},children:"Achievements"}),(0,l.jsx)("button",{onClick:()=>{f({type:"CUSTOM",name:"",issuingBody:"",result:"",certificateNumber:"",issueDate:"",expiryDate:"",notes:"",file:null}),h(!0)},className:"px-4 py-2 rounded-lg text-white font-medium",style:{backgroundColor:e.primary},children:"+ Add My Certificate"})]}),v&&(0,l.jsx)("div",{className:"mb-4 p-3 rounded-lg text-sm ".concat(v.includes("Error")?"bg-red-50 text-red-700":"bg-green-50 text-green-700"),children:v}),(0,l.jsxs)("div",{className:"flex gap-2 mb-6",children:[(0,l.jsxs)("button",{onClick:()=>S("my"),className:"px-4 py-2 rounded-lg font-medium transition-all ".concat("my"===N?"text-white":"text-gray-600 bg-gray-100"),style:"my"===N?{backgroundColor:e.primary}:{},children:["My Certificates (",t.length,")"]}),(0,l.jsxs)("button",{onClick:()=>S("students"),className:"px-4 py-2 rounded-lg font-medium transition-all ".concat("students"===N?"text-white":"text-gray-600 bg-gray-100"),style:"students"===N?{backgroundColor:e.primary}:{},children:["Student Achievements (",c.length,")"]})]}),"my"===N&&(0,l.jsx)(l.Fragment,{children:o?(0,l.jsx)("p",{className:"text-gray-400",children:"Loading..."}):0===t.length?(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow p-8 text-center text-gray-400",children:[(0,l.jsx)("p",{className:"text-lg mb-2",children:"No certificates yet"}),(0,l.jsx)("p",{className:"text-sm",children:"Add your professional certificates to showcase your qualifications"})]}):(0,l.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:t.map(e=>(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow p-4 border-l-4",style:{borderLeftColor:"APPROVED"===e.status?"#10b981":"PENDING"===e.status?"#f59e0b":"#ef4444"},children:[(0,l.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"font-bold text-gray-800",children:e.name}),(0,l.jsx)("p",{className:"text-sm text-gray-500",children:e.issuingBody||""})]}),(0,l.jsx)("span",{className:"px-2 py-1 rounded-full text-xs font-medium ".concat(qe[e.status]||""),children:e.status})]}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs text-gray-500",children:[(0,l.jsx)("span",{className:"px-2 py-1 rounded bg-blue-50 text-blue-700 font-medium",children:e.type}),e.result&&(0,l.jsxs)("span",{children:["Result: ",e.result]}),e.certificateNumber&&(0,l.jsxs)("span",{children:["#",e.certificateNumber]}),e.issueDate&&(0,l.jsxs)("span",{children:["Issued: ",new Date(e.issueDate).toLocaleDateString("en-GB")]}),e.expiryDate&&(0,l.jsxs)("span",{children:["Expires: ",new Date(e.expiryDate).toLocaleDateString("en-GB")]})]}),e.rejectionReason&&(0,l.jsxs)("div",{className:"mt-2 p-2 bg-red-50 rounded text-xs text-red-700",children:["Rejection reason: ",e.rejectionReason]}),e.fileUrl&&(0,l.jsx)("a",{href:"".concat(r.C,"/teacher-certificates/files/").concat(e.fileUrl.split("/").pop()),target:"_blank",rel:"noopener noreferrer",className:"inline-block mt-2 text-xs text-blue-600 hover:underline",children:"View certificate file"})]},e.id))})}),"students"===N&&(0,l.jsx)(l.Fragment,{children:u?(0,l.jsx)("p",{className:"text-gray-400",children:"Loading..."}):0===c.length?(0,l.jsx)("div",{className:"bg-white rounded-lg shadow p-8 text-center text-gray-400",children:(0,l.jsx)("p",{className:"text-lg",children:"No student certificates yet"})}):(0,l.jsx)("div",{className:"bg-white rounded-lg shadow overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{style:{backgroundColor:e.primary},className:"text-white",children:[(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"#"}),(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"Student"}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Type"}),(0,l.jsx)("th",{className:"px-4 py-3 text-left",children:"Result"}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"Exam Date"}),(0,l.jsx)("th",{className:"px-4 py-3 text-center",children:"File"})]})}),(0,l.jsx)("tbody",{children:c.map((e,t)=>{var s;return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50",children:[(0,l.jsx)("td",{className:"px-4 py-3",children:t+1}),(0,l.jsx)("td",{className:"px-4 py-3 font-medium",children:null!==(s=e.student)&&void 0!==s&&s.user?"".concat(e.student.user.firstName," ").concat(e.student.user.lastName):"-"}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:(0,l.jsx)("span",{className:"px-2 py-1 rounded-full text-xs font-medium ".concat(Je[e.type]||""),children:e.type})}),(0,l.jsx)("td",{className:"px-4 py-3 font-mono text-xs",children:A(e)}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:new Date(e.examDate).toLocaleDateString("en-GB")}),(0,l.jsx)("td",{className:"px-4 py-3 text-center",children:e.fileUrl?(0,l.jsx)("a",{href:"".concat(r.C,"/certificates/files/").concat(e.fileUrl.split("/").pop()),target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-600 hover:underline",children:"View"}):"-"})]},e.id)})})]})})}),p&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-lg max-h-[90vh] overflow-y-auto p-6",children:[(0,l.jsx)("h2",{className:"text-xl font-bold mb-4",style:{color:e.primary},children:"Add Certificate"}),(0,l.jsx)("p",{className:"text-sm text-yellow-600 bg-yellow-50 p-2 rounded mb-4",children:"Your certificate will be submitted for admin a
1pproval."}),(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Type *"}),(0,l.jsx)("select",{value:g.type,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{type:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm",children:Ye.map(e=>(0,l.jsx)("option",{value:e,children:e},e))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Certificate Name *"}),(0,l.jsx)("input",{type:"text",value:g.name,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{name:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. CELTA, DELTA Module 1, IELTS Band 8.0"})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Issuing Body"}),(0,l.jsx)("input",{type:"text",value:g.issuingBody,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{issuingBody:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. Cambridge"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Result"}),(0,l.jsx)("input",{type:"text",value:g.result,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{result:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. Pass Grade A"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Certificate Number"}),(0,l.jsx)("input",{type:"text",value:g.certificateNumber,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{certificateNumber:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Issue Date"}),(0,l.jsx)("input",{type:"date",value:g.issueDate,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{issueDate:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Expiry Date"}),(0,l.jsx)("input",{type:"date",value:g.expiryDate,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{expiryDate:e.target.value})),className:"w-full border rounded-lg px-3 py-2 text-sm"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Notes"}),(0,l.jsx)("textarea",{value:g.notes,onChange:e=>f((0,a.A)((0,a.A)({},g),{},{notes:e.target.value})),rows:2,className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Certificate File"}),(0,l.jsx)("input",{type:"file",accept:".pdf,.jpg,.jpeg,.png,.webp",onChange:e=>f((0,a.A)((0,a.A)({},g),{},{file:e.target.files[0]||null})),className:"w-full text-sm text-gray-600 file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"})]})]}),(0,l.jsxs)("div",{className:"flex gap-3 mt-6",children:[(0,l.jsx)("button",{onClick:()=>h(!1),className:"flex-1 px-4 py-2 rounded-lg border text-gray-600 hover:bg-gray-50",children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{y(!0),j("");try{const e=new FormData;e.append("type",g.type),e.append("name",g.name),g.issuingBody&&e.append("issuingBody",g.issuingBody),g.result&&e.append("result",g.result),g.certificateNumber&&e.append("certificateNumber",g.certificateNumber),g.issueDate&&e.append("issueDate",g.issueDate),g.expiryDate&&e.append("expiryDate",g.expiryDate),g.notes&&e.append("notes",g.notes),g.file&&e.append("file",g.file);const t=await(0,r.n)("/teacher-certificates",{method:"POST",body:e}),s=await t.json();s.success?(j("Certificate submitted for approval"),h(!1),w()):j(s.message||"Error saving certificate")}catch(e){j("Error saving certificate")}finally{y(!1)}},disabled:b||!g.name,className:"flex-1 px-4 py-2 rounded-lg text-white font-medium disabled:opacity-50",style:{backgroundColor:e.primary},children:b?"...":"Submit for Approval"})]})]})})]})}const Qe={DRAFT:"bg-gray-100 text-gray-600",PUBLISHED:"bg-blue-100 text-blue-700",IN_PROGRESS:"bg-yellow-100 text-yellow-800",COMPLETED:"bg-green-100 text-green-700",CANCELLED:"bg-red-100 text-red-700"};function Xe(e){let{status:t}=e;return(0,l.jsx)("span",{className:"inline-flex px-2 py-0.5 rounded-full text-xs font-semibold ".concat(Qe[t]||"bg-gray-100 text-gray-600"),children:t})}function Ze(e){let{checked:t,total:s,size:n=48}=e;const r=(n-6)/2,a=2*Math.PI*r,o=a*(1-(s>0?t/s:0));
1return(0,l.jsxs)("svg",{width:n,height:n,className:"-rotate-90",children:[(0,l.jsx)("circle",{cx:n/2,cy:n/2,r:r,fill:"none",stroke:"#e5e7eb",strokeWidth:5}),(0,l.jsx)("circle",{cx:n/2,cy:n/2,r:r,fill:"none",stroke:"#4f46e5",strokeWidth:5,strokeDasharray:a,strokeDashoffset:o,strokeLinecap:"round",style:{transition:"stroke-dashoffset 0.4s ease"}})]})}const $e=[{status:"READY",label:"Ready",activeClass:"bg-green-500 text-white border-green-500 shadow-sm",hoverClass:"hover:bg-green-50 hover:border-green-400 hover:text-green-700"},{status:"NOT_READY",label:"Not Ready",activeClass:"bg-red-500 text-white border-red-500 shadow-sm",hoverClass:"hover:bg-red-50 hover:border-red-400 hover:text-red-700"},{status:"ABSENT",label:"Absent",activeClass:"bg-orange-500 text-white border-orange-500 shadow-sm",hoverClass:"hover:bg-orange-50 hover:border-orange-400 hover:text-orange-700"}];function et(e){var t;let{enrollment:s,taskId:a,onUpdated:o}=e;const[i,d]=(0,n.useState)(s.status||"PENDING"),[c,x]=(0,n.useState)(s.notes||""),[u,m]=(0,n.useState)(!1),[p,h]=(0,n.useState)(s.status||"PENDING"),g=(0,n.useRef)(null),f=null!==(t=s.student)&&void 0!==t&&t.user?"".concat(s.student.user.firstName," ").concat(s.student.user.lastName):s.studentId;return(0,l.jsxs)("div",{className:"rounded-xl border p-3 transition-colors ".concat("READY"===i?"border-green-200 bg-green-50/40":"NOT_READY"===i?"border-red-200 bg-red-50/40":"ABSENT"===i?"border-orange-200 bg-orange-50/40":"border-gray-200 bg-white"),children:[(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,l.jsx)("div",{className:"flex-1 min-w-0",children:(0,l.jsx)("p",{className:"font-medium text-gray-800 truncate",children:f})}),(0,l.jsx)("div",{className:"flex gap-2 shrink-0",children:$e.map(e=>(0,l.jsx)("button",{onClick:()=>async function(e){if(!u){d(e),m(!0);try{await(0,r.n)("/vocab-checks/tasks/".concat(a,"/students/").concat(s.studentId),{method:"PUT",body:JSON.stringify({status:e,notes:c})}),h(e),o&&o(s.studentId,e,c)}catch(t){d(p)}finally{m(!1)}}}(e.status),disabled:u,className:"px-3 py-1.5 rounded-lg border text-sm font-medium transition-all active:scale-95 disabled:opacity-60 ".concat(i===e.status?e.activeClass:"bg-white text-gray-600 border-gray-300 ".concat(e.hoverClass)),children:e.label},e.status))})]}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)("textarea",{value:c,onChange:function(e){const t=e.target.value;x(t),g.current&&clearTimeout(g.current),"PENDING"!==i&&(g.current=setTimeout(async()=>{try{await(0,r.n)("/vocab-checks/tasks/".concat(a,"/students/").concat(s.studentId),{method:"PUT",body:JSON.stringify({status:i,notes:t})}),o&&o(s.studentId,i,t)}catch(e){}},800))},placeholder:"Notes (optional)\u2026",rows:1,className:"w-full text-sm border border-gray-200 rounded-lg px-2 py-1 resize-none focus:outline-none focus:ring-2 focus:ring-indigo-400 bg-white/80"})}),u&&(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Saving\u2026"})]})}function tt(e){var t,s;let{task:o,onCompleted:i}=e;
1const[d,c]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),[m,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)(!1),[f,b]=(0,n.useState)(""),[y,v]=(0,n.useState)({}),[j,N]=(0,n.useState)(!1),S=(0,n.useCallback)(async()=>{if(!x){p(!0);try{const e=await(0,r.n)("/vocab-checks/tasks/".concat(o.id)),t=e.data||e;u(t);const s={};(t.enrollments||[]).forEach(e=>{s[e.studentId]={status:e.status,notes:e.notes||""}}),v(s)}catch(e){b("Failed to load task details.")}finally{p(!1)}}},[o.id,x]);function w(e,t,s){v(n=>(0,a.A)((0,a.A)({},n),{},{[e]:{status:t,notes:s}}))}const k=(null===x||void 0===x?void 0:x.enrollments)||[],A=(null===x||void 0===x||null===(t=x.vocabularyList)||void 0===t?void 0:t.items)||[],C=Object.values(y).filter(e=>"PENDING"!==e.status).length,T=k.length,E={READY:Object.values(y).filter(e=>"READY"===e.status).length,NOT_READY:Object.values(y).filter(e=>"NOT_READY"===e.status).length,ABSENT:Object.values(y).filter(e=>"ABSENT"===e.status).length,PENDING:Object.values(y).filter(e=>"PENDING"===e.status).length},I=["PUBLISHED","IN_PROGRESS"].includes(o.status);return(0,l.jsxs)("div",{className:"rounded-2xl border shadow-sm overflow-hidden ".concat("COMPLETED"===o.status?"border-green-200 bg-green-50/30":"IN_PROGRESS"===o.status?"border-yellow-200 bg-yellow-50/30":"border-gray-200 bg-white"),children:[(0,l.jsx)("div",{className:"p-4 cursor-pointer select-none",onClick:function(){d||S(),c(e=>!e)},children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,l.jsx)("h3",{className:"font-semibold text-gray-800",children:o.title}),(0,l.jsx)(Xe,{status:o.status})]}),(0,l.jsxs)("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-gray-500",children:[o.group&&(0,l.jsxs)("span",{children:["Group: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:o.group.name})]}),o.vocabularyList&&(0,l.jsxs)("span",{children:["List: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:o.vocabularyList.title})]}),(0,l.jsxs)("span",{children:["Date: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:(R=o.scheduledAt,R?new Date(R).toLocaleString("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"\u2014")})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[T>0&&(0,l.jsxs)("div",{className:"relative flex items-center justify-center",children:[(0,l.jsx)(Ze,{checked:C,total:T||1,size:44}),(0,l.jsxs)("span",{className:"absolute text-xs font-bold text-indigo-700",children:[C,"/",T||"?"]})]}),(0,l.jsx)("svg",{className:"w-5 h-5 text-gray-400 transition-transform ".concat(d?"rotate-180":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]})}),d&&(0,l.jsxs)("div",{className:"border-t border-gray-100 px-4 pb-5 space-y-5",children:[f&&(0,l.jsx)("p",{className:"text-sm text-red-600 bg-red-50 rounded-lg px-3 py-2 mt-4",children:f}),m?(0,l.jsx)("div",{className:"py-8 text-center text-gray-400 text-sm",children:"Loading\u2026"}):(0,l.jsxs)(l.Fragment,{children:[A.length>0&&(0,l.jsxs)("div",{className:"pt-4",children:[(0,l.jsxs)("h4",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2",children:["Vocabulary \u2014 ",null===x||void 0===x||null===(s=x.vocabularyList)||void 0===s?void 0:s.title]}),(0,l.jsx)("div",{className:"flex flex-wrap gap-2",children:A.map(e=>(0,l.jsxs)("div",{className:"px-3 py-1.5 bg-indigo-50 border border-indigo-100 rounded-lg text-sm",children:[(0,l.jsx)("span",{className:"font-semibold text-indigo-800",children:e.term}),e.definition&&(0,l.jsxs)("span",{className:"text-indigo-500 ml-1",children:["\u2014 ",e.definition]})]},e.id))})]}),(null===x||void 0===x?void 0:x.notes)&&(0,l.jsxs)("div",{className:"bg-amber-50 border border-amber-100 rounded-lg px-3 py-2 text-sm text-amber-800",children:[(0,l.jsx)("span",{className:"font-medium",children:"Instructions:"})," ",x.notes]}),T>0&&(0,l.jsxs)("div",{className:"flex gap-3 flex-wrap text-sm",children:[(0,l.jsxs)("span",{className:"font-medium text-green-700",children:[E.READY," Ready"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-red-700",children:[E.NOT_READY," Not Ready"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-orange-700",children:[E.ABSENT," Absent"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"text-gray-400",children:[E.PENDING," Pending"]}),(0,l.jsxs)("span",{className:"ml-auto text-gray-500 font-medium",children:[C,"/",T," checked"]})]}),0===k.length?(0,l.jsx)("p",{className:"text-sm text-gray-400 text-center py-4",children:"No students in this task."}):(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsxs)("h4",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide",children:["Students (",k.length,")"]}),k.map(e=>{var t,s,n;return(0,l.jsx)(et,{enrollment:(0,a.A)((0,a.A)({},e),{},{status:(null===(t=y[e.studentId])||void 0===t?void 0:t.status)||e.status,notes:null!==(s=null===(n=y[e.studentId])||void 0===n?void 0:n.notes)&&void 0!==s?s:e.notes}
1),taskId:o.id,onUpdated:w},e.id)})]}),I&&(0,l.jsxs)("div",{className:"pt-2",children:[j?(0,l.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-green-50 border border-green-200 rounded-xl",children:[(0,l.jsx)("p",{className:"text-sm text-green-800 flex-1",children:"Submit results and complete this check?"}),(0,l.jsx)("button",{onClick:async function(){g(!0),b("");try{await(0,r.n)("/vocab-checks/tasks/".concat(o.id,"/complete"),{method:"POST"}),N(!1),i&&i(o.id)}catch(e){b(e.message||"Failed to complete task."),N(!1)}finally{g(!1)}},disabled:h,className:"px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-lg hover:bg-green-700 disabled:opacity-50",children:h?"Submitting\u2026":"Confirm"}),(0,l.jsx)("button",{onClick:()=>N(!1),className:"px-3 py-2 text-sm text-gray-600 hover:text-gray-800",children:"Cancel"})]}):(0,l.jsx)("button",{onClick:()=>N(!0),disabled:h||E.PENDING===T,className:"w-full py-3 bg-green-600 text-white font-semibold rounded-xl hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Submit Results"}),E.PENDING===T&&T>0&&(0,l.jsx)("p",{className:"text-xs text-gray-400 text-center mt-1",children:"Mark at least one student before submitting."})]}),"COMPLETED"===o.status&&(0,l.jsx)("div",{className:"py-3 px-4 bg-green-100 rounded-xl text-sm text-green-800 font-medium text-center",children:"This check has been completed."})]})]})]});var R}function st(e){var t,s;let{task:a,onPublish:o,onRefresh:i}=e;
1const[d,c]=(0,n.useState)(!1),[x,u]=(0,n.useState)(""),m=a.enrollments||[],p=null!==(t=null===(s=a._count)||void 0===s?void 0:s.enrollments)&&void 0!==t?t:m.length;return(0,l.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm p-4",children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,l.jsx)("h3",{className:"font-semibold text-gray-800 truncate",children:a.title}),(0,l.jsx)(Xe,{status:a.status})]}),(0,l.jsxs)("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-gray-500",children:[a.group&&(0,l.jsxs)("span",{children:["Group: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:a.group.name})]}),a.vocabularyList&&(0,l.jsxs)("span",{children:["List: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:a.vocabularyList.title})]}),a.assignedTo&&(0,l.jsxs)("span",{children:["Assistant: ",(0,l.jsxs)("span",{className:"font-medium text-gray-700",children:[a.assignedTo.firstName," ",a.assignedTo.lastName]})]}),(0,l.jsxs)("span",{children:["Students: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:p})]}),(0,l.jsxs)("span",{children:["Date: ",(0,l.jsx)("span",{className:"font-medium text-gray-700",children:(h=a.scheduledAt,h?new Date(h).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"\u2014")})]})]}),x&&(0,l.jsx)("p",{className:"text-xs text-red-600 mt-1",children:x})]}),"DRAFT"===a.status&&(0,l.jsx)("button",{onClick:async function(e){e.stopPropagation(),c(!0),u("");try{await(0,r.n)("/vocab-checks/tasks/".concat(a.id,"/publish"),{method:"POST"}),i&&i()}catch(t){u(t.message||"Failed to publish.")}finally{c(!1)}},disabled:d,className:"shrink-0 px-3 py-1.5 bg-blue-600 text-white text-xs font-semibold rounded-lg hover:bg-blue-700 disabled:opacity-50 transition-colors",children:d?"Publishing\u2026":"Publish"})]})});var h}function nt(e){let{title:t,count:s}=e;return(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,l.jsx)("h2",{className:"text-base font-semibold text-gray-800",children:t}),void 0!==s&&(0,l.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 text-xs font-medium rounded-full",children:s})]})}function rt(e){var t;let{onClose:s,onCreated:o}=e;const[i,d]=(0,n.useState)({title:"",notes:"",scheduledAt:"",groupId:"",vocabularyListId:"",assignedToId:""}),[c,x]=(0,n.useState)([]),[u,m]=(0,n.useState)([]),[p,h]=(0,n.useState)([]),[g,f]=(0,n.useState)([]),[b,y]=(0,n.useState)([]),[v,j]=(0,n.useState)(!1),[N,S]=(0,n.useState)(!1),[w,k]=(0,n.useState)("");async function A(e){if(e.preventDefault(),!i.title.trim())return k("Title is required.");if(!i.groupId)return k("Select a group.");if(!i.vocabularyListId)return k("Select a vocabulary list.");if(!i.assignedToId)return k("Select an assistant.");if(!i.scheduledAt)return k("Set a date and time.");if(0===b.length)return k("Select at least one student.");S(!0),k("");try{await(0,r.n)("/vocab-checks/tasks",{method:"POST",body:JSON.stringify({title:i.title.trim(),notes:i.notes.trim()||void 0,scheduledAt:i.scheduledAt,groupId:i.groupId,vocabularyListId:i.vocabularyListId,assignedToId:i.assignedToId,studentIds:b})}),o()}catch(t){k(t.message||"Failed to create task.")}finally{S(!1)}}(0,n.useEffect)(()=>{!async function(){try{var e,t;const[s,n,a]=await Promise.all([(0,r.n)("/groups"),(0,r.n)("/vocab-checks/lists"),(0,r.n)("/vocab-checks/assistants")]),l=(null===(e=s.data)||void 0===e?void 0:e.groups)||s.data||s.groups||s||[];x(Array.isArray(l)?l.filter(e=>"CANCELLED"!==e.status):[]);const o=(null===(t=n.data)||void 0===t?void 0:t.lists)||n.data||n.lists||n||[];m(Array.isArray(o)?o:[]);const i=a.data||a||[];h(Array.isArray(i)?i:[])}catch(s){k("Failed to load form data.")}}()},[]),(0,n.useEffect)(()=>{if(!i.groupId)return f([]),void y([]);j(!0),(0,r.n)("/students?groupId=".concat(i.groupId,"&status=ACTIVE&limit=200")).then(e=>{var t;const s=(null===(t=e.data)||void 0===t?void 0:t.students)||e.data||e.students||e||[];f(Array.isArray(s)?s:[]),y([])}).catch(()=>f([])).finally(()=>j(!1))},[i.groupId]);const C=u.find(e=>e.id===i.vocabularyListId);return(0,l.jsx)("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-end sm:items-center justify-center p-0 sm:p-4",children:(0,l.jsxs)("div",{className:"bg-white w-full sm:max-w-2xl sm:rounded-2xl shadow-2xl max-h-screen sm:max-h-[90vh] flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b",children:[(0,l.jsx)("h2",{className:"text-lg font-bold text-gray-900",children:"New Vocabulary Check Task"}),(0,l.jsx)("button",{onClick:s,className:"text-gray-400 hover:text-gray-600 text-2xl leading-none",children:"\xd7"})]}),(0,l.jsxs)("form",{onSubmit:A,className:"overflow-y-auto flex-1 px-5 py-4 space-y-4",children:[w&&(0,l.jsx)("div",{className:"px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:w}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"Title *"}),(0,l.jsx)("input",{type:"text",value:i.title,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),placeholder:"e.g. Unit 5 vocab check \u2013 Group A",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400",required:!0})]}),(0,l.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"Group *"}),(0,l.jsxs)("select",{value:i.groupId,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{groupId:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400",children:[(0,l.jsx)("option",{value:"",children:"Select group\u2026"}),c.map(e=>(0,l.jsxs)("option",{value:e.id,children:[e.name," (",e.groupCode,")"]},e.id))]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"Date & Time *"}),(0,l.jsx)("input",{type:"datetime-local",value:i.scheduledAt,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{scheduledAt:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"Vocabulary List *"}),0===u.length?(0,l.jsxs)("p",{className:"text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2",children:["No vocabulary lists yet. Go to the ",(0,l.jsx)("strong",{children:"Vocabulary Lists"})," tab to create one first."]}):(0,l.jsxs)("select",{value:i.vocabularyListId,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{vocabularyListId:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400",children:[(0,l.jsx)("option",{value:"",children:"Select list\u2026"}),u.map(e=>{var t;return(0,l.jsxs)("option",{value:e.id,children:[e.title,null!==(t=e._count)&&void 0!==t&&t.items?" (".concat(e._count.items," words)"):""]},e.id)})]}),C&&(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-1",children:[(null===(t=C._count)||void 0===t?void 0:t.items)||0," words in this list",C.description?" \xb7 ".concat(C.description):""]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"Assign to Assistant *"}),0===p.length?(0,l.jsx)("p",{className:"text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2",children:"No assistant teachers found. Mark a teacher as assistant in Teachers management."}):(0,l.jsxs)("select",{value:i.assignedToId,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{assignedToId:e.target.value})),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400",children:[(0,l.jsx)("option",{value:"",children:"Select assistant\u2026"}),p.map(e=>(0,l.jsxs)("option",{value:e.user.id,children:[e.user.firstName," ",e.user.lastName]},e.user.id))]})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsxs)("label",{className:"text-xs font-semibold text-gray-600",children:["Students * ",g.length>0&&"(".concat(b.length,"/").concat(g.length," selected)")]}),g.length>0&&(0,l.jsx)("button",{type:"button",onClick:function(){y(e=>e.length===g.length?[]:g.map(e=>e.id))},className:"text-xs text-indigo-600 hover:underline",children:b.length===g.length?"Deselect all":"Select all"})]}),i.groupId?v?(0,l.jsx)("p",{className:"text-xs text-gray-400 py-2",children:"Loading students\u2026"}):0===g.length?(0,l.jsx)("p",{className:"text-xs text-gray-400 py-2",children:"No active students in this group."}):(0,l.jsx)("div",{className:"border border-gray-200 rounded-lg divide-y max-h-48 overflow-y-auto",children:g.map(e=>{const t=e.user?"".concat(e.user.firstName," ").concat(e.user.lastName):e.studentId;return(0,l.jsxs)("label",{className:"flex items-center gap-3 px-3 py-2 hover:bg-gray-50 cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:b.includes(e.id),onChange:()=>
1{return t=e.id,void y(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);var t},className:"w-4 h-4 rounded text-indigo-600"}),(0,l.jsx)("span",{className:"text-sm text-gray-700",children:t})]},e.id)})}):(0,l.jsx)("p",{className:"text-xs text-gray-400 bg-gray-50 border border-gray-200 rounded-lg px-3 py-2",children:"Select a group first to see students."})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:["Instructions for assistant ",(0,l.jsx)("span",{className:"font-normal text-gray-400",children:"(optional)"})]}),(0,l.jsx)("textarea",{value:i.notes,onChange:e=>d(t=>(0,a.A)((0,a.A)({},t),{},{notes:e.target.value})),placeholder:"Any specific instructions for the assistant\u2026",rows:2,className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-indigo-400"})]})]}),(0,l.jsxs)("div",{className:"flex items-center justify-end gap-3 px-5 py-4 border-t bg-gray-50 rounded-b-2xl",children:[(0,l.jsx)("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm text-gray-600 hover:text-gray-800",children:"Cancel"}),(0,l.jsx)("button",{onClick:A,disabled:N,className:"px-5 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-lg hover:bg-indigo-700 disabled:opacity-50 transition-colors",children:N?"Creating\u2026":"Create Task"})]})]})})}function at(e){var t;let{list:s,onClose:o,onSaved:i}=e;const[d,c]=(0,n.useState)({title:(null===s||void 0===s?void 0:s.title)||"",description:(null===s||void 0===s?void 0:s.description)||""}
1),[x,u]=(0,n.useState)(null!==s&&void 0!==s&&null!==(t=s.items)&&void 0!==t&&t.length?s.items.map(e=>({term:e.term,definition:e.definition||""})):[{term:"",definition:""}]),[m,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)(""),[f,b]=(0,n.useState)(!1),[y,v]=(0,n.useState)(null),j=(0,n.useRef)(null),[N,S]=(0,n.useState)(!0),[w,k]=(0,n.useState)(""),[A,C]=(0,n.useState)([]);function T(e,t,s){u(n=>{const r=[...n];return r[e]=(0,a.A)((0,a.A)({},r[e]),{},{[t]:s}),r})}async function E(e){e.preventDefault();const t=x.filter(e=>e.term.trim());if(!d.title.trim())return g("Title is required.");p(!0),g("");try{s?await(0,r.n)("/vocab-checks/lists/".concat(s.id),{method:"PUT",body:JSON.stringify({title:d.title.trim(),description:d.description.trim()||void 0})}):await(0,r.n)("/vocab-checks/lists",{method:"POST",body:JSON.stringify({title:d.title.trim(),description:d.description.trim()||void 0,alsoAddToSrs:N,assignToGroupId:N&&w?w:void 0,items:t.map(e=>({term:e.term.trim(),definition:e.definition.trim()||void 0}))})}),i()}catch(n){g(n.message||"Failed to save list.")}finally{p(!1)}}return(0,n.useEffect)(()=>{(0,r.n)("/groups?limit=200").then(e=>e.json()).then(e=>{const t=e.data;C(Array.isArray(t)?t:(null===t||void 0===t?void 0:t.groups)||[])}).catch(()=>{})},[]),(0,l.jsx)("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-end sm:items-center justify-center p-0 sm:p-4",children:(0,l.jsxs)("div",{className:"bg-white w-full sm:max-w-2xl sm:rounded-2xl shadow-2xl max-h-screen sm:max-h-[90vh] flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b",children:[(0,l.jsx)("h2",{className:"text-lg font-bold text-gray-900",children:s?"Edit Vocabulary List":"New Vocabulary List"}),(0,l.jsx)("button",{onClick:o,className:"text-gray-400 hover:text-gray-600 text-2xl leading-none",children:"\xd7"})]}),(0,l.jsxs)("form",{onSubmit:E,className:"overflow-y-auto flex-1 px-5 py-4 space-y-4",children:[h&&(0,l.jsx)("div",{className:"px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:h}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:"List Title *"}),(0,l.jsx)("input",{type:"text",value:d.title,onChange:e=>c(t=>(0,a.A)((0,a.A)({},t),{},{title:e.target.value})),placeholder:"e.g. Unit 5 Vocabulary",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:["Description ",(0,l.jsx)("span",{className:"font-normal text-gray-400",children:"(optional)"})]}),(0,l.jsx)("input",{type:"text",value:d.description,onChange:e=>c(t=>(0,a.A)((0,a.A)({},t),{},{description:e.target.value})),placeholder:"e.g. Cutting Edge Upper-Intermediate, p.62",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("label",{className:"text-xs font-semibold text-gray-600",children:["Words ",(0,l.jsxs)("span",{className:"font-normal text-gray-400",children:["(",x.filter(e=>e.term.trim()).length," terms)"]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("input",{type:"file",ref:j,accept:".xlsx,.xls,.pdf",onChange:async function(e){var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];if(s){e.target.value="",b(!0),g("");try{const e=new FormData;e.append("file",s);const t=await(0,r.n)("/vocab-checks/lists/parse",{method:"POST",body:e}),n=(await t.json()).data||[];v(Array.isArray(n)?n:[])}catch(n){g(n.message||"Failed to parse file.")}finally{b(!1)}}},className:"hidden"}),(0,l.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.click()},disabled:f,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-indigo-700 bg-indigo-50 border border-indigo-200 rounded-lg hover:bg-indigo-100 disabled:opacity-50 transition-colors",children:f?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Parsing\u2026"]}):"Import Excel / PDF"})]})]}),y&&(0,l.jsxs)("div",{className:"mb-3 p-3 bg-indigo-50 border border-indigo-200 rounded-xl",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("p",{className:"text-xs font-semibold text-indigo-800",children:[y.length," word",1!==y.length?"s":""," extracted \u2014 review below"]}),(0,l.jsx)("button",{type:"button",onClick:()=>v(null),className:"text-xs text-gray-400 hover:text-gray-600",children:"Dismiss"})]}),(0,l.jsx)("div",{className:"max-h-36 overflow-y-auto space-y-1 mb-3",children:y.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,l.jsx)("span",{className:"font-semibold text-indigo-900",children:e.term}),e.definition&&(0,l.jsxs)("span",{className:"text-indigo-600 truncate",children:["\u2014 ",e.definition]})]},t))}),(0,l.jsxs)("button",{type:"button",onClick:function(){if(!y)return;const e=x.filter(e=>e.term.trim());u([...e,...y.map(e=>({term:e.term,definition:e.definition||""}))]),v(null)},className:"w-full py-1.5 bg-indigo-600 text-white text-xs font-semibold rounded-lg hover:bg-indigo-700",children:["Add ",y.length," word",1!==y.length?"s":""," to list"]})]}),(0,l.jsx)("div",{className:"space-y-2 max-h-64 overflow-y-auto pr-1",children:x.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("input",{type:"text",value:e.term,onChange:e=>T(t,"term",e.target.value),placeholder:"Term",className:"flex-1 border border-gray-300 rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-indigo-400"}),(0,l.jsx)("input",{type:"text",value:e.definition,onChange:e=>T(t,"definition",e.target.value),placeholder:"Definition (optional)",className:"flex-1 border border-gray-300 rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-indigo-400"}),(0,l.jsx)("button",{type:"button",onClick:()=>function(e){u(t=>t.filter((t,s)=>s!==e))}(t),disabled:1===x.length,className:"text-gray-300 hover:text-red-400 disabled:opacity-30 transition-colors",children:(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},t))}),(0,l.jsx)("button",{type:"button",onClick:function(){u(e=>[...e,{term:"",definition:""}])},className:"mt-2 text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:"+ Add word"})]}),!s&&(0,l.jsxs)("div",{className:"space-y-3 pt-1",children:[(0,l.jsxs)("label",{className:"flex items-center gap-3 cursor-pointer select-none",children:[(0,l.jsxs)("div",{className:"relative shrink-0",children:[(0,l.jsx)("input",{type:"checkbox",className:"sr-only",checked:N,onChange:e=>S(e.target.checked)}),(0,l.jsx)("div",{className:"w-10 h-5 rounded-full transition-colors ".concat(N?"bg-indigo-600":"bg-gray-300")}),(0,l.jsx)("div",{className:"absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ".concat(N?"translate-x-5":"")})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-medium text-gray-700",children:"Add to SRS bank"}),(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Words appear in daily Telegram drills and flashcard game"})]})]}),N&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-xs font-semibold text-gray-600 mb-1",children:["Auto-assign to group ",(0,l.jsx)("span",{className:"font-normal text-gray-400",children:"(optional)"})]}),(0,l.jsxs)("select",{className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-400",value:w,onChange:e=>k(e.target.value),children:[(0,l.jsx)("option",{value:"",children:"Don't assign to students yet"}),A.map(e=>(0,l.jsxs)("option",{value:e.id,children:[e.name,e.groupCode?" (".concat(e.groupCode,")"):""]},e.id))]}),w&&(0,l.jsx)("p",{className:"text-xs text-indigo-600 mt-1",children:"All active students in this group will get these words in their daily SRS drills immediately."})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center justify-end gap-3 px-5 py-4 border-t bg-gray-50 rounded-b-2xl",children:[(0,l.jsx)("button",{type:"button",onClick:o,className:"px-4 py-2 text-sm text-gray-600 hover:text-gray-800",children:"Cancel"}),(0,l.jsx)("button",{onClick:E,disabled:m,className:"px-5 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-lg hover:bg-indigo-700 disabled:opacity-50",children:m?"Saving\u2026":s?"Save Changes":"Create List"})]})]})})}
1function lt(){const[e,t]=(0,n.useState)([]),[s,o]=(0,n.useState)(!0),[i,d]=(0,n.useState)(""),[c,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(null),[p,h]=(0,n.useState)(null),[g,f]=(0,n.useState)({}),[b,y]=(0,n.useState)(null),v=(0,n.useCallback)(async()=>{o(!0),d("");try{const e=await(0,r.n)("/vocab-checks/lists"),s=e.data||e||[];t(Array.isArray(s)?s:[])}catch(e){d("Failed to load vocabulary lists.")}finally{o(!1)}},[]);return(0,n.useEffect)(()=>{v()},[v]),s?(0,l.jsx)("div",{className:"space-y-3",children:[1,2,3].map(e=>(0,l.jsx)("div",{className:"bg-white rounded-xl border h-16 animate-pulse"},e))}):(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("p",{className:"text-sm text-gray-500",children:[e.length," vocabulary list",1!==e.length?"s":""]}),(0,l.jsxs)("button",{onClick:()=>{m(null),x(!0)},className:"flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-xl hover:bg-indigo-700 transition-colors shadow-sm",children:[(0,l.jsx)("span",{className:"text-base leading-none",children:"+"})," New List"]})]}),i&&(0,l.jsx)("p",{className:"text-sm text-red-600 bg-red-50 px-3 py-2 rounded-lg",children:i}),0===e.length?(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 text-center py-14 text-gray-400",children:[(0,l.jsx)("svg",{className:"w-10 h-10 mx-auto mb-3 text-gray-200",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),(0,l.jsx)("p",{className:"text-sm",children:"No vocabulary lists yet."}),(0,l.jsx)("button",{onClick:()=>{m(null),x(!0)},className:"mt-4 px-5 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-xl hover:bg-indigo-700",children:"Create first list"})]}):(0,l.jsx)("div",{className:"space-y-3",children:e.map(e=>{var s,n,o;const i=p===e.id,d=g[e.id];return(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsx)("div",{className:"p-4 cursor-pointer select-none",onClick:()=>async function(e){if(p!==e){if(h(e),!g[e])try{const t=await(0,r.n)("/vocab-checks/lists/".concat(e));f(s=>(0,a.A)((0,a.A)({},s),{},{[e]:t.data||t}))}catch(t){}}else h(null)}(e.id),children:(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("h3",{className:"font-semibold text-gray-800",children:e.title}),(0,l.jsxs)("div",{className:"flex items-center gap-3 mt-0.5 text-xs text-gray-500 flex-wrap",children:[(0,l.jsxs)("span",{className:"font-medium text-indigo-600",children:[null!==(s=null===(n=e._count)||void 0===n?void 0:n.items)&&void 0!==s?s:0," words"]}),e.description&&(0,l.jsx)("span",{className:"truncate",children:e.description}),e.createdBy&&(0,l.jsxs)("span",{children:["by ",e.createdBy.firstName," ",e.createdBy.lastName]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,l.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),function(e){g[e.id]?(m(g[e.id]),x(!0)):(0,r.n)("/vocab-checks/lists/".concat(e.id)).then(t=>{const s=t.data||t;f(t=>(0,a.A)((0,a.A)({},t),{},{[e.id]:s})),m(s),x(!0)}).catch(()=>{m(e),x(!0)})}(e)},className:"text-xs text-gray-500 hover:text-indigo-600 px-2 py-1 rounded-md hover:bg-indigo-50 transition-colors",children:"Edit"}),(0,l.jsx)("button",{type:"button",onClick:s=>{s.stopPropagation(),async function(e){if(window.confirm('Delete "'.concat(e.title,'"? This cannot be undone.'))){y(e.id);try{await(0,r.n)("/vocab-checks/lists/".concat(e.id),{method:"DELETE"}),t(t=>t.filter(t=>t.id!==e.id)),p===e.id&&h(null)}catch(s){alert(s.message||"Failed to delete.")}finally{y(null)}}}(e)},disabled:b===e.id,className:"text-xs text-gray-400 hover:text-red-600 px-2 py-1 rounded-md hover:bg-red-50 disabled:opacity-50 transition-colors",children:b===e.id?"\u2026":"Delete"}),(0,l.jsx)("svg",{className:"w-4 h-4 text-gray-400 transition-transform ml-1 ".concat(i?"rotate-180":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]})}),i&&(0,l.jsx)("div",{className:"border-t px-4 pb-4 pt-3",children:d?null!==(o=d.items)&&void 0!==o&&o.length?(0,l.jsx)("div",{className:"flex flex-wrap gap-2",children:d.items.map(e=>(0,l.jsxs)("div",{className:"px-3 py-1.5 bg-indigo-50 border border-indigo-100 rounded-lg text-sm",children:[(0,l.jsx)("span",{className:"font-semibold text-indigo-800",children:e.term}),e.definition&&(0,l.jsxs)("span",{className:"text-indigo-500 ml-1",children:["\u2014 ",e.definition]})]},e.id))}):(0,l.jsx)("p",{className:"text-xs text-gray-400 text-center py-3",children:"No words in this list yet."}):(0,l.jsx)("div",{className:"text-center text-xs text-gray-400 py-3",children:"Loading\u2026"})})]},e.id)})}),c&&(0,l.jsx)(at,{list:u,onClose:()=>{x(!1),m(null)},onSaved:()=>{x(!1),m(null),f({}),v()}})]})}function ot(){const e=function(){try{return JSON.parse(localStorage.getItem("user")||"{}")}catch(e){return{}}}
1(),[t,s]=(0,n.useState)("tasks"),[a,o]=(0,n.useState)([]),[i,d]=(0,n.useState)(!0),[c,x]=(0,n.useState)(""),[u,m]=(0,n.useState)("ALL"),[p,h]=(0,n.useState)(!1),g=(0,n.useCallback)(async()=>{d(!0),x("");try{var e;const t=await(0,r.n)("/vocab-checks/tasks"),s=(null===(e=t.data)||void 0===e?void 0:e.tasks)||t.data||t.tasks||t||[];o(Array.isArray(s)?s:[])}catch(t){x("Failed to load vocabulary check tasks.")}finally{d(!1)}},[]);(0,n.useEffect)(()=>{g()},[g]);const f=e.id||e.userId,b=a.filter(e=>{var t;return e.assignedToId===f||(null===(t=e.assignedTo)||void 0===t?void 0:t.id)===f}),y=a.filter(e=>{var t;return e.createdById===f||(null===(t=e.createdBy)||void 0===t?void 0:t.id)===f}),v=new Set(b.map(e=>e.id)),j=y.filter(e=>!v.has(e.id));function N(e){return"ALL"===u?e:e.filter(e=>e.status===u)}const S=N(b),w=N(j),k=b.length>0,A=j.length>0,C=S.filter(e=>!["COMPLETED","CANCELLED"].includes(e.status)),T=S.filter(e=>["COMPLETED","CANCELLED"].includes(e.status));return(0,l.jsxs)("div",{className:"min-h-screen bg-gray-50",children:[(0,l.jsxs)("div",{className:"max-w-3xl mx-auto px-4 py-6",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between mb-4 gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h1",{className:"text-2xl font-bold text-gray-900",children:"Vocabulary Checks"}),e.firstName&&(0,l.jsxs)("p",{className:"text-sm text-gray-500 mt-0.5",children:["Welcome, ",e.firstName,"."]})]}),"tasks"===t&&(0,l.jsxs)("button",{onClick:()=>h(!0),className:"shrink-0 flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-xl hover:bg-indigo-700 transition-colors shadow-sm",children:[(0,l.jsx)("span",{className:"text-base leading-none",children:"+"})," New Task"]})]}),(0,l.jsx)("div",{className:"flex gap-1 mb-5 bg-gray-100 p-1 rounded-xl w-fit",children:[{id:"tasks",label:"Check Tasks"},{id:"lists",label:"Vocabulary Lists"}].map(e=>(0,l.jsx)("button",{onClick:()=>s(e.id),className:"px-4 py-2 rounded-lg text-sm font-semibold transition-colors ".concat(t===e.id?"bg-white text-indigo-700 shadow-sm":"text-gray-500 hover:text-gray-700"),children:e.label},e.id))}),"lists"===t&&(0,l.jsx)(lt,{}),"tasks"===t&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex flex-wrap gap-2 mb-6",children:["ALL","DRAFT","PUBLISHED","IN_PROGRESS","COMPLETED","CANCELLED"].map(e=>(0,l.jsx)("button",{onClick:()=>m(e),className:"px-3 py-1 rounded-full text-xs font-semibold border transition-colors ".concat(u===e?"bg-indigo-600 text-white border-indigo-600":"bg-white text-gray-600 border-gray-200 hover:border-indigo-300"),children:"ALL"===e?"All":e},e))}),c&&(0,l.jsxs)("div",{className:"mb-5 px-4 py-3 bg-red-50 border border-red-200 rounded-xl text-sm text-red-700",children:[c,(0,l.jsx)("button",{onClick:g,className:"ml-2 underline hover:no-underline",children:"Retry"})]}),i?(0,l.jsx)("div",{className:"space-y-3",children:[1,2,3].map(e=>(0,l.jsx)("div",{className:"bg-white rounded-xl border border-gray-100 h-20 animate-pulse"},e))}):k||A?(0,l.jsxs)("div",{className:"space-y-8",children:[k&&(0,l.jsxs)("section",{children:[(0,l.jsx)(nt,{title:"My Check Sessions",count:S.length}),0===S.length?(0,l.jsx)("p",{className:"text-sm text-gray-400 py-4",children:"No tasks match the current filter."}):(0,l.jsxs)("div",{className:"space-y-3",children:[C.map(e=>(0,l.jsx)(tt,{task:e,onCompleted:g},e.id)),T.length>0&&(0,l.jsx)(it,{tasks:T})]})]}),A&&(0,l.jsxs)("section",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("h2",{className:"text-base font-semibold text-gray-800",children:"Tasks I Created"}),(0,l.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 text-xs font-medium rounded-full",children:w.length})]}),(0,l.jsx)("button",{onClick:()=>h(!0),className:"text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:"+ New Task"})]}),0===w.length?(0,l.jsx)("p",{className:"text-sm text-gray-400 py-4",children:"No tasks match the current filter."}):(0,l.jsx)("div",{className:"space-y-3",children:w.map(e=>(0,l.jsx)(st,{task:e,onRefresh:g},e.id))})]})]}):(0,l.jsx)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm",children:(0,l.jsxs)("div",{className:"text-center py-14 text-gray-400",children:[(0,l.jsx)("svg",{className:"w-12 h-12 mx-auto mb-3 text-gray-200",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),(0,l.jsx)("p",{className:"text-sm",children:"No vocabulary check tasks yet."}),(0,l.jsx)("button",{onClick:()=>h(!0),className:"mt-4 px-5 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-xl hover:bg-indigo-700 transition-colors",children:"Create your first task"})]})})]})]}),p&&(0,l.jsx)(rt,{onClose:()=>h(!1),onCreated:()=>{h(!1),g()}})]})}function it(e){let{tasks:t}=e;
1const[s,r]=(0,n.useState)(!1);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{onClick:()=>r(e=>!e),className:"flex items-center gap-2 text-sm text-gray-500 hover:text-gray-700 py-1",children:[(0,l.jsx)("svg",{className:"w-4 h-4 transition-transform ".concat(s?"rotate-180":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),s?"Hide":"Show"," ",t.length," completed/cancelled session",1!==t.length?"s":""]}),s&&(0,l.jsx)("div",{className:"space-y-3 mt-2",children:t.map(e=>(0,l.jsx)(tt,{task:e,onCompleted:()=>{}},e.id))})]})}function dt(e){if(!e)return"Unknown";const t=e.user||e;return"".concat(t.firstName||""," ").concat(t.lastName||"").trim()||"Unknown"}function ct(e){var t;const s=null===e||void 0===e||null===(t=e.student)||void 0===t?void 0:t.user;return s?"".concat(s.firstName," ").concat(s.lastName).trim():(null===e||void 0===e?void 0:e.studentId)||"Unknown"}const xt=[{status:"READY",label:"Ready",activeClass:"bg-green-500 text-white border-green-500 shadow-sm",hoverClass:"hover:bg-green-50 hover:border-green-400 hover:text-green-700",rowClass:"border-green-200 bg-green-50/40"},{status:"TRIED_BUT_DIDNT_PASS",label:"Tried",activeClass:"bg-orange-500 text-white border-orange-500 shadow-sm",hoverClass:"hover:bg-orange-50 hover:border-orange-400 hover:text-orange-700",rowClass:"border-orange-200 bg-orange-50/40"},{status:"ABSENT",label:"Absent",activeClass:"bg-red-500 text-white border-red-500 shadow-sm",hoverClass:"hover:bg-red-50 hover:border-red-400 hover:text-red-700",rowClass:"border-red-200 bg-red-50/40"}],ut={READY:"bg-green-100 text-green-700",TRIED_BUT_DIDNT_PASS:"bg-orange-100 text-orange-700",ABSENT:"bg-red-100 text-red-700",PENDING:"bg-gray-100 text-gray-500"};function mt(e){var t,s,a;let{student:o,existingMark:i,onMarked:d}=e;
1const c=(new Date).toISOString().slice(0,10),[x,u]=(0,n.useState)(!1),[m,p]=(0,n.useState)((null===i||void 0===i?void 0:i.status)||null),[h,g]=(0,n.useState)((null===i||void 0===i?void 0:i.notes)||""),[f,b]=(0,n.useState)((null===i||void 0===i?void 0:i.notes)||""),[y,v]=(0,n.useState)(!(null===i||void 0===i||!i.notes)),[j,N]=(0,n.useState)((null===i||void 0===i?void 0:i.topicsAsked)||""),[S,w]=(0,n.useState)((null===i||void 0===i?void 0:i.topicsAsked)||""),[k,A]=(0,n.useState)(!(null===i||void 0===i||!i.topicsAsked)),[C,T]=(0,n.useState)(""),[E,I]=(0,n.useState)(c);(0,n.useEffect)(()=>{p((null===i||void 0===i?void 0:i.status)||null),g((null===i||void 0===i?void 0:i.notes)||""),b((null===i||void 0===i?void 0:i.notes)||""),v(!(null===i||void 0===i||!i.notes)),N((null===i||void 0===i?void 0:i.topicsAsked)||""),w((null===i||void 0===i?void 0:i.topicsAsked)||""),A(!(null===i||void 0===i||!i.topicsAsked))},[null===i||void 0===i?void 0:i.status,null===i||void 0===i?void 0:i.notes,null===i||void 0===i?void 0:i.topicsAsked]);const R=null===(t=o.enrollments)||void 0===t||null===(s=t[0])||void 0===s||null===(a=s.group)||void 0===a?void 0:a.name;async function D(){if(!x&&m){u(!0),T("");try{const e=await(0,r.n)("/readiness-checks/quick-mark",{method:"PUT",body:JSON.stringify({studentId:o.id,status:m,notes:h||void 0,topicsAsked:j||void 0,vocabDate:E})});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.message||"Failed to save")}b(h),w(j),d&&d(o.id,{status:m,notes:h||null,topicsAsked:j||null})}catch(e){g(f),N(S),T(e.message||"Failed to save.")}finally{u(!1)}}}const L=xt.find(e=>e.status===m),z=L?L.rowClass:"border-gray-200 bg-white",W=j!==S,B=h!==f||W;return(0,l.jsxs)("div",{className:"rounded-xl border p-3 transition-colors ".concat(z),children:[(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("p",{className:"font-medium text-gray-800 truncate",children:dt(o)}),R&&(0,l.jsx)("p",{className:"text-xs text-blue-600 mt-0.5",children:R}),(0,l.jsxs)("div",{className:"flex items-center gap-1.5 mt-1",children:[(0,l.jsx)("label",{className:"text-xs text-gray-500 shrink-0",children:"Vocab date:"}),(0,l.jsx)("input",{type:"date",value:E,max:c,onChange:e=>I(e.target.value),className:"text-xs border border-gray-200 rounded px-2 py-0.5 focus:outline-none focus:ring-1 focus:ring-blue-300"})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 flex-wrap",children:[xt.map(e=>(0,l.jsx)("button",{onClick:()=>async function(e){if(x)return;const t=m;p(e),u(!0),T("");try{const t=await(0,r.n)("/readiness-checks/quick-mark",{method:"PUT",body:JSON.stringify({studentId:o.id,status:e,notes:h||void 0,topicsAsked:j||void 0,vocabDate:E})});if(!t.ok){const e=await t.json().catch(()=>({}));throw new Error(e.message||"Failed to save")}b(h),w(j),I(c),d&&d(o.id,{status:e,notes:h||null,topicsAsked:j||null})}catch(s){p(t),T(s.message||"Failed to save. Try again.")}finally{u(!1)}}(e.status),disabled:x,title:"TRIED_BUT_DIDNT_PASS"===e.status?"Tried but did not pass":e.label,className:"px-3 py-1.5 rounded-lg border text-sm font-medium transition-all active:scale-95 disabled:opacity-60 ".concat(m===e.status?e.activeClass:"bg-white text-gray-600 border-gray-300 ".concat(e.hoverClass)),children:e.label},e.status)),(0,l.jsx)("button",{onClick:()=>A(e=>!e),title:k?"Hide topics":"Add topics asked",className:"px-2 py-1.5 rounded-lg border text-xs font-medium transition-colors ".concat(S?"border-purple-200 bg-purple-50 text-purple-600 hover:bg-purple-100":"border-gray-200 bg-white text-gray-400 hover:text-gray-600 hover:bg-gray-50"),children:"Topics"}),(0,l.jsx)("button",{onClick:()=>v(e=>!e),title:y?"Hide comment":"Add comment",className:"p-1.5 rounded-lg border transition-colors ".concat(f?"border-blue-200 bg-blue-50 text-blue-500 hover:bg-blue-100":"border-gray-200 bg-white text-gray-400 hover:text-gray-600 hover:bg-gray-50"),children:(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h6m-6 4h4M5 20l-2 2V4a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H5z"})})})]})]}),C&&(0,l.jsx)("p",{className:"text-xs text-red-600 bg-red-50 rounded-lg px-2 py-1 mt-2",children:C}),k&&(0,l.jsxs)("div",{className:"mt-2",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-purple-600 mb-1 block",children:"Topics asked"}),(0,l.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,l.jsx)("textarea",{value:j,onChange:e=>N(e.target.value),placeholder:"e.g. Unit 5 vocab, past simple, conditionals\u2026",rows:2,className:"flex-1 text-sm border border-purple-200 rounded-lg px-2.5 py-1.5 resize-none focus:outline-none focus:ring-2 focus:ring-purple-300 bg-white"}),W&&(0,l.jsx)("button",{onClick:D,disabled:x||!m,className:"shrink-0 px-3 py-1.5 text-xs font-medium bg-purple-500 text-white rounded-lg hover:bg-purple-600 disabled:opacity-50 transition-colors",children:x?"\u2026":"Save"})]})]}),y&&(0,l.jsxs)("div",{className:"mt-2 flex gap-2 items-end",children:[(0,l.jsx)("textarea",{value:h,onChange:e=>g(e.target.value),placeholder:"Optional comment\u2026",rows:2,className:"flex-1 text-sm border border-gray-200 rounded-lg px-2.5 py-1.5 resize-none focus:outline-none focus:ring-2 focus:ring-blue-300 bg-white"}),B&&(0,l.jsx)("button",{onClick:D,disabled:x||!m,className:"shrink-0 px-3 py-1.5 text-xs font-medium bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 transition-colors",children:x?"\u2026":"Save"})]}),x&&(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Saving\u2026"})]})}function pt(e){let{markedMap:t,onMarked:s}=e;
1const[a,o]=(0,n.useState)(""),[i,d]=(0,n.useState)([]),[c,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(""),p=(0,n.useRef)(null),h=(0,n.useRef)("");return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsxs)("div",{className:"px-4 pt-4 pb-3",children:[(0,l.jsx)("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2",children:"Mark Students"}),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-4.35-4.35M17 11A6 6 0 1 1 5 11a6 6 0 0 1 12 0z"})}),(0,l.jsx)("input",{type:"text",value:a,onChange:function(e){const t=e.target.value;if(o(t),clearTimeout(p.current),!t.trim())return h.current="",d([]),x(!1),void m("");p.current=setTimeout(()=>async function(e){if(h.current=e,!e.trim())return d([]),void x(!1);x(!0),m("");try{const t=await(0,r.n)("/students?search=".concat(encodeURIComponent(e.trim()),"&limit=20¢erFilter=true"));if(h.current!==e)return;if(!t.ok){const e=await t.json().catch(()=>({}));return m(e.message||"Search failed (".concat(t.status,")")),void d([])}const s=await t.json(),n=s.data||s,a=(Array.isArray(n)?n:n.students||[]).filter(e=>(e.enrollments||[]).length>0);d(a)}catch(t){h.current===e&&(m(t.message||"Network error \u2014 please try again."),d([]))}finally{h.current===e&&x(!1)}}(t),300)},placeholder:"Search student by name to mark\u2026",className:"w-full pl-9 pr-8 py-2.5 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-orange-400 bg-gray-50"}),c&&(0,l.jsx)("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 text-xs",children:"\u2026"}),a&&!c&&(0,l.jsx)("button",{onClick:()=>{o(""),d([]),h.current="",m("")},className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&(0,l.jsx)("p",{className:"text-xs text-red-600 mt-1.5",children:u})]}),a.trim()&&!c&&!u&&0===i.length&&(0,l.jsxs)("div",{className:"px-4 pb-4 text-sm text-gray-400 text-center",children:['No students found for "',a.trim(),'".']}),i.length>0&&(0,l.jsx)("div",{className:"border-t border-gray-100 px-4 pb-3 pt-2 space-y-2 max-h-[28rem] overflow-y-auto",children:i.map(e=>(0,l.jsx)(mt,{student:e,existingMark:t[e.id],onMarked:s},e.id))})]})}function ht(e){const t=ct(e);return e.notes?"\u2022 ".concat(t," \u2014 ").concat(e.notes):"\u2022 ".concat(t)}function gt(e,t){var s;const n=(null===(s=e.group)||void 0===s?void 0:s.name)||"\u0413\u0440\u0443\u043f\u043f\u0430",r=new Date(e.createdAt).toLocaleDateString("ru-RU",{day:"numeric",month:"long",year:"numeric"}),a=t.filter(e=>"READY"===e.status),l=t.filter(e=>"TRIED_BUT_DIDNT_PASS"===e.status),o=t.filter(e=>"ABSENT"===e.status||"PENDING"===e.status);let i="\ud83d\udccb *\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u043d\u043e\u0439 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 \u2014 ".concat(n,"*\n\ud83d\udcc5 ").concat(r,"\n\n");return i+="\u2705 \u0413\u043e\u0442\u043e\u0432\u044b: ".concat(a.length,"\n"),i+="\ud83d\udd04 \u041f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438: ".concat(l.length,"\n"),i+="\u274c \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442: ".concat(o.length,"\n"),a.length>0&&(i+="\n\u2705 *\u0413\u043e\u0442\u043e\u0432\u044b:*\n",a.forEach(e=>{i+="".concat(ht(e),"\n")})),l.length>0&&(i+="\n\ud83d\udd04 *\u041f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438, \u043d\u043e \u043d\u0435 \u0441\u0434\u0430\u043b\u0438:*\n",l.forEach(e=>{i+="".concat(ht(e),"\n")})),o.length>0&&(i+="\n\u274c *\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442:*\n",o.forEach(e=>{i+="".concat(ht(e),"\n")})),i.trim()}function ft(e){var t;let{check:s,onClose:a}=e;
1const[o,i]=(0,n.useState)(null),[d,c]=(0,n.useState)(!0),[x,u]=(0,n.useState)(""),[m,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)(!1),[f,b]=(0,n.useState)(0),[y,v]=(0,n.useState)("");(0,n.useEffect)(()=>{(0,r.n)("/readiness-checks/".concat(s.id)).then(e=>e.json()).then(e=>{const t=e.data||e;i(t),u(gt(s,t.enrollments||[]))}).catch(()=>v("Failed to load check details.")).finally(()=>c(!1))},[s.id]);const j=(null===o||void 0===o?void 0:o.enrollments)||[];return(0,l.jsx)("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-end sm:items-center justify-center p-0 sm:p-4",children:(0,l.jsxs)("div",{className:"bg-white w-full sm:max-w-lg sm:rounded-2xl shadow-2xl max-h-screen sm:max-h-[90vh] flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-lg font-bold text-gray-900",children:"Send to Telegram"}),(0,l.jsx)("p",{className:"text-xs text-gray-500 mt-0.5",children:(null===(t=s.group)||void 0===t?void 0:t.name)||"Group"})]}),(0,l.jsx)("button",{onClick:a,className:"text-gray-400 hover:text-gray-600 text-2xl leading-none",children:"\xd7"})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[y&&(0,l.jsx)("div",{className:"px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:y}),h?(0,l.jsxs)("div",{className:"text-center py-10",children:[(0,l.jsx)("div",{className:"text-5xl mb-3",children:"\u2705"}),(0,l.jsx)("p",{className:"font-semibold text-gray-800 text-lg",children:"Message sent!"}),(0,l.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Delivered to ",f," Telegram group",1!==f?"s":"","."]}),(0,l.jsx)("button",{onClick:a,className:"mt-5 px-5 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-lg hover:bg-gray-200",children:"Close"})]}):d?(0,l.jsx)("div",{className:"py-10 text-center text-gray-400 text-sm",children:"Loading\u2026"}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2",children:"Quick fill"}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{type:"button",onClick:()=>u(function(e,t){var s;const n=t.filter(e=>"ABSENT"===e.status||"PENDING"===e.status),r=(null===(s=e.group)||void 0===s?void 0:s.name)||"\u0413\u0440\u0443\u043f\u043f\u0430",a=new Date(e.createdAt).toLocaleDateString("ru-RU",{day:"numeric",month:"long",year:"numeric"});let l="\ud83d\udccb *\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u043d\u043e\u0439 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 \u2014 ".concat(r,"*\n\ud83d\udcc5 ").concat(a,"\n\n");return n.length>0?(l+="\u274c *\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 (".concat(n.length,"):*\n"),n.forEach(e=>{l+="".concat(ht(e),"\n")})):l+="\u2705 \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043d\u0435\u0442 \u2014 \u0432\u0441\u0435 \u043f\u0440\u0438\u0448\u043b\u0438!",l.trim()}(s,j)),className:"px-3 py-1.5 text-xs bg-red-50 text-red-700 border border-red-200 rounded-lg hover:bg-red-100 transition-colors font-medium",children:"\u274c Absent only"}),(0,l.jsx)("button",{type:"button",onClick:()=>u(gt(s,j)),className:"px-3 py-1.5 text-xs bg-blue-50 text-blue-700 border border-blue-200 rounded-lg hover:bg-blue-100 transition-colors font-medium",children:"\ud83d\udcca Full summary"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-gray-600",children:"Message"}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:"Markdown supported"})]}),(0,l.jsx)("textarea",{value:x,onChange:e=>u(e.target.value),rows:11,className:"w-full border border-gray-300 rounded-xl px-3 py-2.5 text-sm font-mono resize-none focus:outline-none focus:ring-2 focus:ring-blue-400"})]})]})]}),!h&&!d&&(0,l.jsxs)("div",{className:"flex items-center justify-end gap-3 px-5 py-4 border-t bg-gray-50 sm:rounded-b-2xl",children:[(0,l.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-sm text-gray-600 hover:text-gray-800",children:"Cancel"}),(0,l.jsx)("button",{onClick:async function(){if(x.trim()){p(!0),v("");try{const e=await(0,r.n)("/telegram/teacher-broadcast",{method:"POST",body:JSON.stringify({message:x.trim(),targetGroupIds:s.groupId?[s.groupId]:"all"})}),t=await e.json();if(0===t.sent)throw new Error(t.message||"No messages sent. Make sure this group is linked to a Telegram group in the Telegram settings.");g(!0),b(t.sent)}catch(e){v(e.message||"Failed to send message.")}finally{p(!1)}}},disabled:m||!x.trim(),className:"px-5 py-2 bg-[#0088cc] text-white text-sm font-semibold rounded-lg hover:bg-[#006da3] disabled:opacity-50 transition-colors flex items-center gap-2",children:m?"Sending\u2026":"\u2708\ufe0f Send to Telegram"})]})]})})}function bt(e){var t,s;let{check:r}=e;
1const[a,o]=(0,n.useState)(!1),i=(r.enrollments||[]).filter(e=>"PENDING"!==e.status),d=i.filter(e=>"READY"===e.status).length,c=i.filter(e=>"TRIED_BUT_DIDNT_PASS"===e.status).length,x=i.filter(e=>"ABSENT"===e.status).length;return 0===i.length?null:(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("h3",{className:"font-semibold text-gray-800",children:(null===(t=r.group)||void 0===t?void 0:t.name)||"Group"}),(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(null===(s=r.group)||void 0===s?void 0:s.groupCode)&&(0,l.jsx)("span",{className:"text-xs text-gray-400",children:r.group.groupCode}),r.vocabDate&&(0,l.jsxs)("span",{className:"text-xs text-purple-600 font-medium",children:["Vocab: ",new Date(r.vocabDate).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,l.jsxs)("div",{className:"flex gap-3 text-sm",children:[(0,l.jsxs)("span",{className:"font-medium text-green-700",children:[d," Ready"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-orange-700",children:[c," Tried"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-red-700",children:[x," Absent"]})]}),(0,l.jsx)("button",{onClick:()=>o(!0),className:"flex items-center gap-1 text-xs text-[#0088cc] hover:text-[#006da3] px-2 py-1 rounded-md hover:bg-blue-50 transition-colors font-medium",children:"\u2708\ufe0f Telegram"})]})]}),(0,l.jsx)("div",{className:"divide-y divide-gray-50",children:i.map(e=>{return(0,l.jsxs)("div",{className:"px-4 py-2",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,l.jsx)("span",{className:"text-sm text-gray-800 flex-1 min-w-0 truncate",children:ct(e)}),e.notes&&(0,l.jsx)("span",{className:"text-xs text-gray-400 truncate max-w-[8rem] hidden sm:block",title:e.notes,children:e.notes}),(0,l.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-semibold shrink-0 ".concat(ut[e.status]||ut.PENDING),children:(t=e.status,"TRIED_BUT_DIDNT_PASS"===t?"Tried":"PENDING"===t?"Pending":t?t.charAt(0)+t.slice(1).toLowerCase():"Pending")})]}),e.topicsAsked&&(0,l.jsxs)("p",{className:"text-xs text-purple-600 mt-0.5 truncate",title:e.topicsAsked,children:["Topics: ",e.topicsAsked]})]},e.id);var t})}),a&&(0,l.jsx)(ft,{check:r,onClose:()=>o(!1)})]})}function yt(e){let{todayChecks:t,loading:s,onRefresh:n}=e;if(s)return(0,l.jsx)("div",{className:"space-y-3",children:[1,2].map(e=>(0,l.jsx)("div",{className:"bg-white rounded-xl border h-24 animate-pulse"},e))});const r=t.filter(e=>(e.enrollments||[]).some(e=>"PENDING"!==e.status)),a=r.reduce((e,t)=>e+(t.enrollments||[]).filter(e=>"PENDING"!==e.status).length,0);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("h2",{className:"text-base font-semibold text-gray-800",children:"Today's Results"}),r.length>0&&(0,l.jsxs)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 text-xs font-medium rounded-full",children:[r.length," group",1!==r.length?"s":""]}),a>0&&(0,l.jsxs)("span",{className:"px-2 py-0.5 bg-orange-100 text-orange-700 text-xs font-medium rounded-full",children:[a," marked"]})]}),(0,l.jsxs)("button",{onClick:n,className:"text-xs text-gray-500 hover:text-gray-700 flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100",children:[(0,l.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Refresh"]})]}),0===r.length?(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm text-center py-10 text-gray-400",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udccb"}),(0,l.jsx)("p",{className:"text-sm",children:"No marks recorded yet today."}),(0,l.jsx)("p",{className:"text-xs mt-1",children:"Use the search above to start marking students."})]}):(0,l.jsx)("div",{className:"space-y-4",children:r.map(e=>(0,l.jsx)(bt,{check:e},e.id))})]})}const vt=[{key:"READY",label:"Ready",icon:"\u2705",color:"#059669",activeBg:"bg-green-500",activeText:"text-white",inactiveText:"text-gray-500",border:"border-green-500"},{key:"TRIED_BUT_DIDNT_PASS",label:"Not Ready",icon:"\ud83d\udd04",color:"#ea580c",activeBg:"bg-orange-500",activeText:"text-white",inactiveText:"text-gray-500",border:"border-orange-500"},{key:"ABSENT",label:"Absent",icon:"\u274c",color:"#dc2626",activeBg:"bg-red-500",activeText:"text-white",inactiveText:"text-gray-500",border:"border-red-500"}];function jt(e){let{group:t}=e;
1const[s,r]=(0,n.useState)("READY"),a={READY:t.students.filter(e=>"READY"===e.lastStatus),TRIED_BUT_DIDNT_PASS:t.students.filter(e=>"TRIED_BUT_DIDNT_PASS"===e.lastStatus),ABSENT:t.students.filter(e=>"ABSENT"===e.lastStatus)},o=t.students.reduce((e,t)=>e+t.ready,0),i=t.students.reduce((e,t)=>e+t.tried,0),d=t.students.reduce((e,t)=>e+t.absent,0);if(o+i+d===0)return null;const c={READY:o,TRIED_BUT_DIDNT_PASS:i,ABSENT:d},x=a[s]||[];return(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("h3",{className:"font-semibold text-gray-800",children:t.groupName}),t.groupCode&&(0,l.jsx)("span",{className:"text-xs text-gray-400",children:t.groupCode})]}),(0,l.jsxs)("div",{className:"flex gap-3 text-sm shrink-0",children:[(0,l.jsxs)("span",{className:"font-medium text-green-700",children:[o," Ready"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-orange-700",children:[i," Tried"]}),(0,l.jsx)("span",{className:"text-gray-300",children:"|"}),(0,l.jsxs)("span",{className:"font-medium text-red-700",children:[d," Absent"]})]})]}),(0,l.jsx)("div",{className:"flex border-b border-gray-100 bg-gray-50/60",children:vt.map(e=>{const t=s===e.key,n=c[e.key];return(0,l.jsxs)("button",{onClick:()=>r(e.key),className:"flex-1 flex items-center justify-center gap-1.5 py-2 px-1 text-xs font-semibold transition-all border-b-2 ".concat(t?"".concat(e.border," ").concat(e.activeText):"border-transparent text-gray-500 hover:text-gray-700"),style:{borderBottomColor:t?e.color:"transparent",color:t?e.color:void 0},children:[(0,l.jsx)("span",{children:e.icon}),(0,l.jsx)("span",{children:e.label}),(0,l.jsx)("span",{className:"inline-flex items-center justify-center rounded-full text-xs font-bold px-1.5 min-w-[1.25rem] h-5",style:{backgroundColor:t?e.color:"#e5e7eb",color:t?"white":"#6b7280"},children:n})]},e.key)})}),0===x.length?(0,l.jsx)("div",{className:"px-4 py-5 text-center text-gray-400 text-sm",children:"No students in this category."}):(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{className:"border-b border-gray-100 bg-gray-50/60",children:[(0,l.jsx)("th",{className:"text-left px-4 py-2 text-xs font-semibold text-gray-400",children:"#"}),(0,l.jsx)("th",{className:"text-left px-3 py-2 text-xs font-semibold text-gray-500",children:"Student"}),(0,l.jsx)("th",{className:"text-center px-3 py-2 text-xs font-semibold text-green-700",children:"Ready"}),(0,l.jsx)("th",{className:"text-center px-3 py-2 text-xs font-semibold text-orange-700",children:"Tried"}),(0,l.jsx)("th",{className:"text-center px-3 py-2 text-xs font-semibold text-red-700",children:"Absent"}),(0,l.jsx)("th",{className:"text-right px-4 py-2 text-xs font-semibold text-gray-400 whitespace-nowrap",children:"Last checked"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-50",children:x.map((e,t)=>{const s=e.ready+e.tried+e.absent,n=s>0?Math.round(e.ready/s*100):0,r=e.lastCheckedAt?new Date(e.lastCheckedAt).toLocaleDateString("en-GB",{day:"2-digit",month:"short"}):"\u2014";return(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50/40",children:[(0,l.jsx)("td",{className:"px-4 py-2 text-xs text-gray-400 font-semibold",children:t+1}),(0,l.jsxs)("td",{className:"px-3 py-2 font-medium text-gray-800",children:[e.name,s>1&&(0,l.jsxs)("span",{className:"ml-1.5 text-xs text-gray-400",children:[n,"% ready"]})]}),(0,l.jsx)("td",{className:"text-center px-3 py-2 font-bold",style:{color:e.ready>0?"#059669":"#d1d5db"},children:e.ready||"\u2014"}),(0,l.jsx)("td",{className:"text-center px-3 py-2 font-bold",style:{color:e.tried>0?"#c2410c":"#d1d5db"},children:e.tried||"\u2014"}),(0,l.jsx)("td",{className:"text-center px-3 py-2 font-bold",style:{color:e.absent>0?"#dc2626":"#d1d5db"},children:e.absent||"\u2014"}),(0,l.jsx)("td",{className:"text-right px-4 py-2 text-gray-500 text-xs whitespace-nowrap",children:r})]},e.studentId)})})]})})]})}const Nt=[{key:"daily",label:"Today"},{key:"weekly",label:"This Week"},{key:"monthly",label:"This Month"},{key:"custom",label:"By Date"},{key:"range",label:"Date Range"}],St=(new Date).toISOString().slice(0,10),wt=new Date((new Date).getFullYear(),(new Date).getMonth(),1).toISOString().slice(0,10);function kt(e){return new Date(e+"T12:00:00").toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"})}function At(e){return new Date(e+"T12:00:00").toLocaleDateString("en-GB",{weekday:"short",day:"2-digit",month:"short"})}const Ct={READY:{bg:"#d1fae5",color:"#059669",label:"Ready"},TRIED_BUT_DIDNT_PASS:{bg:"#fff7ed",color:"#c2410c",label:"Not Ready"},ABSENT:{bg:"#fee2e2",color:"#dc2626",label:"Absent"}};function Tt(e){var t,s,n,r,a;let{data:o,fromDate:i,toDate:d}=e;if(!o||0===(null!==(t=null===(s=o.groups)||void 0===s?void 0:s.length)&&void 0!==t?t:0)||0===(null!==(n=null===(r=o.dates)||void 0===r?void 0:r.length)&&void 0!==n?n:0))return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm text-center py-10 text-gray-400",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udcca"}),(0,l.jsx)("p",{className:"text-sm",children:"No readiness checks in this date range."})]});const c={READY:0,TRIED_BUT_DIDNT_PASS:0,ABSENT:0};for(const l of null!==(x=o.groups)&&void 0!==x?x:[]){var x;for(const e of l.students)for(const t of Object.values(e.byDate))void 0!==c[t]&&c[t]++}return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-4 flex-wrap",children:[(0,l.jsxs)("div",{className:"flex-1 bg-green-50 border border-green-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-green-700",children:c.READY}),(0,l.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"Ready"})]}),(0,l.jsxs)("div",{className:"flex-1 bg-orange-50 border border-orange-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-orange-700",children:c.TRIED_BUT_DIDNT_PASS}),(0,l.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"Not Ready"})]}),(0,l.jsxs)("div",{className:"flex-1 bg-red-50 border border-red-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-red-700",children:c.ABSENT}),(0,l.jsx)("div",{className:"text-xs text-red-600 font-medium",children:"Absent"})]}),(0,l.jsx)("button",{onClick:()=>function(e,t,s){const n={READY:{bg:"#d1fae5",color:"#059669",text:"Ready"},TRIED_BUT_DIDNT_PASS:{bg:"#fff7ed",color:"#c2410c",text:"Not Ready"},ABSENT:{bg:"#fee2e2",color:"#dc2626",text:"Absent"}},r={READY:0,TRIED_BUT_DIDNT_PASS:0,ABSENT:0};for(const i of e.groups)for(const e of i.students)for(const t of Object.values(e.byDate))void 0!==r[t]&&r[t]++;const a=e.groups.map(t=>{const s=e.dates.map(e=>'<th style="padding:5px 7px;text-align:center;border:1px solid #d1d5db;font-size:12px;font-weight:700;white-space:nowrap;background:#f3f4f6">'.concat(At(e),"</th>")).join(""),r=t.students.map((t,s)=>{const r=e.dates.map(e=>{var s;const r=n[t.byDate[e]],a=(null===(s=t.topicsByDate)||void 0===s?void 0:s[e])||"";return'<td style="padding:5px 7px;text-align:center;border:1px solid #e5e7eb;background:'.concat(r?r.bg:"white",";font-size:12px;font-weight:700;color:").concat(r?r.color:"#9ca3af",'">').concat(r?r.text:"----").concat(a?'<div style="font-size:10px;color:#7c3aed;font-weight:500;margin-top:2px">'.concat(a,"</div>"):"","</td>")}).join("");return'<tr><td style="padding:6px 9px;border:1px solid #e5e7eb;font-size:13px;white-space:nowrap;background:'.concat(s%2===0?"white":"#f9fafb",'">').concat(s+1,". ").concat(t.name,"</td>").concat(r,"</tr>")}).join("");return'<div style="margin-bottom:20px;page-break-inside:avoid">\n <div style="background:#002147;color:white;padding:7px 11px;font-weight:700;font-size:14px;border-radius:4px 4px 0 0">'.concat(t.groupName).concat(t.groupCode?" (".concat(t.groupCode,")"):""," \u2014 ").concat(t.students.length," student").concat(1!==t.students.length?"s":"",'</div>\n <table style="width:100%;border-collapse:collapse">\n <thead><tr>\n <th style="padding:5px 9px;text-align:left;border:1px solid #d1d5db;font-size:13px;background:#f3f4f6;min-width:160px">Student</th>').concat(s,"\n </tr></thead>\n <tbody>").concat(r,"</tbody>\n </table></div>")}).join(""),l='<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Readiness '.concat(kt(t)," \u2014 ").concat(kt(s),'</title>\n <style>*{box-sizing:border-box;margin:0;padding:0}body{font-family:Arial,sans-serif;font-size:13px;color:#111827;padding:16px}@media print{.np{display:none!important}@page{size:portrait;margin:10mm}}</style>\n </head><body>\n <div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:14px;padding-bottom:10px;border-bottom:2px solid #002147">\n <div><h1 style="font-size:20px;font-weight:800;color:#002147">Readiness Report</h1><p style="color:#6b7280;font-size:13px;margin-top:3px">').concat(kt(t)," \u2014 ").concat(kt(s),'</p></div>\n <div class="np"><button onclick="window.print()" style="padding:4px 10px;background:#002147;color:white;border:none;border-radius:4px;cursor:pointer;font-size:13px">Print</button></div>\n </div>\n <div style="display:flex;gap:10px;margin-bottom:14px">\n <div style="padding:6px 12px;background:#d1fae5;border:1px solid #6ee7b7;border-radius:5px;text-align:center"><div style="font-size:20px;font-weight:800;color:#059669">').concat(r.READY,'</div><div style="font-size:11px;color:#059669;font-weight:700;text-transform:uppercase">Ready</div></div>\n <div style="padding:6px 12px;background:#fff7ed;border:1px solid #fdba74;border-radius:5px;text-align:center"><div style="font-size:20px;font-weight:800;color:#c2410c">').concat(r.TRIED_BUT_DIDNT_PASS,'</div><div style="font-size:11px;color:#c2410c;font-weight:700;text-transform:uppercase">Not Ready</div></div>\n <div style="padding:6px 12px;background:#fee2e2;border:1px solid #fca5a5;border-radius:5px;text-align:center"><div style="font-size:20px;font-weight:800;color:#dc2626">').concat(r.ABSENT,'</div><div style="font-size:11px;color:#dc2626;font-weight:700;text-transform:uppercase">Absent</div></div>\n <div style="padding:6px 12px;background:#f3f4f6;border:1px solid #e5e7eb;border-radius:5px;text-align:center"><div style="font-size:20px;font-weight:800;color:#374151">').concat(e.dates.length,'</div><div style="font-size:11px;color:#6b7280;font-weight:700;text-transform:uppercase">Dates</div></div>\n </div>\n ').concat(a,"</body></html>"),o=window.open("","_blank");o.document.write(l),o.document.close(),o.focus(),setTimeout(()=>
1o.print(),500)}(o,i,d),className:"shrink-0 flex items-center gap-1.5 px-3 py-2 bg-gray-800 text-white text-xs font-semibold rounded-xl hover:bg-gray-900 transition-colors",children:"\ud83d\udda8\ufe0f Print"})]}),(0,l.jsx)("div",{className:"space-y-4",children:(null!==(a=o.groups)&&void 0!==a?a:[]).map(e=>(0,l.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:[(0,l.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 flex items-center gap-2",style:{backgroundColor:"#002147"},children:[(0,l.jsx)("span",{className:"font-semibold text-white text-sm",children:e.groupName}),e.groupCode&&(0,l.jsxs)("span",{className:"text-xs",style:{color:"rgba(255,255,255,0.7)"},children:["(",e.groupCode,")"]}),(0,l.jsxs)("span",{className:"ml-auto text-xs",style:{color:"rgba(255,255,255,0.65)"},children:[e.students.length," students"]})]}),(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-xs",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{className:"bg-gray-50 border-b border-gray-100",children:[(0,l.jsx)("th",{className:"text-left px-4 py-2 font-semibold text-gray-500 whitespace-nowrap sticky left-0 bg-gray-50",style:{minWidth:"140px",borderRight:"1px solid #f3f4f6"},children:"Student"}),o.dates.map(e=>(0,l.jsx)("th",{className:"text-center px-2 py-2 font-semibold text-gray-600 whitespace-nowrap border-l border-gray-100",children:At(e)},e))]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-50",children:e.students.map((e,t)=>(0,l.jsxs)("tr",{className:t%2===0?"bg-white":"bg-gray-50/40",children:[(0,l.jsxs)("td",{className:"px-4 py-2 font-medium text-gray-800 whitespace-nowrap sticky left-0 border-r border-gray-100",style:{backgroundColor:t%2===0?"white":"rgb(249,250,251,0.4)"},children:[(0,l.jsx)("span",{className:"text-gray-400 mr-1.5",children:t+1}),e.name]}),o.dates.map(t=>{var s;const n=Ct[e.byDate[t]],r=null===(s=e.topicsByDate)||void 0===s?void 0:s[t];return(0,l.jsx)("td",{className:"text-center px-1.5 py-1.5 border-l border-gray-50",style:{backgroundColor:n?n.bg:"transparent"},children:n?(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{style:{color:n.color,fontWeight:700},children:n.label}),r&&(0,l.jsx)("div",{className:"text-xs mt-0.5 leading-tight",style:{color:"#7c3aed",fontWeight:500},title:r,children:r.length>20?r.slice(0,20)+"\u2026":r})]}):(0,l.jsx)("span",{className:"text-gray-300",children:"----"})},t)})]},e.studentId))})]})})]},e.groupId))})]})}function Et(){var e,t,s,a;const[o,i]=(0,n.useState)("daily"),[d,c]=(0,n.useState)(St),[x,u]=(0,n.use
1State)(wt),[m,p]=(0,n.useState)(St),[h,g]=(0,n.useState)(null),[f,b]=(0,n.useState)(!1),[y,v]=(0,n.useState)(""),[j,N]=(0,n.useState)(null),[S,w]=(0,n.useState)(!1),[k,A]=(0,n.useState)("");function C(e,t){let s=!1;b(!0),v(""),g(null);const n="custom"===e&&t?"date=".concat(t):"period=".concat(e);return(0,r.n)("/readiness-checks/report?".concat(n)).then(e=>e.json()).then(e=>{s||(e.success?g(e.data):v(e.message||"Failed to load report."))}).catch(e=>{s||v(e.message||"Network error.")}).finally(()=>{s||b(!1)}),()=>{s=!0}}function T(e,t){if(!e||!t)return;let s=!1;return w(!0),A(""),N(null),(0,r.n)("/readiness-checks/pivot-report?from=".concat(e,"&to=").concat(t)).then(e=>e.json()).then(e=>{s||(e.success?N(e.data):A(e.message||"Failed to load."))}).catch(e=>{s||A(e.message||"Network error.")}).finally(()=>{s||w(!1)}),()=>{s=!0}}(0,n.useEffect)(()=>{if("custom"!==o&&"range"!==o)return C(o,null)},[o]),(0,n.useEffect)(()=>{if("custom"===o&&d)return C("custom",d)},[o,d]),(0,n.useEffect)(()=>{"range"===o&&T(x,m)},[o]);const E=h?(null!==(e=h.groups)&&void 0!==e?e:[]).reduce((e,t)=>(t.students.forEach(t=>{e.ready+=t.ready,e.tried+=t.tried,e.absent+=t.absent}),e),{ready:0,tried:0,absent:0}):null,I="range"===o,R="custom"===o;return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3 flex-wrap gap-2",children:[(0,l.jsx)("h2",{className:"text-base font-semibold text-gray-800",children:"Readiness Statistics"}),(0,l.jsx)("div",{className:"flex bg-gray-100 rounded-lg p-1 gap-0.5 flex-wrap",children:Nt.map(e=>(0,l.jsx)("button",{onClick:()=>{i(e.key),g(null),N(null)},className:"px-3 py-1 text-xs font-medium rounded-md transition-all ".concat(o===e.key?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"),children:e.label},e.key))})]}),R&&(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-gray-500 whitespace-nowrap",children:"Vocab date:"}),(0,l.jsx)("input",{type:"date",value:d,max:St,onChange:e=>c(e.target.value),className:"border border-gray-300 rounded-lg px-2.5 py-1 text-xs text-gray-800 focus:outline-none focus:ring-2 focus:ring-orange-400"}),(0,l.jsx)("span",{className:"text-xs text-gray-400 hidden sm:inline",children:"All students checked for this vocab date"})]}),I&&(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-3 flex-wrap bg-gray-50 rounded-xl border border-gray-200 px-3 py-2.5",children:[(0,l.jsx)("span",{className:"text-xs font-semibold text-gray-500",children:"From:"}),(0,l.jsx)("input",{type:"date",value:x,max:m,onChange:e=>u(e.target.value),className:"border border-gray-300 rounded-lg px-2 py-1 text-xs focus:outline-none focus:ring-2 focus:ring-orange-400"}),(0,l.jsx)("span",{className:"text-xs font-semibold text-gray-500",children:"To:"}),(0,l.jsx)("input",{type:"date",value:m,min:x,max:St,onChange:e=>p(e.target.value),className:"border border-gray-300 rounded-lg px-2 py-1 text-xs focus:outline-none focus:ring-2 focus:ring-orange-400"}),(0,l.jsx)("button",{onClick:()=>T(x,m),className:"px-3 py-1 bg-gray-800 text-white text-xs font-semibold rounded-lg hover:bg-gray-900 transition-colors",children:"Load"}),(0,l.jsx)("button",{onClick:()=>T(x,m),className:"px-2 py-1 text-xs text-gray-500 hover:text-gray-700 rounded-lg hover:bg-gray-100",children:"\u21bb"})]}),I&&(S?(0,l.jsx)("div",{className:"space-y-3",children:[1,2].map(e=>(0,l.jsx)("div",{className:"bg-white rounded-xl border h-28 animate-pulse"},e))}):k?(0,l.jsx)("div",{className:"px-4 py-3 bg-red-50 border border-red-200 rounded-xl text-sm text-red-700",children:k}):j?(0,l.jsx)(Tt,{data:j,fromDate:x,toDate:m}):(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm text-center py-10 text-gray-400",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udcc5"}),(0,l.jsxs)("p",{className:"text-sm",children:["Select a date range and press ",(0,l.jsx)("strong",{children:"Load"}),"."]})]})),!I&&(0,l.jsxs)(l.Fragment,{children:[f&&(0,l.jsx)("div",{className:"space-y-3",children:[1,2].map(e=>(0,l.jsx)("div",{className:"bg-white rounded-xl border h-28 animate-pulse"},e))}),y&&(0,l.jsx)("div",{className:"px-4 py-3 bg-red-50 border border-red-200 rounded-xl text-sm text-red-700",children:y}),!f&&!y&&h&&(0,l.jsxs)(l.Fragment,{children:[E&&E.ready+E.tried+E.absent>0&&(0,l.jsxs)("div",{className:"flex gap-3 mb-4",children:[(0,l.jsxs)("div",{className:"flex-1 bg-green-50 border border-green-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-green-700",children:E.ready}),(0,l.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"Ready"})]}),(0,l.jsxs)("div",{className:"flex-1 bg-orange-50 border border-orange-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-orange-700",children:E.tried}),(0,l.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"Not Ready"})]}),(0,l.jsxs)("div",{className:"flex-1 bg-red-50 border border-red-200 rounded-xl px-3 py-2.5 text-center",children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-red-700",children:E.absent}),(0,l.jsx)("div",{className:"text-xs text-red-600 font-medium",children:"Absent"})]})]}),0===(null!==(t=null===(s=h.groups)||void 0===s?void 0:s.length)&&void 0!==t?t:0)?(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm text-center py-10 text-gray-400",children:[(0,l.jsx)("div",{className:"text-4xl mb-2",children:"\ud83d\udcca"}),R?(0,l.jsxs)("p",{className:"text-sm",children:["No readiness data for ",new Date(d+"T12:00:00").toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}),"."]}):(0,l.jsx)("p",{className:"text-sm",children:"No readiness data for this period."}),"daily"===o&&(0,l.jsx)("p",{className:"text-xs mt-1",children:"Use the search above to mark students."})]}):(0,l.jsx)("div",{className:"space-y-4",children:(null!==(a=h.groups)&&void 0!==a?a:[]).map(e=>(0,l.jsx)(jt,{group:e},e.groupId))})]})]})]})}function It(e){let{user:t}=e;const s=t||function(){try{return JSON.parse(localStorage.getItem("user")||"{}")}catch(e){return{}}}
1(),[o,i]=(0,n.useState)([]),[d,c]=(0,n.useState)(!0),[x,u]=(0,n.useState)({}),[m,p]=(0,n.useState)(!1),h=(0,n.useCallback)(async()=>{try{const e=await(0,r.n)("/readiness-checks/today"),t=await e.json(),s=Array.isArray(t.data)?t.data:[];i(s);const n={};s.forEach(e=>{(e.enrollments||[]).forEach(e=>{"PENDING"!==e.status&&(n[e.studentId]={status:e.status,notes:e.notes,topicsAsked:e.topicsAsked})})}),u(n)}catch(e){}finally{c(!1),p(!1)}},[]);return(0,n.useEffect)(()=>{h();const e=setInterval(h,3e4);return()=>clearInterval(e)},[h]),(0,l.jsx)("div",{className:"min-h-screen bg-gray-50",children:(0,l.jsxs)("div",{className:"max-w-3xl mx-auto px-4 py-6 space-y-8",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h1",{className:"text-2xl font-bold text-gray-900",children:"Readiness Check"}),s.firstName&&(0,l.jsxs)("p",{className:"text-sm text-gray-500 mt-0.5",children:["Welcome, ",s.firstName,"."]})]}),m&&(0,l.jsx)("span",{className:"text-xs text-gray-400 mt-2",children:"Refreshing\u2026"})]}),(0,l.jsx)("section",{children:(0,l.jsx)(pt,{markedMap:x,onMarked:function(e,t){u(s=>(0,a.A)((0,a.A)({},s),{},{[e]:t})),h()}})}),(0,l.jsx)("section",{children:(0,l.jsx)(yt,{todayChecks:o,loading:d,onRefresh:function(){p(!0),h()}})}),(0,l.jsx)("section",{children:(0,l.jsx)(Et,{})})]})})}const Rt={home:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"})}),groups:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"})}),schedule:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5"})}),attendance:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 002.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 00-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75 2.25 2.25 0 00-.1-.664m-5.8 0A2.251 2.251 0 0113.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25z"})}),homework:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"})}),testbank:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 3.104v5.714a2.25 2.25 0 01-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 014.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0112 15a9.065 9.065 0 00-6.23-.693L5 14.5m14.8.8l1.402 1.402c1 1 .03 2.788-1.548 2.545l-4.622-.772a56.26 56.26 0 00-5.064 0L5.2 18.847c-1.578.243-2.547-1.545-1.548-2.545L5 14.5"})}),exams:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 3v11.25A2.25 2.25 0 006 16.5h2.25M3.75 3h-1.5m1.5 0h16.5m0 0h1.5m-1.5 0v11.25A2.25 2.25 0 0118 16.5h-2.25m-7.5 0h7.5m-7.5 0l-1 3m8.5-3l1 3m0 0l.5 1.5m-.5-1.5h-9.5m0 0l-.5 1.5m.75-9l3-3 2.148 2.148A12.061 12.061 0 0116.5 7.605"})}),examschedule:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.375 19.5h17.25m-17.25 0a1.125 1.125 0 01-1.125-1.125M3.375 19.5h7.5c.621 0 1.125-.504 1.125-1.125m-9.75 0V5.625m0 12.75v-1.5c0-.621.504-1.125 1.125-1.125m18.375 2.625V5.625m0 12.75c0 .621-.504 1.125-1.125 1.125m1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125m0 3.75h-7.5A1.125 1.125 0 0112 18.375m9.75-12.75c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125m19.5 0v1.5c0 .621-.504 1.125-1.125 1.125M2.25 5.625v1.5c0 .621.504 1.125 1.125 1.125m0 0h17.25m-17.25 0h7.5c.
1621 0 1.125.504 1.125 1.125M3.375 8.25c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125m17.25-3.75h-7.5c-.621 0-1.125.504-1.125 1.125m8.625-1.125c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5"})}),gradesheets:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z"})}),comments:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 8.25h9m-9 3H12m-9.75 1.51c0 1.6 1.123 2.994 2.707 3.227 1.129.166 2.27.293 3.423.379.35.026.67.21.865.501L12 21l2.755-4.133a1.14 1.14 0 01.865-.501 48.172 48.172 0 003.423-.379c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.
1123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"})}),todos:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),vocabChecks:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 6h9.75M10.5 6a1.5 1.5 0 11-3 0m3 0a1.5 1.5 0 10-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-9.75 0h9.75"})}),readiness:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z"})}),printRequests:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0110.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0l.229 2.523a1.125 1.125 0 01-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0021 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 00-1.913-.247M6.34 18H5.25A2.25 2.25 0 013 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 011.913-.247m10.5 0a48.536 48.536 0 00-10.5 0m10.5 0V3.375c0-.621-.504-1.125-1.125-1.125h-8.25c-.621 0-1.125.504-1.125 1.125v3.659M18 10.5h.008v.008H18V10.5zm-3 0h.008v.008H15V10.5z"})}),achievements:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-3.375c0-.621-.503-1.125-1.125-1.125h-.871M7.5 18.75v-3.375c0-.621.504-1.125 1.125-1.125h.872m5.007 0H9.497m5.007 0a7.454 7.454 0 01-.982-3.172M9.497 14.25a7.454 7.454 0 00.981-3.172M5.25 4.236c-.982.143-1.954.317-2.916.52A6.003 6.003 0 007.73 9.728M5.25 4.236V4.5c0 2.108.966 3.99 2.48 5.228M5.25 4.236V2.721C7.456 2.41 9.71 2.25 12 2.25c2.291 0 4.545.16 6.75.47v1.516M7.73 9.728a6.726 6.726 0 002.748 1.35m8.272-6.842V4.5c0 2.108-.966 3.99-2.48 5.228m2.48-5.492a46.32 46.32 0 012.916.52 6.003 6.003 0 01-5.395 4.972m0 0a6.726 6.726 0 01-2.749 1.35m0 0a6.772 6.772 0 01-3.044 0"})}),messages:(0,l.jsx)("svg",{className:"w-full h-full",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})})};function Dt(){var e;const[t,s]=(0,n.useState)("home"),[a,d]=(0,n.useState)(0),[c,x]=(0,n.useState)(0),[u,m]=(0,n.useState)(!1),[p]=(0,n.useState)(()=>{try{return JSON.parse(localStorage.getItem("user")||"{}")}catch(e){return{}}}),{theme:h,themeId:f,setThemeId:b}=(0,i.DP)();(0,n.useEffect)(()=>{if(localStorage.getItem("user")){if(p.role&&"TEACHER"!==p.role){const e="MASTER_ADMIN"===p.role?"/master":"PARENT"===p.role?"/parent":"/dashboard";window.location.href=e}}else window.location.href="/login"},[p.role]);(0,n.useEffect)(()=>{const e=async()=>{try{const e=await(0,r.n)("/chat/unread-count"),t=await e.json();t.success&&d(t.count)}catch(e){}};e();const t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,n.useEffect)(()=>{const e=async()=>{try{const e=await(0,r.n)("/readiness-checks"),t=await e.json();if(t.success){const e=(t.data||[]).filter(e=>"PENDING"===e.status||"IN_PROGRESS"===e.status);x(e.length)}}catch(e){}};e();const t=setInterval(e,6e4);return()=>clearInterval(t)},[]);const y=e=>{let{id:n,label:r,badge:a}=e;const o=t===n,i=Rt[n];return(0,l.jsxs)("button",{onClick:()=>{s(n),m(!1)},className:"w-full flex items-center gap-2.5 px-3 py-2.5 rounded-xl transition-all text-left",style:o?{backgroundColor:h.primary,color:"white",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}:{color:h.secondary},onMouseEnter:e=>{o||(e.currentTarget.style.backgroundColor=h.primaryLight,e.currentTarget.style.color=h.primary)},onMouseLeave:e=>{o||(e.currentTarget.style.backgroundColor="",e.currentTarget.style.color=h.secondary)},children:[(0,l.jsx)("span",{className:"w-[18px] h-[18px] flex-shrink-0",children:i}),(0,l.jsx)("span",{className:"text-sm font-semibold flex-1 truncate",children:r}),a>0&&(0,l.jsx)("span",{className:"bg-red-500 text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full min-w-[18px] text-center flex-shrink-0",children:a})]})};return(0,l.jsxs)("div",{className:"flex min-h-screen",style:{backgroundColor:h.bgPage},children:[u&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black/50 z-20 lg:hidden",onClick:()=>m(!1)}),(0,l.jsxs)("aside",{className:"fixed top-0 left-0 h-full w-64 bg-white shadow-xl flex flex-col z-30 overflow-y-auto sidebar-transition ".concat(u?"translate-x-0":"-translate-x-full"," lg:translate-x-0"),style:{borderRight:"2px solid ".concat(h.primary)},children:[(0,l.jsxs)("div",{className:"p-5",style:{backgroundColor:h.primary},children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,l.jsx)("img",{src:"/genius-logo.png",alt:"Genius English Courses",className:"h-7 object-contain",style:{filter:"brightness(0) invert(1)"}}),(0,l.jsx)("button",{onClick:()=>m(!1),className:"lg:hidden text-white p-1.5 rounded-lg hover:bg-white/10 transition-colors","aria-label":"Close menu",children:(0,l.jsx)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsxs)("div",{className:"w-10 h-10 rounded-xl bg-white/20 flex items-center justify-center font-black text-white text-sm flex-shrink-0",children:[(p.firstName||"?").charAt(0),(p.lastName||"").charAt(0)]}),(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsxs)("p",{className:"text-sm font-bold text-white truncate",children:[p.firstName," ",p.lastName]}),(0,l.jsx)("p",{className:"text-[0.68rem] text-white/60 truncate mt-0.5",children:p.email})]})]})]}),(0,l.jsxs)("nav",{className:"p-3 space-y-0.5 flex-1",children:[(0,l.jsx)(y,{id:"home",label:"Home"}),(0,l.jsx)(y,{id:"groups",label:"My Groups"}),(0,l.jsx)(y,{id:"schedule",label:"My Schedule"}),(0,l.jsx)(y,{id:"attendance",label:"Attendance"}),(0,l.jsx)(y,{id:"homework",label:"Homework"}),(0,l.jsx)(y,{id:"testbank",label:"Test Bank"}),(0,l.jsx)(y,{id:"exams",label:"Exams & Grades"}),(0,l.jsx)(y,{id:"examschedule",label:"Exam Scheduling"}),(0,l.jsx)(y,{id:"gradesheets",label:"Grade Sheets"}),(0,l.jsx)(y,{id:"comments",label:"Student Comments"}),(0,l.jsx)(y,{id:"todos",label:"TO DO"}),(0,l.jsx)(y,{id:"vocabChecks",label:"Vocab Checks"}),(0,l.jsx)(y,{id:"readiness",label:"Readiness Checks",badge:c}),(0,l.jsx)(y,{id:"printRequests",label:"Print Requests"}),(0,l.jsx)(y,{id:"achievements",label:"Achievements"}),(0,l.jsx)(y,{id:"messages",label:"Messages",badge:a})]}),(0,l.jsxs)("div",{className:"px-4 py-3",style:{borderTop:"1px solid ".concat(h.primaryLight)},children:[(0,l.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest mb-2",style:{color:h.secondary},children:"Theme"}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[Object.values(i.zG).map(e=>(0,l.jsx)("button",{onClick:()=>b(e.id),title:e.name,className:"flex-shrink-0 rounded-full cursor-pointer border-none transition-all",style:{width:22,height:22,background:e.swatch,border:f===e.id?"3px solid white":"2px s
1olid transparent",boxShadow:f===e.id?"0 0 0 2px ".concat(e.swatch):"0 1px 3px rgba(0,0,0,0.2)"}},e.id)),(0,l.jsx)("span",{className:"text-[11px] ml-1",style:{color:h.secondary},children:null===(e=i.zG[f])||void 0===e?void 0:e.name})]})]}),(0,l.jsx)("div",{className:"p-4",style:{borderTop:"2px solid ".concat(h.divider)},children:(0,l.jsxs)("button",{onClick:async()=>{try{await(0,r.n)("/auth/logout",{method:"POST"})}catch(e){}localStorage.removeItem("user"),window.location.href="/login"},className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 text-white rounded-xl transition-colors font-semibold text-sm cursor-pointer border-none",style:{backgroundColor:h.primary},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=h.primaryHover},onMouseLeave:e=>{e.currentTarget.style.backgroundColor=h.primary},children:[(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75"})}),"Logout"]})})]}),(0,l.jsxs)("div",{className:"lg:ml-64 flex-1 min-h-screen flex flex-col",children:[(0,l.jsxs)("div",{className:"lg:hidden sticky top-0 z-10 flex items-center justify-between px-4 py-3 shadow-md flex-shrink-0",style:{backgroundColor:h.primary},children:[(0,l.jsx)("button",{onClick:()=>m(!0),className:"text-white p-1.5 rounded-lg hover:bg-white/10 transition-colors","aria-label":"Open menu",children:(0,l.jsx)("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"})})}),(0,l.jsx)("img",{src:"/genius-logo.png",alt:"Genius English Courses",className:"h-7 object-contain px-2",style:{filter:"brightness(0) invert(1)"}}),(0,l.jsx)("div",{className:"w-8"})]}),(0,l.jsxs)("main",{className:"flex-1 overflow-y-auto",children:["home"===t&&(0,l.jsx)(g,{user:p,onNavigate:s}),"groups"===t&&(0,l.jsx)(k,{}),"schedule"===t&&(0,l.jsx)(j,{}),"attendance"===t&&(0,l.jsx)(Y,{}),"homework"===t&&(0,l.jsx)(ne,{}),"testbank"===t&&(0,l.jsx)(le,{}),"exams"===t&&(0,l.jsx)(ce,{}),"examschedule"===t&&(0,l.jsx)(Ae,{}),"gradesheets"===t&&(0,l.jsx)(Ge,{}),"comments"===t&&(0,l.jsx)(Fe,{}),"todos"===t&&(0,l.jsx)(o,{}),"messages"===t&&(0,l.jsx)(_e,{currentUserId:p.id}),"vocabChecks"===t&&(0,l.jsx)(ot,{user:p}),"readiness"===t&&(0,l.jsx)(It,{user:p}),"printRequests"===t&&(0,l.jsx)(Ve,{}),"achievements"===t&&(0,l.jsx)(Ke,{})]})]})]})}}}]); 2//# sourceMappingURL=943.8a40de58.chunk.js.map
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.