"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[80446],{80446:(e,t,s)=>{s.r(t),s.d(t,{default:()=>o});var l=s(95155),a=s(12115),n=s(74016),r=s(30313),i=s(95355),c=s(27665),d=s(7404),m=s(2581);function o(){let[e,t]=(0,a.useState)([]),[s,o]=(0,a.useState)([]),[x,h]=(0,a.useState)(""),[u,j]=(0,a.useState)(""),[f,N]=(0,a.useState)(null),[b,p]=(0,a.useState)(!1);(0,a.useEffect)(()=>{Promise.all([(0,d.dx)(),(0,d.jS)()]).then(([e,s])=>{t(e.filter(e=>e.isActive)),o(s.filter(e=>e.isActive))}).catch(e=>{t([]),o([]),(0,m.Qg)(e instanceof Error?e.message:"Failed to load filters")})},[]);let $=(0,a.useCallback)(async()=>{if(u&&x){p(!0);try{N(await (0,d.mR)({examId:u,schoolClassId:x}))}catch(e){(0,m.Qg)(e instanceof Error?e.message:"Failed to load merit list"),N(null)}finally{p(!1)}}},[u,x]);return(0,l.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,l.jsx)(n.wc,{title:"Merit list",description:"Ranked students by overall percentage for an exam and class."}),(0,l.jsx)(i.f,{}),(0,l.jsxs)(r.r7,{children:[(0,l.jsx)(r.yB,{label:"Exam",className:"min-w-0 flex-1 sm:min-w-[12rem]",children:(0,l.jsxs)(r.Kd,{value:u,onChange:e=>j(e.target.value),children:[(0,l.jsx)("option",{value:"",children:"Select exam"}),s.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]})}),(0,l.jsx)(r.yB,{label:"Class",className:"min-w-0 flex-1 sm:min-w-[12rem]",children:(0,l.jsxs)(r.Kd,{value:x,onChange:e=>h(e.target.value),children:[(0,l.jsx)("option",{value:"",children:"Select class"}),e.map(e=>(0,l.jsx)("option",{value:e.id,children:e.displayName},e.id))]})}),(0,l.jsx)(r.bE,{children:(0,l.jsx)(r.kL,{type:"button",onClick:()=>void $(),disabled:!u||!x||b,children:b?"Loading…":"Generate"})})]}),f?(0,l.jsx)(c.J,{letterhead:f.letterhead,title:"Merit list",subtitle:`${f.exam.name} \xb7 ${f.schoolClass.displayName}`,meta:`Generated ${new Date(f.generatedAt).toLocaleString()}`,children:(0,l.jsx)(r.T7,{children:(0,l.jsxs)(r.cR,{minWidth:"36rem",children:[(0,l.jsx)(r.K_,{children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:`${r.aB} font-medium`,children:"Rank"}),(0,l.jsx)("th",{className:`${r.aB} font-medium`,children:"Roll"}),(0,l.jsx)("th",{className:`${r.aB} font-medium`,children:"Student"}),(0,l.jsx)("th",{className:`${r.aB} font-medium text-center`,children:"Total"}),(0,l.jsx)("th",{className:`${r.aB} font-medium text-center`,children:"%"}),(0,l.jsx)("th",{className:`${r.aB} font-medium text-center`,children:"Grade"}),(0,l.jsx)("th",{className:`${r.aB} font-medium text-center`,children:"Result"})]})}),(0,l.jsx)("tbody",{children:f.rows.length?f.rows.map(e=>(0,l.jsxs)("tr",{className:"border-t border-slate-100",children:[(0,l.jsx)("td",{className:`${r.Cl} font-semibold tabular-nums`,children:e.rank}),(0,l.jsx)("td",{className:r.Cl,children:e.rollNumber||"—"}),(0,l.jsx)("td",{className:`${r.Cl} font-medium text-slate-900`,children:e.fullName}),(0,l.jsxs)("td",{className:`${r.Cl} text-center tabular-nums`,children:[e.totals.obtained,"/",e.totals.fullMarks]}),(0,l.jsx)("td",{className:`${r.Cl} text-center tabular-nums`,children:e.totals.percent??"—"}),(0,l.jsx)("td",{className:`${r.Cl} text-center`,children:e.totals.overallGrade||"—"}),(0,l.jsx)("td",{className:`${r.Cl} text-center text-xs font-semibold`,children:e.totals.result})]},e.userId)):(0,l.jsx)(r.tU,{colSpan:7,children:"No marked students yet"})})]})})}):null]})}}}]);