var C=Object.defineProperty,S=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var f=(t,s,i)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i,b=(t,s)=>{for(var i in s||(s={}))A.call(s,i)&&f(t,i,s[i]);if(g)for(var i of g(s))B.call(s,i)&&f(t,i,s[i]);return t},y=(t,s)=>S(t,Q(s));import{r as N,j as e,aS as v,aJ as E,b4 as G,aX as M}from"./react-vendor-xYZnmIII.js";import{Q as I,a as L,b as P}from"./question-status-icon-UMdgxa4M.js";import{Q as R}from"./question-type-badge-BwDT6jbG.js";import{B as d,a as T,k as F,m as $,l as D,L as H,I as J}from"./ui-components-CQM92IK3.js";import{P as O}from"./richtor-BECSBxkh.js";import"./inertia-vendor-cBbDTmhJ.js";import"./ui-vendor-Ds9iwIxa.js";import"./interactive-vendor-B1OgcAgP.js";const se=({attempt:t})=>{var u;const[s,i]=N.useState({}),[o,c]=N.useState(!1),m=(u=t.attempt_answers)!=null?u:[],x=a=>{var n;return(n=a.exam_question)!=null?n:{}},k=(a,n)=>{const r=parseFloat(n)||0;i(l=>y(b({},l),{[a]:r}))},_=()=>{c(!0),M.post(route("exam-attempts.grade",t.id),{manual_grades:s},{preserveScroll:!0,onSuccess:()=>{c(!1),i({})},onError:()=>{c(!1)}})},q=m.some(a=>{const n=x(a);return n.question_type==="listening"||n.question_type==="short_answer"});return t?e.jsxs("div",{className:"space-y-6",children:[e.jsxs(T,{children:[e.jsx(F,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx($,{children:"Detailed Analysis"}),e.jsx(d,{asChild:!0,variant:"outline",children:e.jsxs(v,{href:route("exams.edit",{exam:t.exam_id,tab:"attempts"}),children:[e.jsx(E,{className:"h-4 w-4"}),"Back Attempts"]})})]})}),e.jsx(D,{children:e.jsx("div",{className:"space-y-6",children:m.map((a,n)=>{var h,j,p;const r=x(a),l=r.id;return e.jsxs("div",{className:"overflow-hidden rounded-lg border-2 border-gray-200 bg-white",children:[e.jsx("div",{className:"border-b border-gray-200 bg-gray-50 p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-1 items-start gap-3",children:[e.jsx("div",{className:"mt-1 flex-shrink-0",children:e.jsx(I,{answer:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-lg font-semibold",children:["Question ",n+1]}),r.question_type&&e.jsx(R,{type:r.question_type}),e.jsx(L,{answer:a})]}),e.jsx("p",{className:"text-sm font-medium text-gray-700",children:r.title})]})]}),e.jsxs("div",{className:"flex-shrink-0 text-right",children:[e.jsxs("p",{className:"text-lg font-bold text-gray-900",children:[a.marks_obtained||0,"/",r.marks||0]}),e.jsx("p",{className:"text-xs text-gray-500",children:"marks"})]})]})}),e.jsxs("div",{className:"p-4",children:[r.description&&e.jsx(O,{value:r.description}),e.jsx("div",{className:"mb-4",children:e.jsx(P,{answer:a,question:r})}),(r.question_type==="listening"||r.question_type==="short_answer")&&e.jsxs("div",{className:"mt-4 rounded-lg border-t border-gray-200 bg-yellow-50 p-4 pt-4",children:[e.jsxs(H,{htmlFor:`grade-${l}`,className:"text-sm font-semibold text-gray-700",children:["Assign Marks (Max: ",r.marks||0,")"]}),e.jsx(J,{id:`grade-${l}`,type:"number",min:"0",max:r.marks||0,step:"0.5",placeholder:"Enter marks",value:(j=(h=s[l])!=null?h:a.marks_obtained)!=null?j:"",onChange:w=>k(l,w.target.value),className:"mt-1 w-full"}),a.is_correct===null&&e.jsxs("p",{className:"mt-2 flex items-center gap-1 text-xs text-yellow-700",children:[e.jsx(G,{className:"h-3 w-3"}),"This question requires manual grading"]})]})]})]},(p=a.id)!=null?p:n)})})})]}),q&&e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx(d,{variant:"outline",onClick:()=>window.history.back(),children:"Cancel"}),e.jsx(d,{onClick:_,disabled:o||Object.keys(s).length===0,children:o?"Submitting...":"Submit Grades"})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-800",children:"Attempt data unavailable"}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Please return to the exam list and try again."}),e.jsx("div",{className:"mt-4",children:e.jsx(v,{href:route("student.index","exams"),children:e.jsx(d,{variant:"outline",children:"Back to My Exams"})})})]})})};export{se as default};
