"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[50472],{50472:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u});var a=s(95155),l=s(12115),n=s(74016),r=s(56468),i=s(30313),c=s(7404),d=s(16099),f=s(2962),h=s(2581);let m=[{value:"PRESENT",label:"Present"},{value:"ABSENT",label:"Absent"},{value:"LATE",label:"Late"}];function u(){let[e,t]=(0,l.useState)(()=>new Date().toISOString().slice(0,10)),[s,u]=(0,l.useState)([]),[o,x]=(0,l.useState)(!1),[j,b]=(0,l.useState)(!1),N=(0,l.useCallback)(async()=>{if(e){x(!0);try{let t=await (0,c.Mx)(e);u(t.staff)}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to load staff attendance"),u([])}finally{x(!1)}}},[e]);(0,l.useEffect)(()=>{N()},[N]);let S=e=>{u(t=>t.map(t=>({...t,status:e})))},p=async t=>{if(t.preventDefault(),0!==s.length){b(!0);try{let t=await (0,c.RQ)({date:e,records:s.map(e=>({userId:e.userId,status:e.status}))});u(t.staff),(0,h.Te)("Staff attendance saved")}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to save")}finally{b(!1)}}},v=(e,t,s=!1)=>(0,a.jsx)("select",{className:`${i.Mg} ${s?"w-full":"min-w-[7rem]"}`,value:t,onChange:t=>{var s;return s=t.target.value,void u(t=>t.map(t=>t.userId===e?{...t,status:s}:t))},children:m.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))}),g=s.filter(e=>"PRESENT"===e.status).length,y=s.filter(e=>"ABSENT"===e.status).length,E=s.filter(e=>"LATE"===e.status).length;return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)(n.wc,{title:"Staff attendance",description:"Mark daily attendance for teachers and staff."}),(0,a.jsx)(r.O,{}),(0,a.jsxs)(i.a,{tone:"info",title:"Staff list",children:["Attendance includes active teachers and staff from"," ",(0,a.jsx)(f.u,{href:d.bw.SMS_ADMIN.STAFF,className:"font-semibold text-primary-700 hover:underline",children:"Staff Directory"}),". Unmarked staff default to Absent until you save."]}),(0,a.jsxs)(i.r7,{children:[(0,a.jsx)(i.yB,{label:"Date",className:"min-w-0 flex-1 sm:min-w-[10rem]",children:(0,a.jsx)(i.IM,{value:e,onChange:e=>t(e.target.value)})}),s.length>0?(0,a.jsxs)("div",{className:"flex flex-wrap items-end gap-2",children:[(0,a.jsx)(i.mU,{type:"button",size:"sm",onClick:()=>S("PRESENT"),children:"Mark all present"}),(0,a.jsx)(i.mU,{type:"button",size:"sm",onClick:()=>S("ABSENT"),children:"Mark all absent"})]}):null]}),!o&&s.length>0?(0,a.jsxs)("p",{className:"text-sm text-slate-600",children:[g," present \xb7 ",E," late \xb7 ",y," absent \xb7 ",s.length," total"]}):null,o?(0,a.jsx)(i.nI,{rows:4}):(0,a.jsxs)("form",{onSubmit:p,children:[(0,a.jsx)(i.yg,{children:0===s.length?(0,a.jsx)(i.i0,{title:"No staff to mark",description:"Add staff in the directory first, then return to mark attendance.",action:(0,a.jsx)(f.u,{href:d.bw.SMS_ADMIN.STAFF,children:(0,a.jsx)(i.mU,{type:"button",children:"Go to staff directory"})})}):s.map(e=>(0,a.jsxs)(i.oe,{children:[(0,a.jsx)("p",{className:"font-semibold text-slate-900",children:e.fullName}),(0,a.jsx)(i._w,{label:"Role",children:e.staffRoleLabel}),(0,a.jsx)(i.yB,{label:"Status",children:v(e.userId,e.status,!0)})]},e.userId))}),(0,a.jsx)(i.iZ,{children:(0,a.jsxs)(i.cR,{minWidth:"40rem",children:[(0,a.jsx)(i.K_,{children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:`${i.aB} font-medium`,children:"Staff"}),(0,a.jsx)("th",{className:`${i.aB} font-medium`,children:"Role"}),(0,a.jsx)("th",{className:`${i.aB} font-medium`,children:"Email"}),(0,a.jsx)("th",{className:`${i.aB} font-medium`,children:"Status"})]})}),(0,a.jsx)("tbody",{children:0===s.length?(0,a.jsx)("tr",{children:(0,a.jsx)("td",{colSpan:4,className:`${i.Cl} text-center text-slate-500`,children:"No staff members found."})}):s.map(e=>(0,a.jsxs)("tr",{className:"border-t border-slate-100",children:[(0,a.jsx)("td",{className:`${i.Cl} font-medium text-slate-900`,children:e.fullName}),(0,a.jsx)("td",{className:`${i.Cl} text-slate-600`,children:e.staffRoleLabel}),(0,a.jsx)("td",{className:`${i.Cl} text-slate-600`,children:e.email}),(0,a.jsx)("td",{className:i.Cl,children:v(e.userId,e.status)})]},e.userId))})]})}),(0,a.jsx)(i.Yv,{hint:`${s.length} staff \xb7 ${g} present`,visible:s.length>0,children:(0,a.jsx)(i.kL,{type:"submit",disabled:j,children:j?"Saving…":"Save attendance"})})]})]})}}}]);