(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3052],{71644:function(e,t,s){Promise.resolve().then(s.bind(s,22895))},58064:function(e,t,s){"use strict";Object.defineProperty(t,"$",{enumerable:!0,get:function(){return n}});let r=s(74590);function n(e){let{createServerReference:t}=s(6671);return t(e,r.callServer)}},2834:function(e,t,s){"use strict";s.d(t,{ep:function(){return c},h6:function(){return a},lE:function(){return n}}),s(74590);var r=s(58064),n=(0,r.$)("0a435b7bb2545622398293f1cac55cc3a6e9d9e3"),a=(0,r.$)("9b69cb0d8f7c6bf961495639bbe89a426ed56f87"),c=(0,r.$)("c3770d011b99ba83b13abdba687e44e4c947a223")},67669:function(e,t,s){"use strict";s.d(t,{h:function(){return a},i:function(){return n}}),s(74590);var r=s(58064),n=(0,r.$)("5c8f7f611bdec8b3c9e1156ccdf014bfbfbbafa7"),a=(0,r.$)("bef96225b573cb4c444345211c7471ed1c51344c")},22895:function(e,t,s){"use strict";s.d(t,{default:function(){return l}});var r=s(57437),n=s(2265),a=s(2834),c=s(67669);function l(e){let{classes:t}=e,[s,l]=(0,n.useState)(""),[i,d]=(0,n.useState)([]),[u,o]=(0,n.useState)(""),[b,m]=(0,n.useState)([]),[x,f]=(0,n.useState)({}),[h,p]=(0,n.useState)(!1),[g,j]=(0,n.useState)(!1),[v,N]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!s){d([]),m([]);return}p(!0),(0,a.ep)(Number(s)).then(e=>d(e)).finally(()=>p(!1))},[s]),(0,n.useEffect)(()=>{s&&(0,a.lE)(Number(s)).then(m)},[s]);let y=async()=>{if(!u)return;j(!0),N(null);let e=Object.entries(x).map(e=>{let[t,s]=e;return{studentId:t,marksObtained:s,maxMarks:100}});try{let t=await (0,c.h)(Number(u),e);t.success?N({type:"success",text:"Marks saved."}):N({type:"error",text:t.error||"Error saving."})}catch(e){N({type:"error",text:"Unexpected error."})}finally{j(!1)}};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"border-b pb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold text-gray-800",children:"Enter Marks"}),(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Record student performance."})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700",children:"Class"}),(0,r.jsxs)("select",{className:"w-full p-2 border rounded",value:s,onChange:e=>{l(Number(e.target.value)),o(""),f({})},children:[(0,r.jsx)("option",{value:"",children:"Select Class"}),t.map(e=>(0,r.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700",children:"Exam Subject"}),(0,r.jsxs)("select",{className:"w-full p-2 border rounded",value:u,onChange:e=>o(Number(e.target.value)),disabled:!s,children:[(0,r.jsx)("option",{value:"",children:"Select Exam"}),i.map(e=>(0,r.jsxs)("option",{value:e.id,children:[e.title," - ",e.subject.name]},e.id))]})]})]}),h&&(0,r.jsx)("p",{className:"text-gray-500",children:"Loading details..."}),!h&&u&&b.length>0&&(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded border",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsxs)("h3",{className:"font-semibold text-gray-700",children:["Student List (",b.length,")"]}),(0,r.jsx)("button",{onClick:y,disabled:g,className:"px-4 py-2 bg-school-green-600 text-white rounded hover:bg-school-green-500 disabled:opacity-50",children:g?"Saving...":"Save All Marks"})]}),v&&(0,r.jsx)("div",{className:"mb-4 p-2 rounded text-sm ".concat("success"===v.type?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:v.text}),(0,r.jsx)("div",{className:"space-y-2",children:b.map(e=>(0,r.jsxs)("div",{className:"flex items-center justify-between bg-white p-2 border rounded",children:[(0,r.jsxs)("span",{className:"text-sm font-medium w-1/3",children:[e.surname,", ",e.name]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500",children:"Marks (out of 100):"}),(0,r.jsx)("input",{type:"number",className:"w-24 p-1 border rounded text-right",min:"0",max:"100",value:x[e.id]||"",onChange:t=>f(s=>({...s,[e.id]:Number(t.target.value)}))})]})]},e.id))})]})]})}}},function(e){e.O(0,[2971,7023,1744],function(){return e(e.s=71644)}),_N_E=e.O()}]);