import{r as u,j as e,L as h,bO as b,k as y,e as N}from"./vendor-BKmmeuxg.js";import{Q as v,a as k,b as _}from"./question-status-icon-ClKO4JNY.js";import{Q as C}from"./question-type-badge-C65yTFrV.js";import{B as n}from"./button-BpNwv2aE.js";import{C as q,a as w,c as S,b as Q}from"./card-D9_SJYq6.js";import{I as A}from"./input-DM0goJrn.js";import{L as B}from"./label-HmIcv5Yx.js";import{e as E}from"./richtor-CRcM6Du2.js";import"./badge-AQfLLMpR.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const P=({attempt:i})=>{const[l,o]=u.useState({}),[m,d]=u.useState(!1),c=i.attempt_answers??[],x=s=>s.exam_question??{},p=(s,a)=>{const t=parseFloat(a)||0;o(r=>({...r,[s]:t}))},j=()=>{d(!0),N.post(route("exam-attempts.grade",i.id),{manual_grades:l},{preserveScroll:!0,onSuccess:()=>{d(!1),o({})},onError:()=>{d(!1)}})},g=c.some(s=>{const a=x(s);return a.question_type==="listening"||a.question_type==="short_answer"});return i?e.jsxs("div",{className:"space-y-6",children:[e.jsxs(q,{children:[e.jsx(w,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(S,{children:"Detailed Analysis"}),e.jsx(n,{asChild:!0,variant:"outline",children:e.jsxs(h,{href:route("exams.edit",{exam:i.exam_id,tab:"attempts"}),children:[e.jsx(b,{className:"h-4 w-4"}),"Back Attempts"]})})]})}),e.jsx(Q,{children:e.jsx("div",{className:"space-y-6",children:c.map((s,a)=>{const t=x(s),r=t.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(v,{answer:s})}),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 ",a+1]}),t.question_type&&e.jsx(C,{type:t.question_type}),e.jsx(k,{answer:s})]}),e.jsx("p",{className:"text-sm font-medium text-gray-700",children:t.title})]})]}),e.jsxs("div",{className:"flex-shrink-0 text-right",children:[e.jsxs("p",{className:"text-lg font-bold text-gray-900",children:[s.marks_obtained||0,"/",t.marks||0]}),e.jsx("p",{className:"text-xs text-gray-500",children:"marks"})]})]})}),e.jsxs("div",{className:"p-4",children:[t.description&&e.jsx(E,{value:t.description}),e.jsx("div",{className:"mb-4",children:e.jsx(_,{answer:s,question:t})}),(t.question_type==="listening"||t.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(B,{htmlFor:`grade-${r}`,className:"text-sm font-semibold text-gray-700",children:["Assign Marks (Max: ",t.marks||0,")"]}),e.jsx(A,{id:`grade-${r}`,type:"number",min:"0",max:t.marks||0,step:"0.5",placeholder:"Enter marks",value:l[r]??s.marks_obtained??"",onChange:f=>p(r,f.target.value),className:"mt-1 w-full"}),s.is_correct===null&&e.jsxs("p",{className:"mt-2 flex items-center gap-1 text-xs text-yellow-700",children:[e.jsx(y,{className:"h-3 w-3"}),"This question requires manual grading"]})]})]})]},s.id??a)})})})]}),g&&e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx(n,{variant:"outline",onClick:()=>window.history.back(),children:"Cancel"}),e.jsx(n,{onClick:j,disabled:m||Object.keys(l).length===0,children:m?"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(h,{href:route("student.index","exams"),children:e.jsx(n,{variant:"outline",children:"Back to My Exams"})})})]})})};export{P as default};