import{r as x,u as m,j as e}from"./app-DP6lEqpE.js";import{A as b}from"./AppLayout-DveQsGoq.js";import{S as d}from"./SelectInput-BiWhhW9c.js";import{T as n}from"./TextInput-Boj94GH-.js";import{f as u}from"./formatters-CfeoZ7wP.js";function j({grade:l,onClose:i}){const a=m({score:String(l.score),max_score:String(l.maxScore),reason:""});function o(r){r.preventDefault(),a.put(`/teacher/grades/${l.id}`,{onSuccess:()=>i()})}return e.jsx("form",{onSubmit:o,style:{marginTop:"0.75rem",background:"var(--color-bg-soft)",padding:"0.75rem",borderRadius:"var(--radius-sm)"},children:e.jsxs("div",{className:"form-grid",style:{gridTemplateColumns:"1fr 1fr 2fr auto auto"},children:[e.jsx(n,{label:"نمره جدید",type:"number",min:"0",step:"0.25",value:a.data.score,onChange:r=>a.setData("score",r.target.value),error:a.errors.score}),e.jsx(n,{label:"از",type:"number",min:"1",step:"0.25",value:a.data.max_score,onChange:r=>a.setData("max_score",r.target.value)}),e.jsx(n,{label:"دلیل تغییر",value:a.data.reason,onChange:r=>a.setData("reason",r.target.value)}),e.jsx("button",{className:"btn btn-primary btn-sm",style:{alignSelf:"flex-end",marginBottom:"0.1rem"},disabled:a.processing,type:"submit",children:"ذخیره"}),e.jsx("button",{className:"btn btn-ghost btn-sm",style:{alignSelf:"flex-end",marginBottom:"0.1rem"},type:"button",onClick:i,children:"لغو"})]})})}function S({students:l,classes:i,subjects:a,grades:o}){const[r,c]=x.useState(null),s=m({student_id:"",classroom_id:"",subject_id:"",exam_id:"",score:"",max_score:"20",description:""}),h={draft:"badge-muted",submitted:"badge-warning",approved:"badge-success",rejected:"badge-danger"};return e.jsx(b,{title:"نمره‌دهی",children:e.jsxs("div",{className:"page-stack",children:[e.jsxs("form",{className:"panel-card",onSubmit:t=>{t.preventDefault(),s.post("/teacher/grades",{preserveScroll:!0,onSuccess:()=>s.reset()})},children:[e.jsx("h2",{children:"ثبت نمره جدید"}),e.jsxs("div",{className:"form-grid",children:[e.jsx(d,{label:"دانش‌آموز",value:s.data.student_id,onChange:t=>s.setData("student_id",t.target.value),options:[{value:"",label:"انتخاب دانش‌آموز"},...l]}),e.jsx(d,{label:"کلاس",value:s.data.classroom_id,onChange:t=>s.setData("classroom_id",t.target.value),options:[{value:"",label:"انتخاب کلاس"},...i]}),e.jsx(d,{label:"درس",value:s.data.subject_id,onChange:t=>s.setData("subject_id",t.target.value),options:[{value:"",label:"انتخاب درس"},...a]}),e.jsx(n,{label:"نمره",type:"number",min:"0",step:"0.25",value:s.data.score,onChange:t=>s.setData("score",t.target.value),error:s.errors.score}),e.jsx(n,{label:"از نمره",type:"number",min:"1",step:"0.25",value:s.data.max_score,onChange:t=>s.setData("max_score",t.target.value)}),e.jsx(n,{label:"توضیح",value:s.data.description,onChange:t=>s.setData("description",t.target.value)})]}),e.jsx("button",{className:"btn btn-primary",disabled:s.processing,type:"submit",children:"ثبت نمره"})]}),o.length>0?e.jsx("div",{className:"table-wrap",children:e.jsxs("table",{className:"data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"دانش‌آموز"}),e.jsx("th",{children:"درس"}),e.jsx("th",{children:"نمره"}),e.jsx("th",{children:"وضعیت"}),e.jsx("th",{children:"آخرین تغییر"}),e.jsx("th",{children:"تغییر توسط"}),e.jsx("th",{children:"عملیات"})]})}),e.jsx("tbody",{children:o.map(t=>e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.student}),e.jsx("td",{children:t.subject}),e.jsxs("td",{children:[u(t.score)," از ",u(t.maxScore)]}),e.jsx("td",{children:e.jsx("span",{className:`badge ${h[t.statusKey]||"badge-muted"}`,children:t.status})}),e.jsx("td",{children:t.changedAt}),e.jsx("td",{children:t.changedBy}),e.jsx("td",{children:(t.statusKey==="draft"||t.statusKey==="submitted")&&e.jsxs("button",{className:"btn btn-ghost btn-sm",type:"button",onClick:()=>c(r===t.id?null:t.id),children:[e.jsx("i",{className:"bi bi-pencil"})," ویرایش"]})})]},t.id),r===t.id&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,children:e.jsx(j,{grade:t,onClose:()=>c(null)})})},`edit-${t.id}`)]}))})]})}):e.jsxs("section",{className:"panel-card",children:[e.jsx("h2",{children:"نمره‌ای ثبت نشده"}),e.jsx("p",{children:"بعد از ثبت نمره، جدول و audit log واقعی از دیتابیس نمایش داده می‌شود."})]})]})})}export{S as default};
