1"use strict";(self.webpackChunkstudent_management_app=self.webpackChunkstudent_management_app||[]).push([[5174],{11594:(e,t,s)=>{s.d(t,{$o:()=>r,Y_:()=>n,hM:()=>l});const a=e=>String(e||"").trim().toLowerCase(),r=(e,t)=>{var s,r;const l=a("nar"===t?null===(s=e.narRegistration)||void 0===s?void 0:s.status:null===(r=e.cprApplication)||void 0===r?void 0:r.status);return["applied","submitted","approved","completed",..."nar"===t?["active"]:[]].includes(l)},l=(e,t)=>{var s,l;const n=a("nar"===t?null===(s=e.narRegistration)||void 0===s?void 0:s.status:null===(l=e.cprApplication)||void 0===l?void 0:l.status);return{text:{not_started:"Not Started",not_registered:"Not Registered",pending:"Pending",in_progress:"In Progress",applied:"Applied",submitted:"Submitted",approved:"Approved",completed:"Completed",active:"Active"}[n]||(n?"Unknown":"Not Started"),color:r(e,t)?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"}},n=e=>({active:"bg-green-50/50 hover:bg-green-100/60",completed:"bg-blue-50/50 hover:bg-blue-100/60",graduated:"bg-purple-50/50 hover:bg-purple-100/60",withdrawn:"bg-red-50/50 hover:bg-red-100/60",suspended:"bg-orange-50/50 hover:bg-orange-100/60",onleave:"bg-yellow-50/50 hover:bg-yellow-100/60"}[a(e)]||"bg-slate-50/50 hover:bg-slate-100/60")},14012:(e,t,s)=>{function a(e){if(null===e||void 0===e||!e.width||null===e||void 0===e||!e.height)return"";const t=e.getContext("2d").getImageData(0,0,e.width,e.height);let s=e.width,a=-1,r=e.height,l=-1;for(let x=0;x<e.height;x+=1)for(let n=0;n<e.width;n+=1){const i=4*(x*e.width+n);t.data[i+3]>20&&(t.data[i]<235||t.data[i+1]<235||t.data[i+2]<235)&&(s=Math.min(s,n),a=Math.max(a,n),r=Math.min(r,x),l=Math.max(l,x))}if(a<s||l<r)return"";const n=Math.max(8,Math.round(.015*e.width)),i=Math.max(0,s-n),o=Math.max(0,r-n),d=Math.min(e.width-i,a-s+1+2*n),c=Math.min(e.height-o,l-r+1+2*n),m=document.createElement("canvas");m.width=d,m.height=c;const u=m.getContext("2d");return u.fillStyle="#ffffff",u.fillRect(0,0,m.width,m.height),u.drawImage(e,i,o,d,c,0,0,d,c),m.toDataURL("image/png")}s.d(t,{U:()=>a})},19676:(e,t,s)=>{s.d(t,{Yq:()=>r,n4:()=>n,vv:()=>l});var a=s(69212);const r=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"MMM dd, yyyy";if(!e)return"Not set";try{return null!==e&&void 0!==e&&e.toDate?(0,a.GP)(e.toDate(),t):(0,a.GP)(new Date(e),t)}catch(s){return console.error("Error formatting date:",s),"Invalid date"}},l=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";if(void 0===e||null===e)return"$0.00";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:2,maximumFractionDigits:2}).format(e)}catch(s){return console.error("Error formatting currency:",s),"$0.00"}},n=e=>{if(!e)return"";const t=e.replace(/\D/g,"");return 10===t.length?`(${t.slice(0,3)}) ${t.slice(3,6)}-${t.slice(6)}`:e}},34935:(e,t,s)=>{s.d(t,{A:()=>d});var a=s(9950),r=s(2412),l=s(78691),n=s(62510),i=s(47288),o=(s(87302),s(34788),s(44414));function d(e){let{url:t,className:s=""}=e;const r=(0,a.useRef)(null),[d,c]=(0,a.useState)(320),[m,u]=(0,a.useState)(0),[x,h]=(0,a.useState)("");return(0,a.useEffect)(()=>{const e=r.current;if(!e)return;const t=()=>{const t=Math.floor(e.getBoundingClientRect().width-16);c(Math.max(1,Math.min(850,t)))};t();const s=new ResizeObserver(t);return s.observe(e),()=>s.disconnect()},[]),(0,o.jsx)("div",{ref:r,className:`min-w-0 max-w-full overflow-x-hidden overflow-y-auto bg-slate-200 p-2 sm:p-3 ${s}`,children:(0,o.jsx)(l.A,{file:t,onLoadSuccess:e=>{let{numPages:t}=e;u(t),h("")},onLoadError:e=>h((null===e||void 0===e?void 0:e.message)||"Unable to render this PDF."),loading:(0,o.jsxs)("div",{className:"flex min-h-[420px] items-center justify-center gap-2 text-sm text-slate-600",children:[(0,o.jsx)(i.A,{className:"h-5 w-5 animate-spin"}),"Rendering all agreement pages\u2026"]}),error:(0,o.jsxs)("div",{className:"m-4 rounded-lg bg-white p-5 text-center text-sm text-red-700",children:[x||"Unable to render this PDF.",(0,o.jsx)("div",{className:"mt-2",children:(0,o.jsx)("a",{href:t,target:"_blank",rel:"noreferrer",className:"font-semibold underline",children:"Open the PDF in a new tab"})})]}),children:(0,o.jsx)("div",{className:"min-w-0 max-w-full space-y-3 sm:space-y-4",children:Array.from({length:m},(e,t)=>(0,o.jsxs)("div",{className:"mx-auto max-w-full overflow-hidden bg-white shadow-md",style:{width:d},children:[(0,o.jsx)(n.A,{pageNumber:t+1,width:d,renderTextLayer:!1,renderAnnotationLayer:!1,loading:(0,o.jsxs)("div",{style:{width:d,height:1.29*d},className:"grid place-items-center bg-white text-sm text-slate-500",children:["Loading page ",t+1,"\u2026"]})}),(0,o.jsxs)("div",{className:"border-t bg-white py-1 text-center text-[11px] font-medium text-slate-400",children:["Page ",t+1," of ",m]})]},`page-${t+1}`))})})})}r.EA.workerSrc=new URL(s(98956),s.b).toString()},64216:(e,t,s)=>{s.d(t,{nV:()=>r});const a=e=>{if(!e||""===e||null===e||void 0===e)return 0;const t=new Date;let s;if(e instanceof Date)s=e;else{if("string"!==typeof e)return console.warn("calculateAge: Invalid dateOfBirth type:",typeof e),0;s=new Date(e)}if(isNaN(s.getTime()))return console.warn("calculateAge: Invalid date format:",e),0;if(s>t)return console.warn("calculateAge: Birth date is in the future:",s),0;let a=t.getFullYear()-s.getFullYear();const r=t.getMonth()-s.getMonth();return(r<0||0===r&&t.getDate()<s.getDate())&&a--,Math.max(0,a)},r=e=>{const t=a(e);return 0===t?"Age not available":1===t?"1 year old":`${t} years old`}},95784:(e,t,s)=>{s.r(t),s.d(t,{default:()=>yt});var a=s(9950),r=s(56600),l=s(44414);const n=e=>null!==e&&void 0!==e&&e.toDate?e.toDate():new Date(e);function i(e){let{student:t}=e;const[s,i]=(0,a.useState)([]),[o,d]=(0,a.useState)(!0),[c,m]=(0,a.useState)(!1);return(0,a.useEffect)(()=>
1(d(!0),m(!1),i([]),(0,r.aQ)((0,r.P)((0,r.rJ)(r.db,"emailLogs"),(0,r.Hp)("studentId","==",t.id)),e=>{i(e.docs.map(e=>({...e.data(),id:e.id})).filter(e=>"certificate_to_employer"===e.type&&!0===e.success&&("employer"===e.recipientType||!e.recipientType&&String(e.to||"").toLowerCase()!==String(t.email||"").toLowerCase())).sort((e,t)=>(n(t.sentAt).getTime()||0)-(n(e.sentAt).getTime()||0))),d(!1)},()=>{m(!0),d(!1)})),[t.id,t.email]),(0,l.jsxs)("section",{className:"border-t border-slate-200 pt-3","aria-label":"Employer document delivery history",children:[(0,l.jsx)("h5",{className:"text-xs font-bold text-slate-700 uppercase mb-2",children:"Documents Sent to Employers"}),o?(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"Loading delivery history\u2026"}):c?(0,l.jsx)("p",{role:"alert",className:"text-sm text-red-700",children:"Unable to load delivery history. Refresh to try again."}):0===s.length?(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"No employer document deliveries recorded."}):(0,l.jsx)("ul",{className:"max-h-96 overflow-y-auto space-y-2",children:s.map(e=>{var t;return(0,l.jsxs)("li",{className:"rounded-lg border border-slate-200 bg-slate-50 p-3 text-sm",children:[(0,l.jsx)("a",{href:`mailto:${e.to}`,className:"block break-all font-semibold text-blue-700 hover:underline",children:e.to}),e.employerPhone?(0,l.jsx)("a",{href:`tel:${e.employerPhone.replace(/[^+\d]/g,"")}`,className:"mt-1 block text-blue-700 hover:underline",children:e.employerPhone}):(0,l.jsx)("p",{className:"mt-1 text-slate-500",children:"Phone not recorded"}),(0,l.jsxs)("p",{className:"mt-1 text-xs text-slate-500",children:["Sent ",e.sentAt&&!isNaN(n(e.sentAt))?n(e.sentAt).toLocaleString():"\u2014 date not recorded"]}),(null===(t=e.documentsSent)||void 0===t?void 0:t.length)>0&&(0,l.jsxs)("p",{className:"mt-1 break-words text-xs text-slate-600",children:["Documents: ",e.documentsSent.join(", ")]})]},e.id)})})]})}var o=s(22177),d=s(91523),c=s(23849);const m=(e,t)=>(0,c.c4)(r.db,async s=>{const a=(0,c.H9)(r.db,"students",e),l=await s.get(a);if(!l.exists())throw new Error("Student record not found.");const n=l.data().documents||[],i=[...n,...t.filter(e=>!n.some(t=>t.id===e.id))];return s.update(a,{documents:i,"documentStats.totalDocuments":i.length,"documentStats.lastUploadDate":(0,c.O5)()}),i}),u=e=>{if(!e||!["image/jpeg","image/png","image/webp"].includes(e.type))throw new Error("Choose a JPG, PNG, or WebP image.");if(e.size>5242880)throw new Error("Choose an image smaller than 5 MB.")};var x=s(99163),h=s(64112),g=s(55556),p=s(15536);const b=e=>{var t;let{student:s,onPhotoUpload:n,displayName:i=s.fullName||"Student"}=e;const[o,d]=(0,a.useState)(!1),[m,b]=(0,a.useState)(""),[f,v]=(0,a.useState)(!1),[y,j]=(0,a.useState)(""),[N,w]=(0,a.useState)(!1),[S,A]=(0,a.useState)(!1);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("div",{className:"w-16 h-16 rounded-full bg-gray-100 border-2 border-gray-200 flex items-center justify-center overflow-hidden "+(s.profilePhoto?"cursor-pointer hover:ring-2 hover:ring-blue-400 transition-all":""),onClick:()=>s.profilePhoto&&A(!0),title:s.profilePhoto?"Click to view full photo":"",children:s.profilePhoto?(0,l.jsx)("img",{src:s.profilePhoto,alt:"Profile",className:"w-full h-full object-cover"}):(0,l.jsx)(h.A,{className:"w-8 h-8 text-gray-400"})}),(0,l.jsxs)("label",{className:"absolute -bottom-1 -right-1 w-6 h-6 bg-blue-600 rounded-full flex items-center justify-center cursor-pointer hover:bg-blue-700 transition-colors shadow-sm",children:[(0,l.jsx)(g.A,{className:"w-3.5 h-3.5 text-white"}),(0,l.jsx)("input",{type:"file",accept:"image/jpeg,image/png,image/webp","aria-label":"Upload student photo",disabled:o,onChange:async e=>{var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];if(e.target.value="",s&&!o){b(""),d(!0);try{if(u(s),!n)throw new Error("Photo upload is unavailable. Please reload and try again.");await n(s)}catch(a){b(a.message||"Photo could not be saved. Please try again.")}finally{d(!1)}}},className:"hidden"})]})]}),(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("h2",{className:"text-lg font-bold text-slate-900",children:i}),(0,l.jsxs)("p",{className:"text-xs text-slate-600 font-medium",children:["Student ID: ",null===(t=s.id)||void 0===t?void 0:t.slice(-8)]}),o&&(0,l.jsx)("p",{role:"status",className:"text-xs text-blue-600 mt-0.5",children:"Saving photo\u2026 Please wait."}),m&&(0,l.jsx)("p",{role:"alert",className:"text-xs text-red-600 mt-0.5",children:m})]}),(0,l.jsxs)("button",{onClick:async()=>{w(!0);try{const e=`photo_${s.id}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,t=new Date(Date.now()+18e5);await(0,c.BN)((0,c.H9)(r.db,"photoTokens",e),{studentId:s.id,studentName:s.fullName||[s.firstName,s.lastName].filter(
1Boolean).join(" "),createdAt:(0,c.O5)(),expiresAt:t});const a=window.location.origin;j(`${a}/photo-capture/${e}`),v(!0)}catch(e){console.error("QR generation error:",e)}finally{w(!1)}},disabled:N,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-violet-50 text-violet-700 border border-violet-200 rounded-lg hover:bg-violet-100 transition-colors disabled:opacity-50",title:"Scan QR to take photo with phone",children:[(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4h4v4H3V4zm0 12h4v4H3v-4zm12-12h4v4h-4V4zm0 12h4v4h-4v-4zm-6 0h4v4H9v-4zm0-12h4v4H9V4zm-6 6h4v4H3v-4zm12 0h4v4h-4v-4zm-6 0h4v4H9v-4z"})}),N?"Generating...":"QR Photo"]})]}),f&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>v(!1),children:(0,l.jsxs)("div",{className:"bg-white rounded-xl shadow-xl max-w-sm w-full p-6",onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,l.jsx)("h3",{className:"text-lg font-bold text-slate-900",children:"Scan to Take Photo"}),(0,l.jsx)("button",{onClick:()=>v(!1),className:"p-1 hover:bg-slate-100 rounded-lg",children:(0,l.jsx)(p.A,{className:"w-5 h-5 text-slate-500"})})]}),(0,l.jsxs)("p",{className:"text-sm text-slate-600 mb-4",children:["Scan this QR code with your phone to take a photo for ",(0,l.jsx)("strong",{children:i})]}),(0,l.jsx)("div",{className:"flex justify-center p-4 bg-white rounded-lg border-2 border-slate-100",children:(0,l.jsx)(x.h,{value:y,size:220,level:"M"})}),(0,l.jsx)("p",{className:"text-xs text-slate-400 text-center mt-3",children:"Link expires in 30 minutes"})]})}),S&&s.profilePhoto&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4",onClick:()=>A(!1),children:(0,l.jsxs)("div",{className:"relative max-w-lg w-full max-h-[90vh] flex flex-col items-center",onClick:e=>e.stopPropagation(),children:[(0,l.jsx)("button",{onClick:()=>A(!1),className:"absolute -top-2 -right-2 z-10 w-8 h-8 bg-white rounded-full flex items-center justify-center shadow-lg hover:bg-slate-100",children:(0,l.jsx)(p.A,{className:"w-5 h-5 text-slate-700"})}),(0,l.jsx)("img",{src:s.profilePhoto,alt:i,className:"max-w-full max-h-[80vh] rounded-xl shadow-2xl object-contain"}),(0,l.jsx)("p",{className:"text-white text-sm font-medium mt-3",children:i})]})})]})};var f=s(67117),v=s(99699),y=s(47288),j=s(19535),N=s(28400),w=s(55551),S=s(71057),A=s(56790),C=s(67714),D=s(99845),k=s(34935),E=s(14012);function P(e){const t=e.updatedAt||e.createdAt;return null!==t&&void 0!==t&&t.toMillis?t.toMillis():new Date(t||0).getTime()}function $(e){let{student:t,onCompleted:s}=e;const{showToast:n}=(0,C.d)(),{showConfirm:i}=(0,D.M)(),[o,d]=(0,a.useState)(null),[m,u]=(0,a.useState)(!0),[x,h]=(0,a.useState)(!1),[g,p]=(0,a.useState)(!1),[b,$]=(0,a.useState)(!1),[F,I]=(0,a.useState)(""),[R,T]=(0,a.useState)(""),[,M]=(0,a.useState)(!1),[O,U]=(0,a.useState)(""),L=(0,a.useRef)(null),B=(0,a.useRef)(null),z=(0,a.useCallback)(async()=>{if(null!==t&&void 0!==t&&t.id){u(!0);try{const e=(await(0,c.GG)((0,c.P)((0,c.rJ)(r.db,"enrollmentAgreements"),(0,c._M)("studentId","==",t.id)))).docs.map(e=>({id:e.id,...e.data()})).sort((e,t)=>P(t)-P(e));d(e[0]||null)}catch(e){console.warn("Unable to load enrollment agreement",e)}finally{u(!1)}}},[null===t||void 0===t?void 0:t.id]);(0,a.useEffect)(()=>{z()},[z]),(0,a.useEffect)(()=>{(0,r.Ij)("getDocumentSettings").then(e=>{I(t=>{var s;return t||(null===e||void 0===e||null===(s=e.universal)||void 0===s?void 0:s.programRepresentativeName)||""}),T(t=>{var s;return t||(null===e||void 0===e||null===(s=e.universal)||void 0===s?void 0:s.programRepresentativeTitle)||""})}).catch(()=>{})},[]),(0,a.useEffect)(()=>{if(!g||!L.current)return;const e=L.current,t=Math.max(window.devicePixelRatio||1,1);return e.width=e.offsetWidth*t,e.height=170*t,e.getContext("2d").scale(t,t),B.current=new f.A(e,{backgroundColor:"#ffffff",penColor:"#111827"}),()=>{var e;null===(e=B.current)||void 0===e||e.off(),B.current=null}},[g]);const _=async()=>
1{if(!t.email)return n("Add a student email address first","error");if(await i(`Email the Student Enrollment Agreement to ${t.email} for signature?`,{title:"Send Enrollment Agreement",confirmText:"Send agreement"})){h(!0);try{await(0,r.Ij)("sendEnrollmentAgreement",{studentId:t.id}),n("Enrollment Agreement sent for signature","success"),await z()}catch(e){n(e.message||"Unable to send agreement","error")}finally{h(!1)}}},H=null===o||void 0===o?void 0:o.status,G=null!==o&&void 0!==o&&o.id?`https://us-central1-hudumacna-2831c.cloudfunctions.net/viewEnrollmentAgreementPdf?token=${encodeURIComponent(o.id)}`:"";return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("h3",{className:"flex items-center gap-2 font-semibold text-slate-900",children:[(0,l.jsx)(v.A,{className:"h-5 w-5 text-blue-700"}),"Student Enrollment Agreement"]}),(0,l.jsx)("p",{className:"mt-1 text-sm text-slate-500",children:"Send, collect the student signature, countersign, and save the final copy."})]}),m&&(0,l.jsx)(y.A,{className:"h-5 w-5 animate-spin text-blue-600"})]}),!m&&!o&&(0,l.jsxs)("button",{onClick:_,disabled:x||!t.email,className:"mt-4 inline-flex w-full items-center justify-center gap-2 rounded-lg bg-blue-700 px-4 py-2.5 text-sm font-semibold text-white disabled:opacity-50",children:[(0,l.jsx)(j.A,{className:"h-4 w-4"}),x?"Sending\u2026":"Email agreement for signature"]}),!m&&"awaiting_student"===H&&(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded-lg bg-amber-50 p-3 text-sm text-amber-800",children:[(0,l.jsx)(N.A,{className:"h-5 w-5"}),(0,l.jsxs)("span",{children:[(0,l.jsx)("strong",{children:"Awaiting student signature"}),(0,l.jsx)("br",{}),(0,l.jsxs)("span",{className:"text-xs",children:["Sent to ",o.studentEmail]})]})]}),(0,l.jsx)("button",{onClick:_,disabled:x,className:"mt-3 w-full rounded-lg border border-amber-300 px-4 py-2 text-sm font-semibold text-amber-800",children:x?"Resending\u2026":"Send a new signing link"})]}),!m&&"awaiting_admin"===H&&(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsxs)("div",{className:"rounded-lg bg-blue-50 p-3 text-sm text-blue-900",children:[(0,l.jsx)("strong",{children:"Student signature received"}),(0,l.jsx)("p",{className:"mt-1 text-xs",children:"Review the student-signed PDF, then countersign it."})]}),(0,l.jsxs)("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[(0,l.jsxs)("a",{href:G,target:"_blank",rel:"noreferrer",className:"inline-flex items-center justify-center gap-1.5 rounded-lg border border-slate-300 px-3 py-2 text-sm font-semibold text-slate-700",children:[(0,l.jsx)(w.A,{className:"h-4 w-4"}),"Review PDF"]}),(0,l.jsx)("button",{onClick:()=>p(!0),className:"rounded-lg bg-blue-700 px-3 py-2 text-sm font-semibold text-white",children:"Review & sign"}),(0,l.jsx)("button",{onClick:_,disabled:x,className:"rounded-lg border border-amber-300 px-3 py-2 text-sm font-semibold text-amber-800 sm:col-span-2",children:x?"Sending\u2026":"Send a fresh link for student re-signing"})]})]}),!m&&"completed"===H&&(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded-lg bg-emerald-50 p-3 text-sm text-emerald-800",children:[(0,l.jsx)(S.A,{className:"h-5 w-5"}),(0,l.jsxs)("span",{children:[(0,l.jsx)("strong",{children:"Fully signed and saved"}),(0,l.jsx)("br",{}),(0,l.jsx)("span",{className:"text-xs",children:"The completed copy was emailed to the student."})]})]}),o.finalPdfUrl&&(0,l.jsxs)("a",{href:G,target:"_blank",rel:"noreferrer",className:"mt-3 inline-flex w-full items-center justify-center gap-2 rounded-lg border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700",children:[(0,l.jsx)(w.A,{className:"h-4 w-4"}),"View signed agreement"]})]})]}),g&&(0,l.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 p-4",children:(0,l.jsxs)("div",{className:"w-full max-w-6xl overflow-hidden rounded-2xl bg-white shadow-2xl",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between border-b px-5 py-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"font-bold text-slate-900",children:"Review and countersign"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"All four pages are shown below. The final PDF will be saved to Student Documents and emailed automatically."})]}),(0,l.jsx)("button",{onClick:()=>p(!1),className:"p-2 text-slate-500",children:(0,l.jsx)(A.A,{className:"h-5 w-5"})})]}),(0,l.jsxs)("div",{className:"grid max-h-[82vh] gap-5 overflow-y-auto p-5 lg:grid-cols-[minmax(0,1.4fr)_minmax(320px,.6fr)]",children:[(0,l.jsx)(k.A,{url:G,className:"h-[68vh] min-h-[560px] rounded-lg border"}),(0,l.jsxs)("div",{className:"self-start lg:sticky lg:top-0",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700",children:["Representative name",(0,l.jsx)("input",{value:F,onChange:e=>I(e.target.value),className:"mt-1.5 w-full rounded-lg border px-3 py-2 font-normal"})]}),(0,l.jsxs)("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700",children:["Title",(0,l.jsx)("input",{value:R,onChange:e=>T(e.target.value),className:"mt-1.5 w-full rounded-lg border px-3 py-2 font-normal"})]}),(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700",children:["Signing date",(0,l.jsx)("input",{value:(new Date).toLocaleDateString("en-US"),readOnly:!0,className:"mt-1.5 w-full rounded-lg border bg-slate-50 px-3 py-2 font-normal"})]})]}),(0,l.jsxs)("div",{className:"mt-4 flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Representative signature"}),(0,l.jsx)("button",{onClick:()=>{var e;null===(e=B.current)||void 0===e||e.clear(),U(""),M(!1)},className:"text-xs font-semibold text-slate-600",children:"Clear"})]}),(0,l.jsx)("button",{onClick:()=>
1{if(!F.trim()||!L.current||!B.current)return void n("Enter the representative name first","error");const e=L.current,t=e.getContext("2d");B.current.clear(),t.save();let s=42;const a=e.offsetWidth-36;for(t.font=`italic ${s}px "Brush Script MT", "Segoe Script", cursive`;t.measureText(F.trim()).width>a&&s>22;)s-=2,t.font=`italic ${s}px "Brush Script MT", "Segoe Script", cursive`;t.fillStyle="#111827",t.textAlign="center",t.textBaseline="middle",t.fillText(F.trim(),e.offsetWidth/2,85),t.restore(),U((0,E.U)(e))},className:"mt-2 w-full rounded-lg border-2 border-blue-600 bg-blue-50 px-3 py-2.5 text-sm font-bold text-blue-800",children:"Insert typed-name signature"}),(0,l.jsx)("div",{className:"my-2 text-center text-[11px] font-semibold uppercase text-slate-400",children:"or draw below"}),(0,l.jsx)("canvas",{ref:L,onPointerDown:()=>{U(""),M(!1)},className:"h-[170px] w-full cursor-crosshair touch-none rounded-lg border-2 border-slate-400 bg-white"}),(0,l.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"Use mouse, trackpad, stylus, or finger."}),(0,l.jsxs)("button",{onClick:async()=>{const e=O||(B.current&&!B.current.isEmpty()?(0,E.U)(L.current):"");if(F.trim()&&R.trim()&&e){$(!0);try{await(0,r.Ij)("finalizeEnrollmentAgreement",{token:o.id,representativeName:F.trim(),representativeTitle:R.trim(),signatureImage:e}),p(!1),n("Agreement completed, saved, and emailed to the student","success"),await z(),await(null===s||void 0===s?void 0:s())}catch(t){n(t.message||"Unable to finalize agreement","error")}finally{$(!1)}}else n("Enter the representative name and title, then add a signature","error")},disabled:b,className:"mt-5 inline-flex w-full items-center justify-center gap-2 rounded-lg bg-emerald-700 px-4 py-3 font-bold text-white disabled:opacity-60",children:[b&&(0,l.jsx)(y.A,{className:"h-4 w-4 animate-spin"}),b?"Creating final copy\u2026":"Approve, sign, and email final copy"]})]})]})]})})]})}var F=s(11594),I=s(73814),R=s(40648),T=s(29402),M=s(19676);function O(e){let{student:t,onEditRegistrationDate:s,onEditCourseStartDate:a,onEditCompletionDate:r}=e;const n=[{label:"Registration Date",field:"registrationDate",edit:s},{label:"Course Start",field:"courseStartDate",source:"courseStartDateSource",edit:a},{label:"Expected Completion",field:"expectedCompletionDate",source:"completionDateSource",edit:r}];return(0,l.jsx)(l.Fragment,{children:n.map(e=>{let{label:s,field:a,source:r,edit:n}=e;return(0,l.jsxs)("div",{className:"bg-slate-50 p-3 rounded-lg border border-slate-200",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,l.jsx)("p",{className:"text-xs text-slate-600 uppercase tracking-wider font-bold",children:s}),(0,l.jsx)("button",{type:"button","aria-label":`Edit ${s}`,onClick:n,className:"text-xs text-blue-600 hover:text-blue-700 font-semibold",children:"Edit"})]}),(0,l.jsx)("p",{className:"text-sm font-bold text-slate-900 mt-0.5",children:t[a]?(0,M.Yq)(t[a]):"Not set"}),r&&("manual"===t[r]||t.scheduleId)&&(0,l.jsx)("p",{className:"mt-1 text-[10px] font-semibold uppercase tracking-wide text-blue-600",children:"manual"===t[r]?"Manually set":"From schedule"})]},a)})})}var U=s(48805);function L(e){let{student:t,payments:s,onViewDetails:a,onRecordPayment:r}=e;const n=(0,T.Jp)(t,s),i=n.balance>0;return(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"text-center p-4 rounded-lg border-2 "+(i?"bg-red-50 border-red-300 text-red-800":"bg-green-50 border-green-300 text-green-800"),children:[(0,l.jsx)("p",{className:"text-sm font-bold uppercase tracking-wider",children:"Current Balance"}),(0,l.jsx)("p",{className:"text-2xl font-bold mt-2","aria-label":"Current Balance",children:(0,M.vv)(n.balance)})]}),(0,l.jsxs)("dl",{className:"space-y-1 text-sm",children:[(0,l.jsxs)("div",{className:"flex justify-between",children:[(0,l.jsx)("dt",{children:"Total Charges"}),(0,l.jsx)("dd",{children:(0,M.vv)(n.totalAmount)})]}),(0,l.jsxs)("div",{className:"flex justify-between",children:[(0,l.jsx)("dt",{children:"Total Paid"}),(0,l.jsx)("dd",{className:"font-semibold text-green-700",children:(0,M.vv)(n.totalPaid)})]})]}),(0,l.jsxs)("div",{className:"flex space-x-2",children:[(0,l.jsx)(U.$,{size:"sm",variant:"outline",onClick:a,className:"flex-1 text-sm",children:"View Details"}),i&&(0,l.jsx)(U.$,{size:"sm",onClick:r,className:"flex-1 bg-blue-600 hover:bg-blue-700 text-sm",children:"Pay Now"})]})]})}const B={courseStartDate:"courseStartDateSource",expectedCompletionDate:"completionDateSource"},z=async(e,t,s)=>{if(!["registrationDate",...Object.keys(B)].includes(t))throw new Error("Invalid student date");if(!/^\d{4}-\d{2}-\d{2}$/.test(s))throw new Error("Please select a valid date");const[a,l,n]=s.split("-").map(Number),i=new Date(a,l-1,n,12);if(i.getFullYear()!==a||i.getMonth()!==l-1||i.getDate()!==n)throw new Error("Please select a valid date");const o={[t]:i.toISOString(),updatedAt:(0,c.O5)()};return B[t]&&(o[B[t]]="manual"),await(0,c.mZ)((0,c.H9)(r.db,"students",e),o),o};var _=s(674),H=(s(90067),s(23517)),G=s(62935),q=s(64216),Y=s(17638);var V=s(75854),Z=s(40732),W=s(2391),J=s(99696),Q=s(52941);const K=e=>{let{value:t,onChange:s,placeholder:r="Select date",label:n="",required:i=!1,minDate:o=null,maxDate:d=null,className:c="",alwaysShowCalendar:m=!1,viewMonth:u,viewYear:x,onViewDateChange:h}=e;const[g,b]=(0,a.useState)(m),[f,v]=(0,a.useState)(()=>
1{if(void 0!==x&&void 0!==u)return{year:x,month:u};if(t){const[e,s]=t.split("-");return{year:parseInt(e),month:parseInt(s)-1}}const e=new Date;return{year:e.getFullYear(),month:e.getMonth()}}),y=void 0!==x&&void 0!==u?{year:x,month:u}:f,j=e=>{const t="function"===typeof e?e(y):e;h?h(t.year,t.month):v(t)},N=(0,a.useRef)(null),w=(0,a.useRef)(g);(0,a.useEffect)(()=>{w.current=g},[g]);const S=(()=>{if(!t)return null;const[e,s,a]=t.split("-").map(Number);return{year:e,month:s-1,day:a}})();(0,a.useEffect)(()=>{if(t&&!h){const[e,s]=t.split("-");j({year:parseInt(e),month:parseInt(s)-1})}},[t,h]),(0,a.useEffect)(()=>{const e=e=>{N.current&&!N.current.contains(e.target)&&b(!1)};return g&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[g]);const A=e=>{e.stopPropagation(),e.preventDefault(),j(e=>0===e.month?{year:e.year-1,month:11}:{...e,month:e.month-1})},C=e=>{e.stopPropagation(),e.preventDefault(),j(e=>11===e.month?{year:e.year+1,month:0}:{...e,month:e.month+1})},D=(e,t,s)=>{const a=`${e}-${String(t+1).padStart(2,"0")}-${String(s).padStart(2,"0")}`;return!!(o&&a<o)||!!(d&&a>d)},k=(e,t)=>{e.stopPropagation(),e.preventDefault();const a=y.year,r=y.month;if(D(a,r,t))return;const l=`${a}-${String(r+1).padStart(2,"0")}-${String(t).padStart(2,"0")}`;s({target:{value:l}}),b(!1)};return(0,l.jsxs)("div",{className:`relative ${c}`,ref:N,children:[n&&(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:[n,i&&(0,l.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,l.jsxs)("div",{className:`\n flex h-12 w-full items-center justify-between rounded-md border border-gray-300\n bg-white px-4 py-2 text-base cursor-pointer\n focus-within:ring-2 focus-within:ring-blue-500 focus-within:border-blue-500\n hover:border-gray-400 transition-colors\n ${t?"text-gray-900":"text-gray-400"}\n `,onClick:e=>{e.stopPropagation(),b(!g)},children:[(0,l.jsx)("span",{className:"flex-1 truncate",children:t?(e=>{if(!e)return"";const[t,s,a]=e.split("-").map(Number);return new Date(t,s-1,a).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})(t):r}),(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,l.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),s({target:{value:""}})},className:"text-gray-400 hover:text-gray-600 p-1 rounded-full hover:bg-gray-100","aria-label":"Clear date",children:(0,l.jsx)(p.A,{className:"w-4 h-4"})}),(0,l.jsx)(Q.A,{className:"w-5 h-5 text-gray-400"})]})]}),(g||m)&&(0,l.jsx)("div",{className:m?"mt-3 bg-white border border-gray-200 rounded-lg shadow-sm":"absolute left-0 mt-1 bg-white border border-gray-200 rounded-lg shadow-xl",style:m?{}:{zIndex:9999},onClick:e=>e.stopPropagation(),children:(()=>{const e=(t=y.year,a=y.month,new Date(t,a+1,0).getDate());var t,a;const r=((e,t)=>new Date(e,t,1).getDay())(y.year,y.month),n=[];for(let s=0;s<r;s++)n.push((0,l.jsx)("div",{className:"h-8 w-8"},`empty-${s}`));for(let s=1;s<=e;s++){const e=S&&S.year===y.year&&S.month===y.month&&S.day===s,t=D(y.year,y.month,s),a=(()=>{const e=new Date;return e.getFullYear()===y.year&&e.getMonth()===y.month&&e.getDate()===s})();n.push((0,l.jsx)("button",{type:"button",onClick:e=>k(e,s),disabled:t,className:`\n h-8 w-8 rounded-full text-sm font-medium transition-colors\n ${e?"bg-blue-600 text-white hover:bg-blue-700":a?"bg-blue-100 text-blue-700 hover:bg-blue-200":t?"text-gray-300 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}\n `,children:s},s))}return(0,l.jsxs)("div",{className:"p-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsx)("button",{type:"button",onClick:A,className:"p-1 hover:bg-gray-100 rounded-full transition-colors",children:(0,l.jsx)(W.A,{className:"w-5 h-5 text-gray-600"})}),(0,l.jsx)("span",{className:"text-sm font-semibold text-gray-800",children:new Date(y.year,y.month).toLocaleDateString("en-US",{month:"long",year:"numeric"})}),(0,l.jsx)("button",{type:"button",onClick:C,className:"p-1 hover:bg-gray-100 rounded-full transition-colors",children:(0,l.jsx)(J.A,{className:"w-5 h-5 text-gray-600"})})]}),(0,l.jsx)("div",{className:"grid grid-cols-7 gap-1 mb-1",children:["Su","Mo","Tu","We","Th","Fr","Sa"].map(e=>(0,l.jsx)("div",{className:"h-8 w-8 flex items-center justify-center text-xs font-medium text-gray-500",children:e},e))}),(0,l.jsx)("div",{className:"grid grid-cols-7 gap-1",children:n}),(0,l.jsx)("div",{className:"mt-3 pt-3 border-t border-gray-200",children:(0,l.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),e.preventDefault();const t=new Date,a=`${t.getFullYear()}
1-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;s({target:{value:a}}),b(!1)},className:"w-full py-1.5 text-sm text-blue-600 hover:bg-blue-50 rounded-md transition-colors font-medium",children:"Today"})})]})})()})]})};var X=s(69212),ee=s(38138),te=s(17818),se=s(9145),ae=s(48153),re=s(57491),le=s(75516),ne=s(19530),ie=s(16467);const oe=e=>{let{alert:t,onEdit:s,onDelete:a,onAdd:r,canEdit:n=!0}=e;if(!t)return n?(0,l.jsx)("div",{className:"bg-gray-50 border border-gray-200 rounded-lg p-3 mb-6",children:(0,l.jsxs)("button",{onClick:r,className:"flex items-center text-sm text-gray-600 hover:text-gray-900 transition-colors",children:[(0,l.jsx)(re.A,{className:"w-4 h-4 mr-1.5"}),"Add Alert Notice"]})}):null;const i=function(){switch(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"critical"){case"critical":default:return{bg:"bg-red-50",border:"border-red-600",text:"text-red-900",icon:"text-red-600",headerText:"text-red-800",hoverBg:"hover:bg-red-100",dateText:"text-red-700"};case"warning":return{bg:"bg-orange-50",border:"border-orange-600",text:"text-orange-900",icon:"text-orange-600",headerText:"text-orange-800",hoverBg:"hover:bg-orange-100",dateText:"text-orange-700"};case"info":return{bg:"bg-blue-50",border:"border-blue-600",text:"text-blue-900",icon:"text-blue-600",headerText:"text-blue-800",hoverBg:"hover:bg-blue-100",dateText:"text-blue-700"};case"success":return{bg:"bg-green-50",border:"border-green-600",text:"text-green-900",icon:"text-green-600",headerText:"text-green-800",hoverBg:"hover:bg-green-100",dateText:"text-green-700"}}}(t.severity);return(0,l.jsx)("div",{className:"mb-6",children:(0,l.jsx)("div",{className:`${i.bg} border-l-4 ${i.border} rounded-lg shadow-lg`,children:(0,l.jsx)("div",{className:"p-4",children:(0,l.jsxs)("div",{className:"flex items-start",children:[(0,l.jsx)("div",{className:"flex-shrink-0",children:(0,l.jsx)(le.A,{className:`h-6 w-6 ${i.icon} animate-pulse`})}),(0,l.jsx)("div",{className:"ml-3 flex-1",children:(0,l.jsxs)("div",{className:"flex items-start justify-between",children:[(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("h3",{className:`text-sm font-bold ${i.headerText} uppercase tracking-wide mb-1`,children:"\u26a0\ufe0f Important Alert"}),(0,l.jsx)("p",{className:`text-base font-semibold ${i.text} leading-relaxed`,children:t.message}),t.createdAt&&(0,l.jsxs)("p",{className:`text-xs ${i.dateText} mt-2`,children:["Added: ",new Date(t.createdAt).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})]})]}),n&&(0,l.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,l.jsx)("button",{onClick:s,className:`p-1.5 rounded-lg ${i.hoverBg} transition-colors group`,title:"Edit alert",children:(0,l.jsx)(ne.A,{className:`w-4 h-4 ${i.icon} group-hover:opacity-80`})}),(0,l.jsx)("button",{onClick:a,className:`p-1.5 rounded-lg ${i.hoverBg} transition-colors group`,title:"Delete alert (requires PIN)",children:(0,l.jsx)(ie.A,{className:`w-4 h-4 ${i.icon} group-hover:opacity-80`})})]})]})})]})})})})},de=e=>{let{isOpen:t,onClose:s,onSave:r,existingAlert:n=null}=e;const[i,o]=(0,a.useState)(""),[d,c]=(0,a.useState)("critical"),[m,u]=(0,a.useState)(!1),x=[{value:"critical",label:"Critical",color:"red",description:"Immediate attention required"},{value:"warning",label:"Warning",color:"orange",description:"Important notice"},{value:"info",label:"Info",color:"blue",description:"General information"},{value:"success",label:"Success",color:"green",description:"Positive update"}];(0,a.useEffect)(()=>{t&&(o((null===n||void 0===n?void 0:n.message)||""),c((null===n||void 0===n?void 0:n.severity)||"critical"))},[t,n]);const h=()=>{const e=x.find(e=>e.value===d);switch(null===e||void 0===e?void 0:e.color){case"red":default:return{bg:"bg-red-50",border:"border-red-600",text:"text-red-900",icon:"text-red-600",headerText:"text-red-800"};case"orange":return{bg:"bg-orange-50",border:"border-orange-600",text:"text-orange-900",icon:"text-orange-600",headerText:"text-orange-800"};case"blue":return{bg:"bg-blue-50",border:"border-blue-600",text:"text-blue-900",icon:"text-blue-600",headerText:"text-blue-800"};case"green":return{bg:"bg-green-50",border:"border-green-600",text:"text-green-900",icon:"text-green-600",headerText:"text-green-800"}}};return t?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(le.A,{className:"w-6 h-6 text-red-600 mr-3"}),(0,l.jsx)("h2",{className:"text-xl font-bold text-gray-900",children:n?"Edit Alert":"Add Alert Notice"})]}),(0,l.jsx)("button",{onClick:s,className:"p-1 rounded-lg hover:bg-gray-100 transition-colors",children:(0,l.jsx)(p.A,{className:"w-5 h-5 text-gray-500"})})]}),(0,l.jsxs)("div",{className:"p-6 space-y-4",children:[i&&(0,l.jsx)("div",{className:`${h().bg} border-l-4 ${h().border} rounded-lg p-4 mb-4`,children:(0,l.jsxs)("div",{className:"flex items-start",children:[(0,l.jsx)(le.A,{className:`h-5 w-5 ${h().icon} mr-2 flex-shrink-0 mt-0.5`}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:`text-xs font-bold ${h().headerText} uppercase tracking-wide mb-1`,children:"\u26a0\ufe0f Important Alert"}),(0,l.jsx)("p",{className:`text-sm font-semibold ${h().text}`,children:i})]})]})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Alert Severity"}),(0,l.jsx)("div",{className:"grid grid-cols-2 gap-2",children:x.map(e=>(0,l.jsxs)("button",{type:"button",onClick:()=>c(e.value),className:"p-3 rounded-lg border-2 transition-all text-left "+(d===e.value?`border-${e.color}-500 bg-${e.color}-50`:"border-gray-200 bg-white hover:border-gray-300"),children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,l.jsx)("span",{className:"text-sm font-bold "+(d===e.value?`text-${e.color}-700`:"text-gray-700"),children:e.label}),d===e.value&&(0,l.jsx)("div",{className:`w-4 h-4 rounded-full bg-${e.color}-500`})]}),(0,l.jsx)("span",{className:"text-xs text-gray-600",children:e.description})]},e.value))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Alert Message"}),(0,l.jsx)("textarea",{value:i,onChange:e=>o(e.target.value),placeholder:"Enter the alert message to display on this student's profile...",rows:4,className:"w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent resize-none",maxLength:200}),(0,l.jsxs)("div",{className:"flex justify-between mt-1",children:[(0,l.jsx)("p",{className:"text-xs text-gray-500",children:"This message will be prominently displayed at the top of the student's profile"}),(0,l.jsxs)("p",{className:"text-xs text-gray-500",children:[i.length,"/200"]})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Qu
1ick Templates"}),(0,l.jsx)("div",{className:"flex flex-wrap gap-2",children:[{text:"Do not apply NAR",severity:"critical"},{text:"Do not register for State Exam",severity:"critical"},{text:"Payment plan required",severity:"warning"},{text:"Pending documentation review",severity:"warning"},{text:"Contact before processing",severity:"info"}].map((e,t)=>{var s;null===(s=x.find(t=>t.value===e.severity))||void 0===s||s.color;return(0,l.jsx)("button",{onClick:()=>(e=>{o(e.text),c(e.severity)})(e),className:"px-3 py-1.5 text-xs hover:opacity-80 rounded-md transition-colors border "+("critical"===e.severity?"bg-red-100 border-red-300 text-red-800":"warning"===e.severity?"bg-orange-100 border-orange-300 text-orange-800":"info"===e.severity?"bg-blue-100 border-blue-300 text-blue-800":"bg-gray-100 border-gray-300 text-gray-700"),children:e.text},t)})})]}),(0,l.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3",children:(0,l.jsxs)("p",{className:"text-xs text-blue-800",children:[(0,l.jsx)("strong",{children:"\ud83d\udca1 Tip:"})," Use alerts to highlight important information that all staff should see when viewing this student's profile, such as registration restrictions, payment requirements, or special instructions."]})})]}),(0,l.jsxs)("div",{className:"flex justify-end space-x-3 p-6 border-t border-gray-200 bg-gray-50",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:s,disabled:m,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:async()=>{if(i.trim()){u(!0);try{await r({message:i.trim(),severity:d}),s()}catch(e){console.error("Error saving alert:",e)}finally{u(!1)}}},disabled:!i.trim()||m,className:"critical"===d?"bg-red-600 hover:bg-red-700":"warning"===d?"bg-orange-600 hover:bg-orange-700":"info"===d?"bg-blue-600 hover:bg-blue-700":"bg-green-600 hover:bg-green-700",children:m?"Saving...":n?"Update Alert":"Add Alert"})]})]})}):null};var ce=s(33720),me=s(64725);const ue=e=>{let{student:t,Card:s}=e;const[n,i]=(0,a.useState)([]),[o,d]=(0,a.useState)([]),[m,u]=(0,a.useState)(!1),[x,h]=(0,a.useState)(!1);(0,a.useEffect)(()=>{if(null===t||void 0===t||!t.id)return;u(!1);const e=(0,c.P)((0,c.rJ)(r.db,"courseAttendance"),(0,c._M)("studentId","==",t.id));return(0,c.aQ)(e,e=>{i(e.docs.map(e=>({id:e.id,...e.data()}))),u(!0)},e=>{console.error("Unable to load signed attendance progress:",e),i([]),u(!0)})},[null===t||void 0===t?void 0:t.id]),(0,a.useEffect)(()=>{const e=null===t||void 0===t?void 0:t.scheduleSeriesId,s=null===t||void 0===t?void 0:t.scheduleId;if(h(!1),e){const t=(0,c.P)((0,c.rJ)(r.db,"classSchedules"),(0,c._M)("seriesId","==",e));return(0,c.aQ)(t,e=>{d(e.docs.map(e=>({id:e.id,...e.data()})).filter(e=>"cancelled"!==e.status)),h(!0)},e=>{console.error("Unable to load cohort schedule:",e),d([]),h(!0)})}if(s)return(0,c.aQ)((0,c.H9)(r.db,"classSchedules",s),e=>{const t=e.exists()?{id:e.id,...e.data()}:null;d(t&&"cancelled"!==t.status?[t]:[]),h(!0)},e=>{console.error("Unable to load student schedule:",e),d([]),h(!0)});d([]),h(!0)},[null===t||void 0===t?void 0:t.scheduleId,null===t||void 0===t?void 0:t.scheduleSeriesId]);const g=(0,a.useMemo)(()=>{const e=new Set(o.map(e=>e.id)),t=new Set(n.filter(t=>{var s;return(null===(s=t.studentSignature)||void 0===s?void 0:s.signedAt)&&e.has(t.sessionId)}).map(e=>e.sessionId)),s=e.size,a=t.size,r=s>0?Math.min(100,Math.round(a/s*100)):0;return{total:s,attended:a,remaining:Math.max(0,s-a),percentage:r}},[n,o]),p=!m||!x,b=Math.max(0,100-g.percentage);return(0,l.jsx)(s,{title:"Academic Progress",icon:ce.A,compact:!0,headerAction:(0,l.jsxs)("span",{className:"rounded-full bg-blue-50 px-2 py-1 text-xs font-bold text-blue-700",children:[g.percentage,"% complete"]}),children:p?(0,l.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,l.jsx)("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-blue-600 border-t-transparent"})}):(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"mb-2 flex items-center justify-between text-xs font-medium text-gray-600",children:[(0,l.jsxs)("span",{children:[g.attended," of ",g.total," class days attended"]}),(0,l.jsxs)("span",{children:[g.percentage,"%"]})]}),(0,l.jsx)("div",{className:"h-3 w-full overflow-hidden rounded-full bg-gray-100",children:(0,l.jsx)("div",{className:"h-full rounded-full transition-all duration-500 "+(100===g.percentage?"bg-green-500":"bg-blue-600"),style:{width:`${g.percentage}%`}})}),(0,l.jsx)("p",{className:"mt-2 text-xs text-gray-500",children:"Progress updates automatically from signed attendance."})]}),0===g.total?(0,l.jsx)("div",{className:"border border-gray-200 bg-gray-50 p-3 text-sm text-gray-600",children:"No cohort class days are scheduled for this student yet."}):100===g.percentage?(0,l.jsxs)("div",{className:"flex items-center gap-3 border border-green-200 bg-green-50 p-3",children:[(0,l.jsx)("span",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-green-500",children:(0,l.jsx)(me.A,{className:"h-4 w-4 text-white"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-bold text-green-800",children:"Attendance Complete"}),(0,l.jsx)("p",{className:"text-xs text-green-700",children:"All scheduled class days have been signed."})]})]}):(0,l.jsxs)("div",{className:"border border-amber-200 bg-amber-50 p-3",children:[(0,l.jsxs)("div",{className:"mb-3 flex items-center gap-2",children:[(0,l.jsx)(le.A,{className:"h-4 w-4 text-amber-700"}),(0,l.jsx)("p",{className:"text-sm font-bold text-amber-900",children:"Remaining to Complete"})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,l.jsxs)("div",{className:"border border-amber-100 bg-white px-3 py-2",children:[(0,l.jsx)("p",{className:"text-lg font-bold text-amber-800",children:g.remaining}),(0,l.jsx)("p",{className:"text-[11px] text-amber-700",children:"class days remaining"})]}),(0,l.jsxs)("div",{className:"border border-amber-100 bg-white px-3 py-2",children:[(0,l.jsxs)("p",{className:"text-lg font-bold text-amber-800",children:[b,"%"]}),(0,l.jsx)("p",{className:"text-[11px] text-amber-700",children:"remaining to complete"})]})]})]})]})})};var xe=s(39751),he=s(21946),ge=s(24155),pe=s(88348),be=s(41435),fe=s(77873),ve=s(54114),ye=s(50201),je=s(23615),Ne=s(53399),we=s(63075),Se=s(39818),Ae=s(32406),Ce=s(22896),De=s(93958),ke=s(2765),Ee=s(36923),Pe=s(81714),$e=s(73214),Fe=s(71572),Ie=s(95641),Re=s(37619),Te=s(2599),Me=s(90045),Oe=s(43302),Ue=s(48996),Le=s(16215),Be=s(14776),ze=s(82777),_e=s(67844),He=s(37055),Ge=s(61465),qe=s(14185),Ye=s(75067);const Ve=e=>e?e.split(" ").map(e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"").join(" "):"N/A",Ze=a.memo(e=>{let{status:t,type:s="default"}=e;if(!t)return null;const a="in_accommodation"===t?"In Accommodation":"not_in_accommodation"===t?"Not in Accommodation":"not_started"===t?"Not Started":"in_progress"===t?"In Progress":t.charAt(0).toUpperCase()+t.slice(1),r="completed"===t||"paid"===t;return(0,l.jsxs)("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-xs tracking-wide uppercase border ${(()=>{switch(s){case"payment":return"paid"===t||"completed"===t?"bg-green-100 text-green-900 border-green-300 font-bold":"partial"===t?"bg-amber-100 text-amber-900 border-amber-300 font-bold":"bg-red-100 text-red-900 border-red-300 font-bold";case"course":return"active"===t?"bg-blue-100 text-blue-900 border-blue-300 font-bold":"completed"===t?"bg-green-100 text-green-900 border-green-300 font-bold":"withdrew"===t||"withdrawn"===t||"deleted"===t?"bg-red-100 text-red-900 border-red-300 font-bold":"bg-gray-100 text-gray-900 border-gray-300 font-bold";case"nar":case"cpr":case"certificate":return["completed","approved","active"].includes(t)?"bg-green-100 text-green-900 border-green-400 font-bold":["applied","submitted"].includes(t)?"bg-emerald-100 text-emerald-900 border-emerald-300 font-bold":"in_progress"===t?"bg-amber-100 text-amber-900 border-amber-300 font-bold":"bg-gray-100 text-gray-900 border-gray-300 font-bold";case"accommodation":return"in_accommodation"===t?"bg-blue-100 text-blue-900 border-blue-300 font-bold":"bg-gray-100 text-gray-900 border-gray-300 font-bold";default:return"bg-gray-100 text-gray-900 border-gray-300 font-bold"}})()}`,children:[r&&(0,l.jsx)(me.A,{className:"w-3.5 h-3.5 mr-1"}),a]})}),We=e=>{let{label:t,value:s,icon:a,className:r="",valueClassName:n="",compact:i=!1}=e;return(0,l.jsxs)("div",{className:`flex items-center justify-between ${i?"py-2":"py-2.5"} ${r}`,children:[(0,l.jsxs)("div",{className:"flex items-center text-sm text-slate-700",children:[a&&(0,l.jsx)(a,{className:"w-4 h-4 mr-2 text-slate-500"}),(0,l.jsx)("span",{className:"font-semibold",children:t})]}),(0,l.jsx)("div",{className:`text-sm text-slate-900 text-right max-w-[60%] font-semibold ${n}
1`,children:s||"N/A"})]})},Je=e=>{let{title:t,children:s,className:a="",headerAction:r=null,icon:n,compact:i=!1,bgColor:o="bg-white"}=e;return(0,l.jsxs)("div",{className:`${o} rounded-lg border border-gray-200 shadow-sm hover:shadow-md transition-shadow ${a}`,children:[(0,l.jsx)("div",{className:(i?"px-4 py-3":"px-5 py-3.5")+" border-b border-gray-200 bg-slate-50",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[n&&(0,l.jsx)(n,{className:"w-5 h-5 mr-2 text-slate-700"}),(0,l.jsx)("h3",{className:"text-base font-bold text-slate-900",children:t})]}),r]})}),(0,l.jsx)("div",{className:""+(i?"px-4 py-3":"px-5 py-4"),children:s})]})},Qe=e=>{let{onEdit:t,onDelete:s}=e;const[r,n]=(0,a.useState)(!1);return(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("button",{onClick:()=>n(!r),className:"p-2 rounded-lg hover:bg-gray-100 transition-colors",children:(0,l.jsx)(De.A,{className:"w-5 h-5 text-gray-600"})}),r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>n(!1)}),(0,l.jsxs)("div",{className:"absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg border border-gray-200 z-20",children:[(0,l.jsxs)("button",{onClick:()=>{n(!1),t()},className:"flex items-center w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-50",children:[(0,l.jsx)(ne.A,{className:"w-4 h-4 mr-2"}),"Edit Student"]}),(0,l.jsxs)("button",{onClick:()=>{n(!1),s()},className:"flex items-center w-full px-4 py-2 text-sm text-red-600 hover:bg-red-50",children:[(0,l.jsx)(ie.A,{className:"w-4 h-4 mr-2"}),"Delete Student"]})]})]})]})},Ke=e=>{let{student:t}=e;const[s,r]=(0,a.useState)(()=>Date.now());(0,a.useEffect)(()=>{const e=window.setInterval(()=>r(Date.now()),6e4);return()=>window.clearInterval(e)},[]);const n=new Set(["completed","graduated"]),i=String(t.status||"").toLowerCase(),o=n.has(i),d=t.courseStartDate,c=t.completionDate||t.expectedCompletionDate,m=mt(d),u=mt(c),x=o||Boolean(m&&m.getTime()<=s),g=e=>{const t=Math.max(0,Math.ceil(Math.abs(e)/6e4)),s=Math.floor(t/1440),a=Math.floor(t%1440/60),r=t%60;return s>0?`${s}d ${a}h ${r}m`:a>0?`${a}h ${r}m`:`${r}m`};let p={label:"Waiting for schedule",detail:"No class schedule is linked",tone:"text-slate-600"};["withdrawn","inactive","suspended","onleave"].includes(i)?p={label:"onleave"===i?"On leave":i.charAt(0).toUpperCase()+i.slice(1),detail:"Course progression is paused",tone:"text-amber-700"}:o?p={label:"graduated"===i?"Graduated":"Completed",detail:t.completionDate?(0,M.Yq)(t.completionDate):"Program requirements completed",tone:"text-emerald-700"}:m&&s<m.getTime()?p={label:"Waiting to start",detail:`Starts in ${g(m.getTime()-s)}`,tone:"text-blue-700"}:m&&u&&s<=u.getTime()?p={label:"In progress",detail:`${g(u.getTime()-s)} remaining`,tone:"text-blue-700"}:u&&s>u.getTime()?p={label:"Awaiting completion confirmation",detail:`Scheduled end passed ${g(s-u.getTime())} ago`,tone:"text-amber-700"}:m&&s>=m.getTime()&&(p={label:"In progress",detail:"Waiting for the final scheduled session date",tone:"text-blue-700"});const b=[{label:"Registration",date:t.registrationDate,completed:Boolean(t.registrationDate),icon:h.A,current:!t.registrationDate},{label:"Course Start",date:d,completed:Boolean(x),icon:ce.A,current:Boolean(t.registrationDate&&!x)},{label:o?"Completed":"Expected Completion",date:c,completed:o,icon:ke.A,current:Boolean(x&&!o)}];return(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("div",{className:"absolute left-4 top-0 bottom-0 w-0.5 bg-gray-200"}),(0,l.jsx)("div",{className:"space-y-6",children:b.map((e,t)=>(0,l.jsxs)("div",{className:"relative flex items-start",children:[(0,l.jsx)("div",{className:"absolute left-0 w-8 h-8 rounded-full flex items-center justify-center "+(e.completed?"bg-green-500 text-white":e.current?"bg-blue-500 text-white animate-pulse":"bg-gray-200 text-gray-400"),children:e.completed?(0,l.jsx)(me.A,{className:"w-4 h-4"}):(0,l.jsx)(e.icon,{className:"w-4 h-4"})}),(0,l.jsxs)("div",{className:"ml-12 flex-1",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-sm font-semibold "+(e.completed?"text-slate-800":"text-slate-500"),children:e.label}),(0,l.jsx)("span",{className:"text-sm text-slate-600 font-medium",children:e.date?(0,M.Yq)(e.date):"Pending"})]}),e.current&&(0,l.jsxs)("div",{className:"mt-2 rounded-lg border border-blue-100 bg-blue-50 px-3 py-2",children:[(0,l.jsxs)("span",{className:`inline-flex items-center text-sm font-bold ${p.tone}`,children:[(0,l.jsx)(Ee.A,{className:"mr-1.5 h-4 w-4"}),p.label]}),(0,l.jsx)("p",{className:"mt-0.5 text-xs font-medium text-slate-600",children:p.detail})]})]})]},t))})]})},Xe=e=>{let{isOpen:t,onClose:s,payments:n,student:i,onPaymentEdited:o}=e;const[d,m]=(0,a.useState)(null),[u,x]=(0,a.useState)(""),[h,g]=(0,a.useState)(!1),[p,b]=(0,a.useState)(!1),[f,v]=(0,a.useState)(null),{showToast:y}=(0,C.d)();if(!t)return null;const j=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),N=e=>{if(!e)return"N/A";try{return(null!==e&&void 0!==e&&e.toDate?e.toDate():new Date(e)).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(t){return"Invalid Date"}},w=e=>{let{status:t}=e;const s=(e=>{switch(null===e||void 0===e?void 0:e.toLowerCase()){case"completed":case"paid":default:return{bg:"bg-green-100",text:"text-green-800",label:"COMPLETED"};
1case"pending":return{bg:"bg-yellow-100",text:"text-yellow-800",label:"PENDING"};case"failed":return{bg:"bg-red-100",text:"text-red-800",label:"FAILED"}}})(t);return(0,l.jsx)("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${s.bg} ${s.text}`,children:s.label})},S=n.reduce((e,t)=>e+(t.amount||0),0);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-4xl w-full max-h-[90vh] overflow-hidden",children:[(0,l.jsx)("div",{className:"px-6 py-4 border-b border-gray-200 bg-gray-50",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Payment History"}),(0,l.jsxs)("p",{className:"text-sm text-gray-600 mt-1",children:[null===i||void 0===i?void 0:i.firstName," ",null===i||void 0===i?void 0:i.lastName," \u2022 ",n.length," payments \u2022 Total: ",j(S)]})]}),(0,l.jsx)("button",{onClick:s,className:"text-gray-400 hover:text-gray-600 transition-colors",children:(0,l.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),(0,l.jsx)("div",{className:"overflow-y-auto max-h-[calc(90vh-120px)]",children:n.length>0?(0,l.jsx)("div",{className:"p-6",children:(0,l.jsx)("div",{className:"space-y-3",children:n.map((e,t)=>(0,l.jsx)("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-lg border border-gray-200 hover:bg-gray-100 transition-colors",children:(0,l.jsx)("div",{className:"flex-1",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-lg font-bold text-gray-900",children:j(e.amount)}),(0,l.jsxs)("div",{className:"text-sm text-gray-600 mt-1",children:[N(e.createdAt)," \u2022 ",e.method||e.paymentMethod||"Cash"]}),e.notes&&(0,l.jsx)("div",{className:"text-sm text-gray-500 mt-1",children:e.notes}),e.receiptNumber&&(0,l.jsxs)("div",{className:"text-xs text-gray-400 mt-1",children:["Receipt: ",e.receiptNumber]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(w,{status:e.status||"completed"}),(0,l.jsx)("button",{onClick:()=>(e=>{m(e),x(String(e.amount||0))})(e),className:"p-1.5 rounded-md text-gray-500 hover:text-blue-600 hover:bg-blue-50 transition-colors",title:"Edit amount","aria-label":"Edit payment amount",children:(0,l.jsx)(ne.A,{className:"w-4 h-4"})})]})]})})},e.id||t))})}):(0,l.jsxs)("div",{className:"p-6 text-center text-gray-500",children:[(0,l.jsx)(Pe.A,{className:"w-12 h-12 mx-auto mb-4 text-gray-300"}),(0,l.jsx)("p",{className:"text-lg font-semibold",children:"No payment history"}),(0,l.jsx)("p",{className:"text-sm mt-1",children:"Payments will appear here once recorded"})]})}),(0,l.jsx)("div",{className:"px-6 py-4 border-t border-gray-200 bg-gray-50",children:(0,l.jsx)("div",{className:"flex justify-end",children:(0,l.jsx)("button",{onClick:s,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors",children:"Close"})})})]})}),d&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-[60]",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-6",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Edit Payment Amount"}),(0,l.jsxs)("p",{className:"text-sm text-gray-600 mb-2",children:[N(d.createdAt)," \u2022 ",d.receiptNumber||"No receipt"]}),(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Amount ($)"}),(0,l.jsx)("input",{type:"number",step:"0.01",min:"0",value:u,onChange:e=>x(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"0.00"})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,l.jsx)("button",{onClick:()=>m(null),className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50",children:"Cancel"}),(0,l.jsx)("button",{onClick:()=>
1{if(!d||null===i||void 0===i||!i.id)return;const e=parseFloat(u);isNaN(e)||e<0?y("Please enter a valid amount","error"):Math.abs(e-(d.amount||0))<.01?m(null):(v({payment:d,amount:e}),m(null),b(!0))},disabled:h,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",children:h?"Saving...":"Save"})]})]})}),(0,l.jsx)(te.A,{isOpen:p,onClose:()=>{b(!1),v(null)},onSuccess:()=>{b(!1),f&&(async(e,t)=>{if(e&&null!==i&&void 0!==i&&i.id){g(!0);try{const s=(0,c.H9)(r.db,"payments",e.id);await(0,c.mZ)(s,{amount:t}),await(0,R.Y2)(i.id),y("Payment amount updated successfully","success"),v(null),b(!1),null===o||void 0===o||o()}catch(s){console.error("Error updating payment:",s),y(s.message||"Failed to update payment","error")}finally{g(!1)}}})(f.payment,f.amount)},title:"Edit Payment Authentication"})]})},et=e=>{let{isOpen:t,onClose:s,student:n,onChargeAdded:i}=e;const[o,d]=(0,a.useState)({description:"",amount:"",date:(0,X.GP)(new Date,"MM/dd/yyyy")}),[m,u]=(0,a.useState)(!1),{showToast:x}=(0,C.d)();return t?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md",children:[(0,l.jsxs)("div",{className:"bg-blue-600 text-white px-6 py-4 rounded-t-lg flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold",children:"ADD NEW CHARGE"}),(0,l.jsx)("button",{onClick:s,className:"p-1 hover:bg-blue-700 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),!o.description||!o.amount||parseFloat(o.amount)<=0)x("Please fill in all required fields with valid values","error");else{u(!0);try{var t,a;const e={description:o.description,amount:parseFloat(o.amount),date:o.date,type:"additional",status:"pending",createdAt:(new Date).toISOString(),createdBy:"admin"},l=(null===(t=n.paymentDetails)||void 0===t?void 0:t.charges)||[],m=(0,T.q5)(n)+parseFloat(o.amount),u=(null===(a=n.paymentDetails)||void 0===a?void 0:a.totalPaid)||0,h=m-u;if(await(0,c.mZ)((0,c.H9)(r.db,"students",n.id),{"paymentDetails.charges":[...l,e],"paymentDetails.totalAmount":m,"paymentDetails.balance":h,"paymentDetails.paymentStatus":h>0?"partial":"paid",updatedAt:(0,c.O5)()}),x("Charge added successfully","success"),i&&i(),s(),d({description:"",amount:"",date:(0,X.GP)(new Date,"MM/dd/yyyy")}),n.email){const t=[...l,e];(0,Y.jZ)({studentId:n.id,studentName:n.fullName||`${n.firstName||""} ${n.lastName||""}`.trim(),studentEmail:n.email,newCharge:e,chargesBreakdown:t.map(e=>({description:e.description,amount:e.amount,date:e.date})),newTotalAmount:m,totalPaid:u,newBalance:h}).catch(e=>{console.error("Failed to send charge added email:",e),x("Charge added but email notification failed","error")})}}catch(l){console.error("Error adding charge:",l),x("Error adding charge","error")}finally{u(!1)}}},className:"p-6 space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Description ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsx)("input",{type:"text",value:o.description,onChange:e=>d({...o,description:e.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"e.g. Phone or program registration",required:!0})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Amount ($) ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsx)("input",{type:"number",step:"0.01",value:o.amount,onChange:e=>d({...o,amount:e.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"0.00",required:!0})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Date ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{type:"text",value:o.date,onChange:e=>d({...o,date:e.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 pr-10",placeholder:"MM/DD/YYYY",required:!0}),(0,l.jsx)(Q.A,{className:"absolute right-3 top-3.5 h-5 w-5 text-gray-400"})]})]}),(0,l.jsxs)("div",{className:"pt-4 space-y-3",children:[(0,l.jsxs)(U.$,{type:"submit",className:"w-full bg-gray-600 hover:bg-gray-700 text-white py-3 rounded-md font-medium flex items-center justify-center",disabled:m,children:[(0,l.jsx)(re.A,{className:"w-5 h-5 mr-2"}),m?"Adding Charge...":"Add Charge"]}),(0,l.jsx)(U.$,{type:"button",variant:"outline",onClick:s,className:"w-full",children:"Cancel"})]})]})]})}):null},tt=e=>{var t,s,n,i,o,d;let{isOpen:c,onClose:m,student:u,onSave:x}=e;const[h,g]=(0,a.useState)([]),[p,b]=(0,a.useState)({programId:(null===u||void 0===u?void 0:u.programId)||"cna-traditional",fullName:(null===u||void 0===u?void 0:u.fullName)||"",email:(null===u||void 0===u?void 0:u.email)||"",phoneNumber:(null===u||void 0===u?void 0:u.phoneNumber)||"",countryOfOrigin:(null===u||void 0===u?void 0:u.countryOfOrigin)||"",emergencyContact:(null===u||void 0===u?void 0:u.emergencyContact)||"",gender:(null===u||void 0===u?void 0:u.gender)||"",dateOfBirth:(null===u||void 0===u?void 0:u.dateOfBirth)||"",address:{addressLine1:(null===u||void 0===u||null===(t=u.address)||void 0===t?void 0:t.addressLine1)||(null===u||void 0===u?void 0:u.streetAddress)||"",addressLine2:(null===u||void 0===u||null===(s=u.address)||void 0===s?void 0:s.addressLine2)||(null===u||void 0===u?void 0:u.addressLine2)||"",city:(null===u||void 0===u||null===(n=u.address)||void 0===n?void 0:n.city)||(null===u||void 0===u?void 0:u.city)||"",state:(null===u||void 0===u||null===(i=u.address)||void 0===i?void 0:i.state)||(null===u||void 0===u?void 0:u.state)||"",postalCode:(null===u||void 0===u||null===(o=u.address)||void 0===o?void 0:o.postalCode)||(null===u||void 0===u?void 0:u.postalCode)||(null===u||void 0===u?void 0:u.zipCode)||"",country:(null===u||void 0===u||null===(d=u.address)||void 0===d?void 0:d.country)||""}}),[f,v]=(0,a.useState)(!1),{showToast:y}=(0,C.d)();(0,a.useEffect)(()=>{var e,t,s,a,r,l;c&&u&&b({programId:u.programId||"cna-traditional",fullName:u.fullName||"",email:u.email||"",phoneNumber:u.phoneNumber||"",countryOfOrigin:u.countryOfOrigin||"",emergencyContact:u.emergencyContact||"",gender:u.gender||"",dateOfBirth:u.dateOfBirth||"",address:{addressLine1:(null===(e=u.address)||void 0===e?void 0:e.addressLine1)||u.streetAddress||"",addressLine2:(null===(t=u.address)||void 0===t?void 0:t.addressLine2)||u.addressLine2||"",city:(null===(s=u.address)||void 0===s?void 0:s.city)||u.city||"",state:(null===(a=u.address)||void 0===a?void 0:a.state)||u.state||"",postalCode:(null===(r=u.address)||void 0===r?void 0:r.postalCode)||u.postalCode||u.zipCode||"",country:(null===(l=u.address)||void 0===l?void 0:l.country)||""}})},[c,u]),(0,a.useEffect)(()=>{c&&(0,_.Sc)({fresh:!0}).then(e=>g((e.programs||[]).filter(e=>!1!==e.enabled))).catch(e=>{console.error("Could not load configured programs:",e),g([])})},[c]);const j=(e,t)=>{b(s=>({...s,address:{...s.address,[e]:t}}))};return c?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[(0,l.jsx)("div",{className:"px-6 py-4 border-b border-slate-200",children:(0,l.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Edit Student Information"})}),(0,l.jsxs)("div",{className:"px-6 py-4 space-y-4",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Enrolled Program"}),(0,l.jsxs)("select",{value:p.programId,onChange:e=>b({...p,programId:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[!h.some(e=>e.id===p.programId)&&(0,l.jsx)("option",{value:p.programId,children:u.courseType||u.programName||"Current program"}),h.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,l.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"Changing this updates the student profile and linked enrollment."})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Full Name"}),(0,l.jsx)("input",{type:"text",value:p.fullName,onChange:e=>b({...p,fullName:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Email"}),(0,l.jsx)("input",{type:"email",value:p.email,onChange:e=>b({...p,email:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Phone Number"}),(0,l.jsx)("input",{type:"tel",value:p.phoneNumber,onChange:e=>b({...p,phoneNumber:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Gender"}
1),(0,l.jsxs)("select",{value:p.gender,onChange:e=>b({...p,gender:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[(0,l.jsx)("option",{value:"",children:"Select Gender"}),(0,l.jsx)("option",{value:"male",children:"Male"}),(0,l.jsx)("option",{value:"female",children:"Female"}),(0,l.jsx)("option",{value:"other",children:"Other"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Date of Birth"}),(0,l.jsx)("input",{type:"date",value:p.dateOfBirth,onChange:e=>b({...p,dateOfBirth:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Country of Origin"}),(0,l.jsx)("input",{type:"text",value:p.countryOfOrigin,onChange:e=>b({...p,countryOfOrigin:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Emergency Contact"}),(0,l.jsx)("input",{type:"text",value:p.emergencyContact,onChange:e=>b({...p,emergencyContact:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{className:"col-span-2 border-t border-slate-200 pt-4 mt-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,l.jsx)($e.A,{className:"w-5 h-5 text-blue-600"}),(0,l.jsx)("h4",{className:"text-base font-semibold text-slate-900",children:"Address"})]}),(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"Residential or mailing address"})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Street Address"}),(0,l.jsx)("input",{type:"text",value:p.address.addressLine1,onChange:e=>j("addressLine1",e.target.value),placeholder:"House number and street name",className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Apartment, Suite, or Unit"}),(0,l.jsx)("input",{type:"text",value:p.address.addressLine2,onChange:e=>j("addressLine2",e.target.value),placeholder:"Optional",className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"City"}),(0,l.jsx)("input",{type:"text",value:p.address.city,onChange:e=>j("city",e.target.value),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"State / Province"}),(0,l.jsx)("input",{type:"text",value:p.address.state,onChange:e=>j("state",e.target.value),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"ZIP / Postal Code"}),(0,l.jsx)("input",{type:"text",value:p.address.postalCode,onChange:e=>j("postalCode",e.target.value),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Country"}),(0,l.jsx)("input",{type:"text",value:p.address.country,onChange:e=>j("country",e.target.value),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]}),(0,l.jsxs)("div",{className:"flex space-x-3 pt-4",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:m,className:"flex-1",disabled:f,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:async()=>{v(!0);try{const{programId:e,...t}=p,s={...t,fullName:t.fullName.trim(),email:t.email.trim().toLowerCase(),phoneNumber:t.phoneNumber.trim(),address:Object.fromEntries(Object.entries(p.address).map(e=>{let[t,s]=e;return[t,s.trim()]}))},a=await(0,r.Ij)("updateStudentInformation",{studentId:u.id,student:s});if(null===a||void 0===a||!a.success)throw new Error("The student record was not saved.");e!==(u.programId||"cna-traditional")&&await(0,r.Ij)("changeStudentProgram",{studentId:u.id,programId:e}),await(null===x||void 0===x?void 0:x()),y("Student information saved"+(s.email!==u.email?` \u2014 email updated to ${s.email}`:""),"success"),m()}catch(e){console.error("Error updating student:",e),y(e.message||"Error updating student information","error")}finally{v(!1)}},className:"flex-1 bg-blue-600 hover:bg-blue-700",disabled:f,children:f?"
1Saving...":"Save Changes"})]})]})]})}):null},st=e=>{let{isOpen:t,onClose:s,onConfirm:a,studentName:r,isDeleting:n}=e;return t?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsx)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md",children:(0,l.jsxs)("div",{className:"px-6 py-4",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-3 mb-4",children:[(0,l.jsx)(Fe.A,{className:"w-8 h-8 text-red-500"}),(0,l.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Delete Student"})]}),(0,l.jsxs)("p",{className:"text-slate-600 mb-6",children:["Are you sure you want to delete ",(0,l.jsx)("strong",{children:r}),"? This action cannot be undone."]}),(0,l.jsxs)("div",{className:"flex space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:s,className:"flex-1",disabled:n,children:"Cancel"}),(0,l.jsx)(U.$,{variant:"danger",onClick:a,className:"flex-1",disabled:n,children:n?"Deleting...":"Delete Student"})]})]})})}):null},at=e=>{let{isOpen:t,onClose:s,student:n,employerToEdit:i}=e;const[o,d]=(0,a.useState)(!1),{showToast:m}=(0,C.d)(),[u,x]=(0,a.useState)({employerName:"",phone:"",location:"",isCurrent:!0});(0,a.useEffect)(()=>{x(i?{employerName:i.employerName||"",phone:i.phone||"",location:i.location||"",isCurrent:i.isCurrent||!1}:{employerName:"",phone:"",location:"",isCurrent:!0})},[i,t]);return t?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[(0,l.jsx)("div",{className:"px-6 py-4 border-b border-slate-200",children:(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsx)(Ie.A,{className:"w-6 h-6 text-blue-600"}),(0,l.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:i?"Edit Employment Information":"Add New Employer"})]})}),(0,l.jsxs)("div",{className:"px-6 py-4 space-y-4",children:[(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:["Employer Name ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsx)("input",{type:"text",value:u.employerName,onChange:e=>x({...u,employerName:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Enter employer name"})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Phone Number"}),(0,l.jsx)("input",{type:"tel",value:u.phone,onChange:e=>x({...u,phone:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Enter phone number"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"Location"}),(0,l.jsx)("input",{type:"text",value:u.location,onChange:e=>x({...u,location:e.target.value}),className:"w-full px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"City, State"})]})]}),(0,l.jsx)("div",{children:(0,l.jsxs)("label",{className:"flex items-center space-x-2",children:[(0,l.jsx)("input",{type:"checkbox",checked:u.isCurrent,onChange:e=>x({...u,isCurrent:e.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),(0,l.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"This is the current employer"})]})})]}),(0,l.jsxs)("div",{className:"flex space-x-3 pt-4",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:s,className:"flex-1",disabled:o,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:async()=>{if(u.employerName.trim()){d(!0);try{const e=n.employmentHistory||[];let t;if(u.isCurrent){const s=e.map(e=>({...e,isCurrent:!1}));t=[{...u,isCurrent:!0,addedAt:(new Date).toISOString()},...s]}else t=[...e,{...u,isCurrent:!1,addedAt:(new Date).toISOString()}];await(0,c.mZ)((0,c.H9)(r.db,"students",n.id),{employmentHistory:t,updatedAt:(0,c.O5)()}),m("Employment information saved successfully","success"),s(),window.location.reload()}catch(e){console.error("Error saving employment:",e),m("Error saving employment information","error")}finally{d(!1)}}else m("Please enter employer name","error")},className:"flex-1 bg-blue-600 hover:bg-blue-700",disabled:o,children:o?"Saving...":"Save Employment"})]})]})]})}):null},rt=e=>{var t,s,n;let{isOpen:i,onClose:o,student:m}=e;
1const[u,x]=(0,a.useState)(""),[h,g]=(0,a.useState)(""),[b,f]=(0,a.useState)([]),[v,y]=(0,a.useState)([]),[j,N]=(0,a.useState)(!1),[w,S]=(0,a.useState)(!1),[A,D]=(0,a.useState)(""),{showToast:k}=(0,C.d)();(0,a.useEffect)(()=>{if(i){f([]),S(!1),x(""),g(""),D("");(async()=>{N(!0);try{const e=(await(0,c.x7)((0,c.H9)(r.db,"students",m.id))).data();y((null===e||void 0===e?void 0:e.documents)||[])}catch(e){console.error("Error loading student documents:",e),y([])}finally{N(!1)}})()}},[i,m.id]);const E=e=>{if(!e)return"";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(1))+" "+["Bytes","KB","MB"][t]};if(!i)return null;const P=((null===m||void 0===m||null===(t=m.paymentDetails)||void 0===t?void 0:t.totalAmount)||0)-((null===m||void 0===m||null===(s=m.paymentDetails)||void 0===s?void 0:s.totalPaid)||0);return(0,l.jsx)("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:(0,l.jsxs)("div",{className:"flex items-center justify-center min-h-screen p-4",children:[(0,l.jsx)("div",{className:"fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity",onClick:o}),(0,l.jsxs)("div",{className:"relative bg-white rounded-xl shadow-2xl max-w-lg w-full max-h-[90vh] flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 bg-gradient-to-r from-blue-600 to-blue-700 rounded-t-xl flex-shrink-0",children:[(0,l.jsxs)("h3",{className:"text-lg font-bold text-white flex items-center",children:[(0,l.jsx)(Re.A,{className:"w-5 h-5 mr-2"}),"Send Documents to Employer"]}),(0,l.jsx)("button",{onClick:o,className:"text-white/80 hover:text-white transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6 overflow-y-auto",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-5 p-3 bg-gray-50 rounded-lg",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-700 font-bold text-sm",children:null===(n=((null===m||void 0===m?void 0:m.fullName)||"?")[0])||void 0===n?void 0:n.toUpperCase()}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-800",children:Ve(null===m||void 0===m?void 0:m.fullName)}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:(null===m||void 0===m?void 0:m.email)||"No email on file"})]})]}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700 mb-1.5",children:["Employer Email Address ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)(Re.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),(0,l.jsx)("input",{type:"email",value:u,onChange:e=>x(e.target.value),className:"w-full border border-gray-300 rounded-lg pl-10 pr-3 py-2.5 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"[email protected]"})]})]}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsxs)("label",{htmlFor:"employer-document-phone",className:"block text-sm font-semibold text-slate-700 mb-1.5",children:["Employer Phone Number ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,l.jsx)("input",{id:"employer-document-phone",type:"tel",required:!0,autoComplete:"tel",value:h,onChange:e=>g(e.target.value),className:"w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"e.g. +1 206 555 0123"}),(0,l.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"Saved with the recipient email in Employment History."})]}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700",children:["Select Documents to Send ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),v.length>0&&(0,l.jsx)("button",{onClick:()=>{b.length===v.length?f([]):f(v.map(e=>e.id))},className:"text-xs text-blue-600 hover:text-blue-800 font-semibold transition-colors",children:b.length===v.length?"Deselect All":"Select All"})]}),(0,l.jsx)("div",{className:"space-y-1 max-h-52 overflow-y-auto border border-gray-200 rounded-lg p-2",children:j?(0,l.jsxs)("div",{className:"flex items-center justify-center py-6 text-sm text-gray-500",children:[(0,l.jsxs)("svg",{className:"animate-spin mr-2 h-4 w-4 text-blue-500",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Loading documents..."]}):0===v.length?(0,l.jsxs)("div",{className:"text-center py-6",children:[(0,l.jsx)(he.A,{className:"w-8 h-8 text-gray-300 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm text-gray-500",children:"No documents uploaded for this student."}),(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Upload documents in the Academic Progress tab first."})]}):v.map(e=>(0,l.jsxs)("label",{className:"flex items-center p-2.5 rounded-lg cursor-pointer transition-colors "+(b.includes(e.id)?"bg-blue-50 border border-blue-200":"hover:bg-gray-50 border border-transparent"),children:[(0,l.jsx)("input",{type:"checkbox",checked:b.includes(e.id),onChange:()=>{return t=e.id,void f(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);var t},className:"h-4 w-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500"}),(0,l.jsxs)("div",{className:"ml-3 flex-1 min-w-0",children:[(0,l.jsx)("span",{className:"text-sm font-medium text-slate-800 truncate block",children:e.name}),(0,l.jsxs)("span",{className:"text-xs text-slate-400",children:[E(e.size),` \u2022 Uploaded: ${(0,d.Nl)(e.uploadedAt)}`]})]})]},e.id))})]}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700 mb-1.5",children:["Note to Employer ",(0,l.jsx)("span",{className:"text-gray-400 font-normal",children:"(optional)"})]}),(0,l.jsx)("textarea",{value:A,onChange:e=>D(e.target.value),rows:3,className:"w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors resize-none placeholder-gray-400",placeholder:"e.g. Please find attached the training certificates for the above student. Feel free to contact us for any verification..."})]}),b.length>0&&(0,l.jsxs)("div",{className:"mb-5 p-3 bg-blue-50 rounded-lg border border-blue-100",children:[(0,l.jsx)("p",{className:"text-xs font-bold text-blue-800 uppercase tracking-wide mb-1",children:"Email Preview"}),(0,l.jsxs)("p",{className:"text-sm text-slate-700",children:["Sending ",(0,l.jsx)("strong",{children:b.length})," document",b.length>
11?"s":""," for ",(0,l.jsx)("strong",{children:Ve(null===m||void 0===m?void 0:m.fullName)}),u?(0,l.jsxs)(l.Fragment,{children:[" to ",(0,l.jsx)("strong",{children:u})]}):""]}),P>0&&(0,l.jsxs)("p",{className:"text-xs text-amber-700 mt-1.5 flex items-center",children:[(0,l.jsx)(le.A,{className:"w-3.5 h-3.5 mr-1 flex-shrink-0"}),"Email will include a note about outstanding tuition balance (amount not disclosed)."]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("button",{onClick:o,disabled:w,className:"flex-1 px-4 py-2.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors disabled:opacity-50",children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{if(u.trim())if(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))if(0!==b.length)if(/^[+\d() .-]+$/.test(h.trim())&&/^\d{7,15}$/.test(h.replace(/\D/g,""))){S(!0);try{const e=v.filter(e=>b.includes(e.id));await(0,Y.o0)({studentId:m.id,employerEmail:u.trim(),employerPhone:h.trim(),recipientType:"employer",selectedDocuments:e.map(e=>({name:e.name,storagePath:e.storagePath,type:e.type||"application/pdf"})),note:A.trim()}),k(`Documents sent successfully to ${u}`,"success"),o()}catch(e){console.error("Error sending certificates:",e),k(e.message||"Failed to send documents.","error")}finally{S(!1)}}else k("Please enter a valid employer phone number (7\u201315 digits).","error");else k("Please select at least one document","error");else k("Please enter a valid email address","error");else k("Please enter employer email address","error")},disabled:w||0===b.length||!u.trim()||!h.trim(),className:"flex-1 px-4 py-2.5 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",children:w?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Sending..."]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Re.A,{className:"w-4 h-4 mr-1.5"}),"Send Documents"]})})]})]})]})]})})},lt=e=>{var t;let{isOpen:s,onClose:n,student:i}=e;const[o,m]=(0,a.useState)([]),[u,x]=(0,a.useState)([]),[h,g]=(0,a.useState)(!1),[b,f]=(0,a.useState)(!1),{showToast:v}=(0,C.d)();(0,a.useEffect)(()=>{if(s){m([]),f(!1);(async()=>{g(!0);try{const e=(await(0,c.x7)((0,c.H9)(r.db,"students",i.id))).data();x((null===e||void 0===e?void 0:e.documents)||[])}catch(e){console.error("Error loading student documents:",e),x([])}finally{g(!1)}})()}},[s,i.id]);const y=e=>{if(!e)return"";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(1))+" "+["Bytes","KB","MB"][t]};return s?(0,l.jsx)("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:(0,l.jsxs)("div",{className:"flex items-center justify-center min-h-screen p-4",children:[(0,l.jsx)("div",{className:"fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity",onClick:n}),(0,l.jsxs)("div",{className:"relative bg-white rounded-xl shadow-2xl max-w-lg w-full",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 bg-gradient-to-r from-green-600 to-green-700 rounded-t-xl",children:[(0,l.jsxs)("h3",{className:"text-lg font-bold text-white flex items-center",children:[(0,l.jsx)(Re.A,{className:"w-5 h-5 mr-2"}),"Send Documents to Student"]}),(0,l.jsx)("button",{onClick:n,className:"text-white/80 hover:text-white transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-5 p-3 bg-gray-50 rounded-lg",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-700 font-bold text-sm",children:null===(t=((null===i||void 0===i?void 0:i.fullName)||"?")[0])||void 0===t?void 0:t.toUpperCase()}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-800",children:Ve(null===i||void 0===i?void 0:i.fullName)}),(0,l.jsxs)("p",{className:"text-xs text-slate-500",children:["Sending to: ",null===i||void 0===i?void 0:i.email]})]})]}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("label",{className:"block text-sm font-semibold text-slate-700",children:["Select Documents to Send ",(0,l.jsx)("span",{className:"text-red-500",children:"*"})]}),u.length>0&&(0,l.jsx)("button",{onClick:()=>{o.length===u.length?m([]):m(u.map(e=>e.id))},className:"text-xs text-green-600 hover:text-green-800 font-semibold transition-colors",children:o.length===u.length?"Deselect All":"Select All"})]}),(0,l.jsx)("div",{className:"space-y-1 max-h-52 overflow-y-auto border border-gray-200 rounded-lg p-2",children:h?(0,l.jsxs)("div",{className:"flex items-center justify-center py-6 text-sm text-gray-500",children:[(0,l.jsxs)("svg",{className:"animate-spin mr-2 h-4 w-4 text-green-500",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Loading documents..."]}):0===u.length?(0,l.jsxs)("div",{className:"text-center py-6",children:[(0,l.jsx)(he.A,{className:"w-8 h-8 text-gray-300 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm text-gray-500",children:"No documents uploaded for this student."})]}):u.map(e=>(0,l.jsxs)("label",{className:"flex items-center p-2.5 rounded-lg cursor-pointer transition-colors "+(o.includes(e.id)?"bg-green-50 border border-green-200":"hover:bg-gray-50 border border-transparent"),children:[(0,l.jsx)("input",{type:"checkbox",checked:o.includes(e.id),onChange:()=>{return t=e.id,void m(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);var t},className:"h-4 w-4 text-green-600 rounded border-gray-300 focus:ring-green-500"}),(0,l.jsxs)("div",{className:"ml-3 flex-1 min-w-0",children:[(0,l.jsx)("span",{className:"text-sm font-medium text-slate-800 truncate block",children:e.name}),(0,l.jsxs)("span",{className:"text-xs text-slate-400",children:[y(e.size),` \u2022 Uploaded: ${(0,d.Nl)(e.uploadedAt)}`]})]})]},e.id))})]}),o.length>0&&(0,l.jsxs)("div",{className:"mb-5 p-3 bg-green-50 rounded-lg border border-green-100",children:[(0,l.jsx)("p",{className:"text-xs font-bold text-green-800 uppercase tracking-wide mb-1",children:"Email Preview"}),(0,l.jsxs)("p",{className:"text-sm text-slate-700",children:["Sending ",(0,l.jsx)("strong",{children:o.length})," document",o.length>
11?"s":""," to ",(0,l.jsx)("strong",{children:null===i||void 0===i?void 0:i.email})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("button",{onClick:n,disabled:b,className:"flex-1 px-4 py-2.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors disabled:opacity-50",children:"Cancel"}),(0,l.jsx)("button",{onClick:async()=>{if(0!==o.length){f(!0);try{const e=u.filter(e=>o.includes(e.id));await(0,Y.o0)({studentId:i.id,employerEmail:i.email,recipientType:"student",selectedDocuments:e.map(e=>({name:e.name,storagePath:e.storagePath,type:e.type||"application/pdf"}))}),v(`Documents sent successfully to ${i.email}`,"success"),n()}catch(e){console.error("Error sending documents to student:",e),v(e.message||"Failed to send documents.","error")}finally{f(!1)}}else v("Please select at least one document","error")},disabled:b||0===o.length,className:"flex-1 px-4 py-2.5 text-sm font-medium text-white bg-green-600 rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",children:b?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Sending..."]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Re.A,{className:"w-4 h-4 mr-1.5"}),"Send to Student"]})})]})]})]})]})}):null},nt=e=>{let{student:t,onAddEmployment:s,onEditEmployment:a}=e;const r=t.employmentHistory||[],n=r.find(e=>e.isCurrent),o=r.filter(e=>!e.isCurrent);return(0,l.jsx)(Je,{title:"Employment History",icon:Ie.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:[n?(0,l.jsxs)("div",{className:"p-3 bg-blue-50 rounded-lg border border-blue-200",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(Te.A,{className:"w-4 h-4 text-blue-600 mr-2"}),(0,l.jsx)("h4",{className:"text-base font-bold text-slate-800",children:"Current Employer"})]}),(0,l.jsx)("span",{className:"text-xs font-semibold text-blue-700 bg-blue-100 px-2 py-1 rounded",children:"CURRENT"})]}),(0,l.jsxs)("div",{className:"space-y-2 mt-3",children:[(0,l.jsxs)("div",{className:"flex items-start",children:[(0,l.jsx)(Te.A,{className:"w-4 h-4 text-slate-600 mr-2 mt-0.5"}),(0,l.jsx)("div",{className:"text-sm font-bold text-slate-900",children:n.employerName})]}),n.phone&&(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(Me.A,{className:"w-4 h-4 text-slate-600 mr-2"}),(0,l.jsx)("a",{href:`tel:${n.phone}`,className:"text-sm text-blue-600 hover:underline",children:n.phone})]}),n.location&&(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)($e.A,{className:"w-4 h-4 text-slate-600 mr-2"}),(0,l.jsx)("span",{className:"text-sm text-slate-700",children:n.location})]})]})]}):(0,l.jsxs)("div",{className:"p-4 bg-slate-50 rounded-lg border border-slate-200 text-center",children:[(0,l.jsx)(Ie.A,{className:"w-8 h-8 text-slate-400 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm text-slate-600",children:"No employment information"})]}),o.length>0&&(0,l.jsxs)("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-200",children:[(0,l.jsx)("h5",{className:"text-xs font-bold text-slate-700 uppercase mb-2",children:"Previous Employers"}),(0,l.jsx)("div",{className:"space-y-2",children:o.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center justify-between text-sm p-2 bg-white rounded",children:[(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("div",{className:"font-semibold text-slate-900",children:e.employerName}),e.location&&(0,l.jsx)("div",{className:"text-xs text-slate-600",children:e.location})]}),(0,l.jsx)("button",{onClick:()=>a(e),className:"text-blue-600 hover:text-blue-700 ml-2",children:(0,l.jsx)(ge.A,{className:"w-4 h-4"})})]},t))})]}),(0,l.jsx)(i,{student:t}),(0,l.jsxs)("div",{className:"flex space-x-2",children:[(0,l.jsxs)(U.$,{size:"sm",variant:"outline",onClick:s,className:"flex-1 text-sm",children:[(0,l.jsx)(re.A,{className:"w-4 h-4 mr-1"}),n?"Add New Employer":"Add Employer"]}),n&&(0,l.jsxs)(U.$,{size:"sm",variant:"outline",onClick:()=>a(n),className:"flex-1 text-sm",children:[(0,l.jsx)(ne.A,{className:"w-4 h-4 mr-1"}),"Edit Current"]})]})]})})},it=e=>{let{student:t,onPhotoUpload:s,alert:a}=e;return(0,l.jsx)(Je,{title:"Personal Information",icon:h.A,compact:!0,bgColor:(()=>
1{if(!a)return"bg-white";switch(a.severity){case"critical":return"bg-red-50";case"warning":return"bg-orange-50";case"info":return"bg-blue-50";case"success":return"bg-green-50";default:return"bg-white"}})(),className:a?(()=>{if(!a)return"";switch(a.severity){case"critical":return"border-red-300";case"warning":return"border-orange-300";case"info":return"border-blue-300";case"success":return"border-green-300";default:return""}})():"",children:(0,l.jsxs)("div",{className:"space-y-4",children:[a&&(0,l.jsx)("div",{className:"rounded-lg p-3 mb-3 border-2 "+("critical"===a.severity?"bg-red-100 border-red-400":"warning"===a.severity?"bg-orange-100 border-orange-400":"info"===a.severity?"bg-blue-100 border-blue-400":"success"===a.severity?"bg-green-100 border-green-400":"bg-red-100 border-red-400"),children:(0,l.jsxs)("div",{className:"flex items-start",children:[(0,l.jsx)(le.A,{className:"h-5 w-5 mr-2 flex-shrink-0 mt-0.5 "+("critical"===a.severity?"text-red-700":"warning"===a.severity?"text-orange-700":"info"===a.severity?"text-blue-700":"success"===a.severity?"text-green-700":"text-red-700")}),(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("p",{className:"text-xs font-bold uppercase tracking-wide mb-1 "+("critical"===a.severity?"text-red-900":"warning"===a.severity?"text-orange-900":"info"===a.severity?"text-blue-900":"success"===a.severity?"text-green-900":"text-red-900"),children:"\u26a0\ufe0f ALERT"}),(0,l.jsx)("p",{className:"text-sm font-semibold "+("critical"===a.severity?"text-red-900":"warning"===a.severity?"text-orange-900":"info"===a.severity?"text-blue-900":"success"===a.severity?"text-green-900":"text-red-900"),children:a.message})]})]})}),(0,l.jsx)(b,{student:t,displayName:Ve(t.fullName),onPhotoUpload:s}),(0,l.jsxs)("div",{className:"grid grid-cols-1 gap-0.5 divide-y divide-gray-100",children:[(0,l.jsx)(We,{label:"Email",value:t.email?(0,l.jsx)("a",{href:`mailto:${t.email}`,className:"text-blue-600 hover:underline font-medium",children:t.email}):"N/A",icon:Re.A,compact:!0}),(0,l.jsx)(We,{label:"Phone",value:t.phoneNumber?(0,l.jsx)("a",{href:`tel:${t.phoneNumber}`,className:"text-blue-600 hover:underline font-medium",children:(0,M.n4)(t.phoneNumber)}):"N/A",icon:Me.A,compact:!0}),(0,l.jsx)(We,{label:"Gender",value:t.gender,icon:h.A,compact:!0}),(0,l.jsx)(We,{label:"Age",value:t.dateOfBirth?(0,q.nV)(t.dateOfBirth):"Not provided (click Edit to add)",icon:Oe.A,compact:!0}),(0,l.jsx)(We,{label:"Country",value:t.countryOfOrigin,icon:$e.A,compact:!0}),(0,l.jsx)(We,{label:"Emergency Contact",value:t.emergencyContact,icon:Me.A,valueClassName:"text-orange-600 font-bold",compact:!0})]})]})})},ot=e=>{var t,s,a,r,n,i;let{student:o}=e;const d={addressLine1:(null===(t=o.address)||void 0===t?void 0:t.addressLine1)||o.streetAddress||"",addressLine2:(null===(s=o.address)||void 0===s?void 0:s.addressLine2)||o.addressLine2||"",city:(null===(a=o.address)||void 0===a?void 0:a.city)||o.city||"",state:(null===(r=o.address)||void 0===r?void 0:r.state)||o.state||"",postalCode:(null===(n=o.address)||void 0===n?void 0:n.postalCode)||o.postalCode||o.zipCode||"",country:(null===(i=o.address)||void 0===i?void 0:i.country)||""},c=Object.values(d).some(e=>String(e||"").trim());return(0,l.jsx)(Je,{title:"Address",icon:$e.A,compact:!0,children:c?(0,l.jsxs)("div",{className:"grid grid-cols-1 gap-0.5 divide-y divide-gray-100",children:[(0,l.jsx)(We,{label:"Street",value:d.addressLine1,icon:Ue.A,compact:!0}),d.addressLine2&&(0,l.jsx)(We,{label:"Apartment / Unit",value:d.addressLine2,icon:Le.A,compact:!0}),(0,l.jsx)(We,{label:"City",value:d.city,icon:Te.A,compact:!0}),(0,l.jsx)(We,{label:"State / Province",value:d.state,icon:$e.A,compact:!0}),(0,l.jsx)(We,{label:"ZIP / Postal Code",value:d.postalCode,icon:$e.A,compact:!0}),(0,l.jsx)(We,{label:"Country",value:d.country,icon:$e.A,compact:!0})]}):(0,l.jsxs)("div",{className:"py-3 text-center",children:[(0,l.jsx)($e.A,{className:"w-8 h-8 mx-auto text-slate-300 mb-2"}),(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"No address on file. Click Edit to add one."})]})})},dt=e=>{const t=(0,ae.FQ)(e);return t?(0,X.GP)(t,"MMM dd, yyyy"):""},ct=e=>{var t;let{student:s,onEditRegistrationDate:a,onEditCourseStartDate:r,onEditCompletionDate:n,onGraduate:i,onOpenPromise:o}=e;const d=(0,V.xn)(s.programId),c=s.courseType||s.programName||d.courseName,m=Number(s.programHours)||(null===(t=d.requiredHours)||void 0===t?void 0:t.total)||0;return(0,l.jsx)(Je,{title:"Program Enrollment",icon:ce.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-3",children:[(0,l.jsx)("p",{className:"text-xs font-bold uppercase tracking-wider text-blue-700",children:"Enrolled program"}),(0,l.jsx)("p",{className:"mt-1 font-bold text-slate-900",children:c}),(0,l.jsxs)("p",{className:"mt-1 text-xs text-slate-600",children:[m," required training hours"]})]}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsx)(O,{student:s,onEditRegistrationDate:a,onEditCourseStartDate:r,onEditCompletionDate:n}),(0,l.jsxs)("div",{className:"bg-slate-50 p-3 rounded-lg border border-slate-200",children:[(0,l.jsx)("p",{className:"text-xs text-slate-600 uppercase tracking-wider font-bold",children:"Status"}),(0,l.jsx)("div",{className:"mt-0.5",children:(0,l.jsx)(Ze,{status:s.status,type:"course"})})]})]}),(0,l.jsxs)("div",{className:"mt-4 bg-slate-50 p-3 rounded-lg border border-slate-200",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("p",{className:"text-xs text-slate-600 uppercase tracking-wider font-bold",children:"Promise to Pay"}),(0,l.jsx)("button",{onClick:()=>o&&o(),className:"text-xs text-blue-600 hover:text-blue-700 font-semibold",children:"Add / View"})]}),(()=>{const e=(0,ae.Hz)(s);if(!e)return(0,l.jsx)("p",{className:"text-sm text-slate-400 mt-0.5",children:"None logged"});const t=(0,ae.ir)(e);return(0,l.jsxs)("div",{className:"mt-0.5",children:[(0,l.jsxs)("p",{className:"text-sm font-bold "+(t?"text-red-600":"text-slate-900"),children:[dt(e.date),null!=e.amount?` \xb7 $${Number(e.amount).toFixed(2)}`:"",t?" (overdue)":""]}),e.note&&(0,l.jsx)("p",{className:"text-xs text-slate-500 mt-0.5",children:e.note})]})})()]}),"active"===s.status&&(0,l.jsx)("div",{className:"mt-4",children:(0,l.jsxs)("button",{onClick:()=>i&&i(),className:"w-full inline-flex justify-center items-center px-4 py-2 border border-transparent roun
1ded-lg shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",children:[(0,l.jsx)(ke.A,{className:"w-4 h-4 mr-2"}),"Mark as Graduated"]})}),(0,l.jsxs)("div",{className:"border-t border-gray-100 pt-4",children:[(0,l.jsx)("h4",{className:"text-sm font-bold text-slate-800 mb-3",children:"Course Progress"}),(0,l.jsx)(Ke,{student:s})]})]})})},mt=e=>{if(!e)return null;const t=null!==e&&void 0!==e&&e.toDate?e.toDate():new Date(e);return Number.isNaN(t.getTime())?null:t},ut=e=>{var t,s,n,i,o,d,m,u,x,h,g,p;let{student:b,charges:f,payments:v,onRecordPayment:y,onAddCharge:j,onDownloadReceipt:N,onChargeUpdated:w}=e;const{showToast:S}=(0,C.d)(),[A,D]=(0,a.useState)(null),[k,E]=(0,a.useState)(""),[P,$]=(0,a.useState)(!1),[F,I]=(0,a.useState)(!1),[R,O]=(0,a.useState)(()=>{var e,t,s,a;const r={};return null!==(e=b.accommodationDetails)&&void 0!==e&&e.cancelled&&(r.accommodation=!0),null!==(t=b.cancelledServices)&&void 0!==t&&t.narRegistration&&(r["nar-registration"]=!0),null!==(s=b.cancelledServices)&&void 0!==s&&s.stateExamRegistration&&(r["state-exam-registration"]=!0),null!==(a=b.cancelledServices)&&void 0!==a&&a.stateExamFee&&(r["state-exam-fee"]=!0),r}),{totalAmount:L,totalPaid:B,balance:z,paymentStatus:H}=(0,T.Jp)(b,v||[]),G=[...(v||[]).filter(T.B4)].sort((e,t)=>{var s,a;return((null===(s=mt(t.createdAt||t.paymentDate||t.date))||void 0===s?void 0:s.getTime())||0)-((null===(a=mt(e.createdAt||e.paymentDate||e.date))||void 0===a?void 0:a.getTime())||0)})[0],q=f||[],Y=[],Z=(0,V.xn)(b.programId);Y.push({description:`${b.courseType||b.programName||Z.courseName} Tuition`,amount:(0,_.s1)(b,"courseFee"),type:"registration",id:"program-tuition",cancellable:!1}),!0===(null===(t=b.accommodationDetails)||void 0===t?void 0:t.required)&&Y.push({description:"Accommodation Fee",amount:(0,_.s1)(b,"accommodationFee"),type:"registration",id:"accommodation",cancellable:!0}),!0===(null===(s=b.optionalFees)||void 0===s?void 0:s.narRegistration)&&Y.push({description:"NAR Registration",amount:(0,_.s1)(b,"narRegistrationFee"),type:"registration",id:"nar-registration",cancellable:!0}),!0===(null===(n=b.optionalFees)||void 0===n?void 0:n.stateExamRegistration)&&Y.push({description:"State Exam Registration",amount:(0,_.s1)(b,"stateExamRegistrationFee"),type:"registration",id:"state-exam-registration",cancellable:!0}),!0===(null===(i=b.optionalFees)||void 0===i?void 0:i.stateExamFee)&&Y.push({description:"State Exam Fee",amount:(0,_.s1)(b,"stateExamFee"),type:"registration",id:"state-exam-fee",cancellable:!0}),(null===(o=b.fees)||void 0===o?void 0:o.narRegistrationFee)>0&&!Y.find(e=>"nar-registration"===e.id)&&Y.push({description:"NAR Registration",amount:b.fees.narRegistrationFee,type:"registration",id:"nar-registration",cancellable:!0}),(null===(d=b.fees)||void 0===d?void 0:d.stateExamRegistrationFee)>0&&!Y.find(e=>"state-exam-registration"===e.id)&&Y.push({description:"State Exam Registration",amount:b.fees.stateExamRegistrationFee,type:"registration",id:"state-exam-registration",cancellable:!0}),(null===(m=b.fees)||void 0===m?void 0:m.stateExamFee)>0&&!Y.find(e=>"state-exam-fee"===e.id)&&Y.push({description:"State Exam Fee",amount:b.fees.stateExamFee,type:"registration",id:"state-exam-fee",cancellable:!0}),(null===(u=b.fees)||void 0===u?void 0:u.accommodationFee)>0&&!Y.find(e=>"accommodation"===e.id)&&Y.push({description:"Accommodation Fee",amount:b.fees.accommodationFee,type:"registration",id:"accommodation",cancellable:!0}),(b.optionalServices||(null===(x=b.fees)||void 0===x?void 0:x.optionalServices)||[]).forEach((e,t)=>{null!==e&&void 0!==e&&e.name&&Number(e.amount)>=0&&Y.push({description:e.name,amount:Number(e.amount),type:"registration",id:e.id||`optional-service-${t}`,cancellable:!1})}),b.customFees&&Array.isArray(b.customFees)&&b.customFees.forEach((e,t)=>{e.name&&e.amount>0&&Y.push({description:e.name,amount:e.amount,type:"registration",id:`custom-${t}`,cancellable:!0})}),null!==(h=b.fees)&&void 0!==h&&h.customFees&&Array.isArray(b.fees.customFees)&&b.fees.customFees.forEac
1h((e,t)=>{e.name&&e.amount>0&&Y.push({description:e.name,amount:e.amount,type:"registration",id:`fees-custom-${t}`,cancellable:!0})});const W=[],J=new Set;Y.forEach(e=>{J.has(e.description)||(J.add(e.description),W.push(e))});const Q=()=>{D(null),E("")},K=async()=>{if(null==A)return;const e=parseFloat(k);if(isNaN(e)||e<0)S("Please enter a valid amount","error");else{$(!0);try{var t;const s=[...(null===(t=b.paymentDetails)||void 0===t?void 0:t.charges)||[]].map((t,s)=>s===A?{...t,amount:e}:t),a=W.filter(e=>!R[e.id]).reduce((e,t)=>e+t.amount,0),l=a+s.reduce((e,t)=>e+(t.amount||0),0),n=Math.max(0,l-B);await(0,c.mZ)((0,c.H9)(r.db,"students",b.id),{"paymentDetails.charges":s,"paymentDetails.totalAmount":l,"paymentDetails.balance":n,"paymentDetails.paymentStatus":n>0?B>0?"partial":"pending":"paid",updatedAt:(0,c.O5)()}),S("Charge amount updated successfully","success"),Q(),I(!1),null===w||void 0===w||w()}catch(s){console.error("Error updating charge:",s),S("Failed to update charge amount","error")}finally{$(!1)}}},X=W.filter(e=>!R[e.id]).reduce((e,t)=>e+t.amount,0),ee=q.reduce((e,t)=>e+(t.amount||0),0);return(0,l.jsx)(Je,{title:"Payment Information",icon:Be.A,headerAction:z>0&&(0,l.jsxs)(U.$,{size:"sm",onClick:y,className:"bg-blue-600 hover:bg-blue-700 text-xs px-3 py-1.5",children:[(0,l.jsx)(re.A,{className:"w-3.5 h-3.5 mr-1"}),"Record Payment"]}),compact:!0,children:(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,l.jsxs)("div",{className:"text-center p-3 bg-slate-50 rounded-lg border border-slate-200",children:[(0,l.jsx)("p",{className:"text-xs text-slate-600 uppercase tracking-wider font-bold",children:"Total Amount"}),(0,l.jsxs)("p",{className:"text-xl font-bold text-slate-900 mt-1",children:["$",L.toFixed(2)]})]}),(0,l.jsxs)("div",{className:"text-center p-3 bg-green-50 rounded-lg border border-green-200",children:[(0,l.jsx)("p",{className:"text-xs text-green-700 uppercase tracking-wider font-bold",children:"Total Paid"}),(0,l.jsxs)("p",{className:"text-xl font-bold text-green-700 mt-1",children:["$",B.toFixed(2)]})]}),(0,l.jsxs)("div",{className:"text-center p-3 rounded-lg border-2 "+(z>0?"bg-red-50 border-red-300":"bg-green-50 border-green-300"),children:[(0,l.jsx)("p",{className:"text-xs uppercase tracking-wider font-bold "+(z>0?"text-red-700":"text-green-700"),children:"Balance"}),(0,l.jsxs)("p",{className:"text-xl font-bold mt-1 "+(z>0?"text-red-700":"text-green-700"),children:["$",z.toFixed(2)]})]})]}),(0,l.jsxs)("div",{className:"bg-slate-50 rounded-lg p-3",children:[(0,l.jsx)("h4",{className:"text-sm font-bold text-slate-800 mb-2",children:"Charges Breakdown"}),(0,l.jsxs)("div",{className:"space-y-1.5",children:[W.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mt-1",children:"Registration Fees"}),W.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center justify-between py-1 pl-2",children:[(0,l.jsxs)("span",{className:"text-sm text-gray-600 flex items-center "+(R[e.id]?"line-through opacity-50":""),children:[e.description,e.cancellable&&(0,l.jsx)("button",{onClick:()=>(async e=>{const t=R[e];O(t=>({...t,[e]:!t[e]}));try{const s={};"accommodation"===e?(s["accommodationDetails.cancelled"]=!t,t&&(s["accommodationDetails.required"]=!0)):"nar-registration"===e?(s["cancelledServices.narRegistration"]=!t,t&&(s["optionalFees.narRegistration"]=!0)):"state-exam-registration"===e?(s["cancelledServices.stateExamRegistration"]=!t,t&&(s["optionalFees.stateExamRegistration"]=!0)):"state-exam-fee"===e&&(s["cancelledServices.stateExamFee"]=!t,t&&(s["optionalFees.stateExamFee"]=!0));const a={...R,[e]:!t},l=W.filter(e=>!a[e.id]),n=l.reduce((e,t)=>e+t.amount,0)+ee;s["paymentDetails.totalAmount"]=n,s["paymentDetails.balance"]=n-B,await(0,c.mZ)((0,c.H9)(r.db,"students",b.id),s),S(t?"Service restored successfully":"Service cancelled successfully","success")}catch(s){console.error("Error updating service:",s),S(t?"Failed to restore service":"Failed to cancel service","error"),O(t=>({...t,[e]:!t[e]}))}})(e.id),className:"ml-2 text-xs font-medium "+(R[e.id]?"text-green-600 hover:text-green-700":"text-red-600 hover:text-red-700"),children:R[e.id]?"(Restore)":"(Cancel)"})]}),(0,l.jsxs)("span",{className:"text-sm font-semibold text-gray-900 "+(R[e.id]?"line-through opacity-50":""),children:["$",e.amount.toFixed(2)]})]},`reg-${t}`)),(0,l.jsxs)("div",{className:"flex items-center justify-between py-2 pl-2 border-t border-slate-200 mt-1",children:[(0,l.jsx)("span",{className:"text-sm font-bold text-slate-700",children:"Registration Subtotal"}),(0,l.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:["$",X.toFixed(2)]})]})]}),q.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"border-t border-slate-300 my-2"}),(0,l.jsx)("div",{className:"text-sm font-bold text-slate-700 uppercase tracking-wider",children:"Additional Charges"}),q.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center justify-between py-1.5 pl-2",children:[(0,l.jsxs)("span",{className:"text-sm text-slate-700 font-medium",children:[e.description||"Additional Charge",e.date&&(0,l.jsxs)("span",{className:"text-xs text-slate-500 ml-1",children:["(",(0,M.Yq)(e.date),")"]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:["$",(e.amount||0).toFixed(2)]}),(0,l.jsx)("button",{type:"button",onClick:()=>((e,t)=>{var s;D(t),E(String(null!==(s=e.amount)&&void 0!==s?s:""))})(e,t),disabled:"agreement_interest"===e.type,className:"p-1 text-blue-600 hover:bg-blue-50 rounded",title:"agreement_interest"===e.type?"Automatically calculated from the signed agreement and payments":"Edit amount",children:(0,l.jsx)(ne.A,{className:"w-3.5 h-3.5"})})]})]},e.id||`charge-${t}`)),(0,l.jsxs)("div",{className:"flex items-center justify-between py-2 pl-2 border-t border-slate-200 mt-1",children:[(0,l.jsx)("span",{className:"text-sm font-bold text-slate-700",children:"Additional Charges Subtotal"}),(0,l.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:["$",ee.toFixed(2)]})]})]}),(0,l.jsx)("div",{className:"border-t-2 border-slate-400 pt-3 mt-3",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-base font-bold text-slate-800",children:"Total Charges"}),(0,l.jsxs)("span",{className:"text-lg font-bold text-slate-900",children:["$",L.toFixed(2)]})]})})]})]}),(0,l.jsxs)("div",{className:"space-y-2 bg-slate-50 rounded-lg p-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Payment Status"}),(0,l.jsx)(Ze,{status:H,type:"payment"})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-slate-200",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Payment Method"}),(0,l.jsx)("span",{className:"text-sm font-bold text-slate-900",children:(null===G||void 0===G?void 0:G.paymentMethod)||(null===G||void 0===G?void 0:G.method)||(null===(g=b.paymentDetails)||void 0===g?void 0:g.lastPaymentMethod)||"N/A"})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-slate-200",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Last Payment Date"}),(0,l.jsx)("span",{className:"text-sm font-bold text-slate-900",children:(0,M.Yq)((null===G||void 0===G?void 0:G.createdAt)||(null===G||void 0===G?void 0:G.paymentDate)||(null===G||void 0===G?void 0:G.date)||(null===(p=b.paymentDetails)||void 0===p?void 0:p.lastPaymentDate))})]})]}),(0,l.jsxs)("div",{className:"flex space-x-3 mt-5",children:[(0,l.jsxs)(U.$,{variant:"outline",onClick:j,className:"flex-1 text-base font-bold py-3 border-2 border-slate-400 hover:border-slate-500 hover:bg-slate-50",children:[(0,l.jsx)(re.A,{className:"w-5 h-5 mr-2"}),"Add Charge"]}),(0,l.jsxs)(U.$,{onClick:N,className:"flex-1 bg-blue-700 hover:bg-blue-800 text-base font-bold py-3 shadow-lg hover:shadow-xl",children:[(0,l.jsx)(Re.A,{className:"w-5 h-5 mr-2"}),"Email Receipt"]})]}),null!=A&&q[A]&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-[60]",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-6",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Edit Charge Amount"}),(0,l.jsxs)("p",{className:"text-sm text-gray-600 mb-2",children:[q[A].description||"Additional Charge",q[A].date&&(0,l.jsxs)("span",{className:"ml-1",children:["(",(0,M.Yq)(q[A].date),")"]})]}),(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Amount ($)"}),(0,l.jsx)("input",{type:"number",step:"0.01",min:"0",value:k,onChange:e=>E(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"0.00"})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,l.jsx)("button",{type:"button",onClick:Q,disabled:P,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:"Cancel"}),(0,l.jsx)("button",{type:"button",onClick:()=>
1{if(null==A)return;const e=parseFloat(k);isNaN(e)||e<0?S("Please enter a valid amount","error"):K()},disabled:P,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",children:P?"Saving...":"Save"})]})]})}),(0,l.jsx)(te.A,{isOpen:F,onClose:()=>I(!1),onSuccess:()=>{I(!1),K()},title:"Edit Charge Authentication"})]})})},xt=e=>{let{student:t}=e;const[s,n]=(0,a.useState)([]),[i,o]=(0,a.useState)([]),[d,c]=(0,a.useState)(!0),[m,u]=(0,a.useState)(!1),[x,h]=(0,a.useState)("sent"===t.portalInvitationStatus),[g,p]=(0,a.useState)(Boolean(t.portalAccountUid&&"accepted"===t.portalInvitationStatus)),{showToast:b}=(0,C.d)();(0,a.useEffect)(()=>{h("sent"===t.portalInvitationStatus),p(Boolean(t.portalAccountUid&&"accepted"===t.portalInvitationStatus))},[t.portalAccountUid,t.portalInvitationStatus]),(0,a.useEffect)(()=>{if(c(!0),!t.programId)return n([]),void c(!1);let e=!1,s=!1;const a=async()=>{if(!s){s=!0;try{const s=await(0,r.Ij)("getStaffStudentExamSummary",{studentId:t.id});if(e)return;n((s.exams||[]).sort((e,t)=>(e.dayNumber||0)-(t.dayNumber||0))),o(s.accessRecords||[])}catch(a){e||b(a.message||"Unable to load program exams","error")}finally{s=!1,e||c(!1)}}};a();const l=window.setInterval(a,15e3);return()=>{e=!0,window.clearInterval(l)}},[t.id,t.programId,b]);return(0,l.jsx)(Je,{title:"Program Exams",icon:ze.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:[!g&&(0,l.jsxs)("div",{className:"flex flex-col gap-3 border border-slate-200 bg-slate-50 p-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-bold text-slate-800",children:"Student portal access"}),(0,l.jsxs)("p",{className:"mt-0.5 text-xs text-slate-500",children:["Invitation uses ",t.email||"the registered student email","."]})]}),(0,l.jsx)(U.$,{size:"sm",onClick:async()=>{u(!0);try{const e=await(0,r.Ij)("inviteStudentAccount",{studentId:t.id});if(e.skipped)return p(!0),void b("This student already has an active portal account.","success");h(!0),b(`Student account invitation sent to ${e.email}`,"success")}catch(e){b(e.message||"Unable to invite student","error")}finally{u(!1)}},disabled:m||!t.email,className:"bg-slate-900 hover:bg-slate-800",children:m?"Sending\u2026":x?"Resend invitation":"Invite student"})]}),d&&(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"Loading program exams\u2026"}),!d&&0===s.length&&(0,l.jsxs)("div",{className:"rounded-lg border border-dashed border-slate-300 p-5 text-center",children:[(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-700",children:"No exams configured for this program"}),(0,l.jsxs)("p",{className:"mt-1 text-xs text-slate-500",children:["Uploaded exams assigned to ",t.programName||"this program"," will appear here."]})]}),s.filter(e=>"retake"!==e.examType).map(e=>{var s,a,r,n,o,d;const c=(e=>{var s,a;const r=null===(s=t.programExamStatuses)||void 0===s?void 0:s[e.id],l=i.filter(t=>t.examId===e.id||t.originalExamId===e.id).sort((e,t)=>(t.createdAt||0)-(e.createdAt||0))[0],n="active"===(null===l||void 0===l?void 0:l.status)&&Boolean(l.openedAt||l.draftSavedAt||l.hasDraftAnswers);return"passed"===(null===r||void 0===r?void 0:r.status)?{label:`Passed \xb7 ${r.scorePercent}%`,tone:"bg-green-100 text-green-800",result:r,access:l}:n?{label:"In progress",tone:"bg-amber-100 text-amber-800",result:r,access:l}:"failed"===(null===r||void 0===r?void 0:r.status)?{label:"active"===(null===l||void 0===l?void 0:l.status)&&l.originalExamId===e.id?`Retake assigned \xb7 ${r.scorePercent}%`:`Not passed \xb7 ${r.scorePercent}%`,tone:"bg-red-100 text-red-800",result:r,access:l}:"active"===(null===l||void 0===l?void 0:l.status)?{label:"Available now",tone:"bg-blue-100 text-blue-800",result:r,access:l}:"completed"===(null===l||void 0===l?void 0:l.status)?{label:null!=(null===(a=l.latestResult)||void 0===a?void 0:a.scorePercent)?`Completed \xb7 ${l.latestResult.scorePercent}%`:"Completed",tone:"bg-slate-200 text-slate-800",result:r||l.latestResult,access:l}:"published"!==e.status?{label:"Preparing",tone:"bg-amber-100 text-amber-800",result:r,access:l}:{label:"Not released",tone:"bg-slate-100 text-slate-700",result:r,access:l}})(e),m=null!==(s=null!==(a=null===(r=c.result)||void 0===r?void 0:r.attemptCount)&&void 0!==a?a:null===(n=c.access)||void 0===n?void 0:n.attemptCount)&&void 0!==s?s:0;return(0,l.jsxs)("div",{className:"border border-slate-200 bg-white p-4",children:[(0,l.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,l.jsxs)("div",{className:"flex min-w-0 gap-3",children:[(0,l.jsxs)("div",{className:"flex h-10 w-10 flex-none items-center justify-center border border-slate-200 bg-slate-50 text-xs font-extrabold text-slate-700",children:["D",e.dayNumber||"\u2014"]}),(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("h4",{className:"font-bold text-slate-900",children:e.title}),e.description&&(0,l.jsx)("p",{className:"mt-0.5 text-xs text-slate-500",children:e.description}),(0,l.jsxs)("p",{className:"mt-1 text-xs text-slate-500",children:[e.questionCount||0," questions \xb7 ",e.durationMinutes||"\u2014"," minutes \xb7 Pass ",e.passPercent||"\u2014","%"]})]})]}),(0,l.jsx)("span",{className:`w-fit px-2.5 py-1 text-xs font-bold ${c.tone}`,children:c.label})]}),(0,l.jsxs)("div",{className:"mt-3 grid grid-cols-2 gap-px border border-slate-200 bg-slate-200 text-xs sm:grid-cols-4",children:[(0,l.jsxs)("div",{className:"bg-slate-50 p-2",children:[(0,l.jsx)("span",{className:"text-slate-500",children:"Class day"}),(0,l.jsxs)("p",{className:"mt-0.5 font-bold text-slate-800",children:["Day ",e.dayNumber||"\u2014"]})]}),(0,l.jsxs)("div",{className:"bg-slate-50 p-2",children:[(0,l.jsx)("span",{className:"text-slate-500",children:"Attempts"}),(0,l.jsx)("p",{className:"mt-0.5 font-bold text-slate-800",children:m})]}),(0,l.jsxs)("div",{className:"bg-slate-50 p-2",children:[(0,l.jsx)("span",{className:"text-slate-500",children:"Latest score"}),(0,l.jsx)("p",{className:"mt-0.5 font-bold text-slate-800",children:null!=(null===(o=c.result)||void 0===o?void 0:o.scorePercent)?`${c.result.scorePercent}%`:"Not taken"})]}),(0,l.jsxs)("div",{className:"bg-slate-50 p-2",children:[(0,l.jsx)("span",{className:"text-slate-500",children:"Availability"}),(0,l.jsx)("p",{className:"mt-0.5 font-bold text-slate-800",children:null!==(d=c.access)&&void 0!==d&&d.closesAt?`Until ${new Date(c.access.closesAt).toLocaleStr
1ing()}`:c.label})]})]})]},e.id)})]})})},ht=e=>{var t,s,n;let{student:i,onUpdateAccommodationStatus:o}=e;const[d,m]=(0,a.useState)((null===(t=i.accommodationDetails)||void 0===t?void 0:t.status)||"not_in_accommodation"),{showToast:u}=(0,C.d)();return(0,l.jsx)(Je,{title:"Accommodation Details",icon:Le.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsxs)("div",{className:"p-3 bg-blue-50 rounded-lg border border-blue-200",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(Ue.A,{className:"w-4 h-4 text-blue-600 mr-2"}),(0,l.jsx)("h4",{className:"text-base font-bold text-slate-800",children:"Accommodation Status"})]}),(0,l.jsx)(Ze,{status:d,type:"accommodation"})]}),(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsxs)("select",{value:d,onChange:e=>m(e.target.value),className:"flex-1 px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[(0,l.jsx)("option",{value:"in_accommodation",children:"In Accommodation"}),(0,l.jsx)("option",{value:"not_in_accommodation",children:"Not in Accommodation"})]}),d!==((null===(s=i.accommodationDetails)||void 0===s?void 0:s.status)||"not_in_accommodation")&&(0,l.jsx)(U.$,{size:"sm",onClick:async()=>{try{await(0,c.mZ)((0,c.H9)(r.db,"students",i.id),{"accommodationDetails.status":d,"accommodationDetails.updatedAt":(0,c.O5)()}),u("Accommodation status updated successfully","success"),o&&o()}catch(e){u("Error updating accommodation status","error")}},className:"bg-blue-600 hover:bg-blue-700 text-xs px-3 py-1.5",children:"Update"})]})]}),(null===(n=i.accommodationDetails)||void 0===n?void 0:n.roomNumber)&&(0,l.jsxs)("div",{className:"bg-slate-50 rounded-lg p-3 space-y-2 border border-slate-200",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Room Number"}),(0,l.jsx)("span",{className:"text-sm font-bold text-slate-900",children:i.accommodationDetails.roomNumber})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-slate-200",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Check-in Date"}),(0,l.jsx)("span",{className:"text-sm font-bold text-slate-900",children:(0,M.Yq)(i.accommodationDetails.checkInDate)})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-slate-200",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-700",children:"Monthly Rate"}),(0,l.jsx)("span",{className:"text-sm font-bold text-slate-900",children:(0,M.vv)(i.accommodationDetails.monthlyRate)})]})]})]})})},gt=e=>{let{payments:t,student:s,onViewAllPayments:n,onPaymentEdited:i}=e;const{showToast:o}=(0,C.d)(),[d,m]=(0,a.useState)(null),[u,x]=(0,a.useState)(""),[h,g]=(0,a.useState)(!1),[p,b]=(0,a.useState)(!1),[f,v]=(0,a.useState)(null);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Je,{title:"Payment History",icon:Pe.A,compact:!0,children:(0,l.jsx)("div",{className:"space-y-2",children:t.length>0?(0,l.jsxs)(l.Fragment,{children:[t.slice(0,3).map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center justify-between p-2.5 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-sm font-bold text-gray-900",children:(0,M.vv)(e.amount)}),(0,l.jsxs)("div",{className:"text-xs text-gray-500",children:[(0,M.Yq)(e.createdAt)," \u2022 ",e.method||e.paymentMethod||"Cash"]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(Ze,{status:e.status||"completed",type:"payment"}),e.id&&(0,l.jsx)("button",{onClick:()=>(e=>{var t;e.id&&(m(e),x(String(null!==(t=e.amount)&&void 0!==t?t:0)))})(e),className:"p-1 rounded text-gray-500 hover:text-blue-600 hover:bg-blue-50",title:"Edit amount","aria-label":"Edit payment amount",children:(0,l.jsx)(ne.A,{className:"w-3.5 h-3.5"})})]})]},e.id||t)),t.length>3&&(0,l.jsx)("div",{className:"text-center pt-1",children:(0,l.jsxs)("button",{onClick:n,className:"text-sm text-blue-600 hover:text-blue-700 font-semibold transition-colors",children:["View all ",t.length," payments \u2192"]})})]}):(0,l.jsxs)("div",{className:"text-center py-6 text-gray-500",children:[(0,l.jsx)(Pe.A,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),(0,l.jsx)("p",{className:"text-sm font-semibold",children:"No payment history"}),(0,l.jsx)("p",{className:"text-xs mt-0.5",children:"Payments will appear here once recorded"})]})})}),d&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-[60]",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-6",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Edit Payment Amount"}),(0,l.jsxs)("p",{className:"text-sm text-gray-600 mb-2",children:[(0,M.Yq)(d.createdAt)," \u2022 ",d.receiptNumber||"No receipt"]}),(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Amount ($)"}),(0,l.jsx)("input",{type:"number",step:"0.01",min:"0",value:u,onChange:e=>x(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"0.00"})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,l.jsx)("button",{onClick:()=>m(null),disabled:h,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:"Cancel"}),(0,l.jsx)("button",{onClick:()=>
1{if(!d||null===s||void 0===s||!s.id)return;const e=parseFloat(u);isNaN(e)||e<0?o("Please enter a valid amount","error"):Math.abs(e-(d.amount||0))<.01?m(null):(v({payment:d,amount:e}),m(null),b(!0))},disabled:h,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",children:h?"Saving...":"Save"})]})]})}),(0,l.jsx)(te.A,{isOpen:p,onClose:()=>{b(!1),v(null)},onSuccess:()=>{b(!1),f&&(async(e,t)=>{if(null!==e&&void 0!==e&&e.id&&null!==s&&void 0!==s&&s.id){g(!0);try{await(0,c.mZ)((0,c.H9)(r.db,"payments",e.id),{amount:t}),await(0,R.Y2)(s.id),o("Payment amount updated successfully","success"),v(null),b(!1),null===i||void 0===i||i()}catch(a){console.error("Error updating payment:",a),o(a.message||"Failed to update payment","error")}finally{g(!1)}}})(f.payment,f.amount)},title:"Edit Payment Authentication"})]})},pt=(0,a.memo)(e=>{let{student:t,documents:s,setDocuments:n,showToast:i,isDragging:o,setIsDragging:d}=e;const[c,u]=(0,a.useState)([]),[x,h]=(0,a.useState)({}),g=(0,a.useRef)(null),p=async e=>{const s=`${Date.now()}_${e.name}`;try{if(u(t=>[...t,{id:s,name:e.name,size:e.size}]),h(e=>({...e,[s]:0})),e.size>10485760)throw new Error(`${e.name} is too large. Maximum size is 10MB.`);const a=[".pdf",".jpg",".jpeg",".png",".doc",".docx"],l=e.name.toLowerCase().substring(e.name.lastIndexOf("."));if(!a.includes(l))throw new Error(`${e.name} is not a supported file type.`);if(!r.j2.currentUser)throw new Error("You must be logged in to upload files");const o=Date.now(),d=Math.random().toString(36).substring(2,9),c=e.name.replace(/[^a-zA-Z0-9.-]/g,"_"),x=`student-documents/${t.id}/${o}_${d}_${c}`;console.log("\ud83d\udce4 Uploading:",e.name,"to",x);const g=(0,xe.KR)(r.IG,x),p=await(0,xe.D)(g,e),f=await(0,xe.qk)(p.ref);console.log("\u2705 Upload successful:",e.name);const v={id:`doc_${o}_${d}`,name:e.name,type:e.type,size:e.size,category:b(e),url:f,storagePath:x,uploadedAt:p.metadata.timeCreated||(new Date).toISOString(),uploadedBy:r.j2.currentUser.email||"admin",description:"",tags:[],shared:!1,shareableId:null},y=await m(t.id,[v]);n(y),i(`${e.name} uploaded successfully`,"success")}catch(a){console.error("\u274c Upload error:",a),i(a.message||`Failed to upload ${e.name}`,"error")}finally{u(e=>e.filter(e=>e.id!==s)),h(e=>{const t={...e};return delete t[s],t})}},b=e=>{const t=e.name.toLowerCase();return t.includes("license")||t.includes("licence")?"license":t.includes("certificate")||t.includes("cert")?"certificate":e.type.includes("image")?"photo":e.type.includes("pdf")&&(t.includes("id")||t.includes("identity"))?"id":e.type.includes("pdf")?"document":"other"},f=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]};return(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{onDrop:async e=>{e.preventDefault(),e.stopPropagation(),d(!1);const t=Array.from(e.dataTransfer.files);console.log("\ud83d\udce5 Files dropped:",t.length);for(const s of t)await p(s)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),d(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),d(!1)},className:"border-2 border-dashed rounded-lg p-6 text-center transition-colors "+(o?"border-blue-400 bg-blue-50":"border-gray-300 hover:border-gray-400"),children:[(0,l.jsx)(pe.A,{className:"w-10 h-10 mx-auto text-gray-400 mb-2"}),(0,l.jsx)("p",{className:"text-sm text-gray-600 mb-3",children:"Drag files here or click to browse"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("input",{ref:g,type:"file",multiple:!0,onChange:async e=>{console.log("\ud83c\udfaf File input changed, event:",e),console.log("\ud83c\udfaf Files in event:",e.target.files);const t=Array.from(e.target.files||[]);if(0!==t.length){console.log("\ud83d\udcc1 Files selected:",t.map(e=>({name:e.name,size:e.size})));for(const e of t)await p(e);e.target.value=""}else console.log("\u26a0\ufe0f No files selected")},accept:".pdf,.jpg,.jpeg,.png,.doc,.docx",style:{display:"none"},id:"file-upload-input"}),(0,l.jsx)("button",{type:"button",onClick:()=>{console.log("\ud83d\uddb1\ufe0f Button clicked!"),g.current?(console.log("\ud83c\udfaf Triggering file input click"),g.current.click()):console.error("\u274c File input ref is null")},className:"px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 cursor-pointer",children:"Select Files"})]}),(0,l.jsx)("p",{className:"text-xs text-gray-500 mt-2",children:"PDF, JPG, PNG, DOC, DOCX (Max 10MB)"})]}),c.length>0&&(0,l.jsxs)("div",{className:"bg-gray-50 rounded-lg p-3",children:[(0,l.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Uploading..."}),(0,l.jsx)("div",{className:"space-y-2",children:c.map(e=>(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600"}),(0,l.jsx)("span",{className:"text-sm text-gray-600 truncate flex-1",children:e.name}),(0,l.jsx)("span",{className:"text-xs text-gray-500",children:f(e.size)})]},e.id))})]})]})}),bt=e=>{let{student:t,onDocumentUpdate:s}=e;const[n,i]=(0,a.useState)([]),[m,u]=(0,a.useState)([]),[x,h]=(0,a.useState)(!1),[g,b]=(0,a.useState)(!1),[f,v]=(0,a.useState)(""),[y,j]=(0,a.useState)("all"),[N,w]=(0,a.useState)(null),[S,A]=(0,a.useState)(""),[D,k]=(0,a.useState)(!1),[E,P]=(0,a.useState)(!1),{showToast:$}=(0,C.d)(),F=[{id:"all",name:"All Documents",icon:be.A}
1,{id:"license",name:"Licenses",icon:fe.A},{id:"certificate",name:"Certificates",icon:ce.A},{id:"receipt",name:"Receipts",icon:Pe.A},{id:"exam",name:"Exam Trials",icon:ve.A},{id:"photo",name:"Photos",icon:ye.A},{id:"other",name:"Other",icon:he.A}],I=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]};(0,a.useEffect)(()=>{R()},[t.id]);const R=async()=>{try{const e=(await(0,c.x7)((0,c.H9)(r.db,"students",t.id))).data();i(e.documents||[]);const s=await(0,r.Ij)("getDocumentSettings");u((null===s||void 0===s?void 0:s.requiredDocuments)||[])}catch(e){console.error("Error loading documents:",e)}},T=async(e,a)=>{const l=await((e,t,s)=>(0,c.c4)(r.db,async a=>{const l=(0,c.H9)(r.db,"students",e),n=await a.get(l);if(!n.exists())throw new Error("Student record not found.");const i=(0,d.ru)(n.data().documents,t,s);return a.update(l,{documents:i}),i}))(t.id,e,a);i(l),null===s||void 0===s||s(),$(a?"Document tag saved":"Document tag removed","success")},M=async e=>{const s=(0,G.t3)(e.name);try{if($("Downloading file...","info"),e.restrictedToStaff||"exam"===e.category&&e.storagePath){const a=await(0,r.Ij)("getStaffStudentDocument",{studentId:t.id,documentId:e.id}),l=Uint8Array.from(atob(a.contentBase64),e=>e.charCodeAt(0)),n=URL.createObjectURL(new Blob([l],{type:a.type||e.type||"application/pdf"})),i=window.document.createElement("a");i.href=n,i.download=s,i.click(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}else{if(null===e||void 0===e||!e.url)throw new Error("The stored file is unavailable.");await(0,G.Yp)(e.url,s)}$(`${s} download started`,"success")}catch(a){console.error("Download failed:",a),$("Download initiated. Check your downloads folder.","info")}},O=()=>{navigator.clipboard.writeText(S),$("Link copied to clipboard","success")},L=n.filter(e=>{var t,s;const a=e.name.toLowerCase().includes(f.toLowerCase())||(null===(t=e.description)||void 0===t?void 0:t.toLowerCase().includes(f.toLowerCase()))||(null===(s=e.customTag)||void 0===s?void 0:s.toLowerCase().includes(f.toLowerCase())),r="all"===y||e.category===y;return a&&r}),B=()=>D?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md",children:[(0,l.jsx)("div",{className:"px-6 py-4 border-b border-gray-200",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Share Document"}),(0,l.jsx)("button",{onClick:()=>k(!1),className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-5 h-5 text-gray-500"})})]})}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"Share this link to allow others to view the document:"}),(0,l.jsxs)("div",{className:"flex items-center space-x-2 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[(0,l.jsx)(je.A,{className:"w-5 h-5 text-gray-400 flex-shrink-0"}),(0,l.jsx)("input",{type:"text",value:S,readOnly:!0,className:"flex-1 bg-transparent text-sm text-gray-700 outline-none"}),(0,l.jsx)("button",{onClick:O,className:"p-2 hover:bg-gray-200 rounded transition-colors",children:(0,l.jsx)(Ne.A,{className:"w-4 h-4 text-gray-600"})})]}),(0,l.jsx)("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:(0,l.jsx)("p",{className:"text-xs text-blue-700",children:"This link will remain active for 30 days. The recipient will be able to view and download the document."})}),(0,l.jsx)("div",{className:"mt-6",children:(0,l.jsx)(U.$,{onClick:()=>k(!1),className:"w-full bg-blue-600 hover:bg-blue-700",children:"Done"})})]})]})}):null;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Je,{title:"Documents & Files",icon:we.A,headerAction:(0,l.jsx)(U.$,{size:"sm",onClick:()=>P(!E),className:"text-xs px-3 py-1.5 "+(E?"bg-gray-600 hover:bg-gray-700":"bg-blue-600 hover:bg-blue-700"),children:E?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(p.A,{className:"w-3.5 h-3.5 mr-1"}),"Close"]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(pe.A,{className:"w-3.5 h-3.5 mr-1"}),"Upload"]})}),compact:!0,children:(0,l.jsxs)("div",{className:"space-y-4",children:[m.length>0&&(()=>{const e=new Set(n.map(e=>
1e.requirementId).filter(Boolean)),t=m.filter(t=>!e.has(t.id)).length;return(0,l.jsxs)("section",{className:"rounded-lg border border-slate-200 bg-white p-4",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h4",{className:"text-sm font-bold text-slate-900",children:"Required document checklist"}),(0,l.jsxs)("p",{className:"mt-0.5 text-xs text-slate-500",children:[m.length-t," of ",m.length," received"]})]}),(0,l.jsx)("span",{className:"rounded-full px-2.5 py-1 text-xs font-bold "+(t?"bg-amber-100 text-amber-800":"bg-emerald-100 text-emerald-800"),children:t?`${t} missing`:"Complete"})]}),(0,l.jsx)("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:m.map(t=>{const s=e.has(t.id);return(0,l.jsxs)("div",{className:"flex items-start gap-2 rounded-md border p-2.5 "+(s?"border-emerald-200 bg-emerald-50":"border-amber-200 bg-amber-50"),children:[s?(0,l.jsx)(ke.A,{className:"mt-0.5 h-4 w-4 shrink-0 text-emerald-700"}):(0,l.jsx)(Fe.A,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-xs font-bold text-slate-800",children:t.name}),t.description&&(0,l.jsx)("p",{className:"mt-0.5 text-[11px] text-slate-600",children:t.description}),(0,l.jsx)("p",{className:"mt-1 text-[10px] font-bold uppercase tracking-wide "+(s?"text-emerald-700":"text-amber-700"),children:s?"Received":"Missing"})]})]},t.id)})})]})})(),E&&(0,l.jsx)("div",{className:"mb-4",children:(0,l.jsx)(pt,{student:t,documents:n,setDocuments:i,showToast:$,isDragging:g,setIsDragging:b})}),(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsxs)("div",{className:"flex-1 relative",children:[(0,l.jsx)(Se.A,{className:"absolute left-3 top-2.5 w-4 h-4 text-gray-400"}),(0,l.jsx)("input",{type:"text",placeholder:"Search documents or tags...",value:f,onChange:e=>v(e.target.value),className:"w-full pl-9 pr-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,l.jsx)("select",{value:y,onChange:e=>j(e.target.value),className:"px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:F.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))})]}),(0,l.jsx)("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:L.length>0?L.map(e=>{const a=(u=e.type).includes("image")?ye.A:u.includes("pdf")?ve.A:he.A;var u;return(0,l.jsxs)("div",{className:"group flex items-center justify-between p-3 bg-gray-50 hover:bg-gray-100 rounded-lg transition-colors",children:[(0,l.jsxs)("div",{className:"flex items-center flex-1 min-w-0",children:[(0,l.jsx)(a,{className:"w-8 h-8 text-gray-400 mr-3 flex-shrink-0"}),(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("button",{onClick:()=>M(e),className:"text-sm font-medium text-gray-900 hover:text-blue-600 truncate cursor-pointer text-left w-full",title:"Click to download",children:e.name}),(0,l.jsxs)("p",{className:"text-xs text-gray-500",children:[I(e.size)," \u2022 Uploaded: ",(0,d.Nl)(e.uploadedAt),e.shared&&(0,l.jsxs)("span",{className:"ml-2 inline-flex items-center text-blue-600",children:[(0,l.jsx)(Ae.A,{className:"w-3 h-3 mr-0.5"}),"Shared"]})]}),(0,l.jsx)(o.A,{value:e.customTag,documentName:e.name,onSave:t=>T(e.id,t)}),"exam"===e.category&&(0,l.jsxs)("div",{className:"mt-1.5 flex flex-wrap gap-1.5 text-[10px] font-bold uppercase tracking-wide",children:[(0,l.jsxs)("span",{className:"rounded bg-slate-200 px-2 py-1 text-slate-700",children:["Attempt ",e.attemptNumber||"\u2014"]}),null!=e.scorePercent&&(0,l.jsxs)("span",{className:"rounded px-2 py-1 "+(e.passed?"bg-emerald-100 text-emerald-800":"bg-amber-100 text-amber-800"),children:[e.scorePercent,"% \xb7 ",e.passed?"Pass":"Not passed"]}),(0,l.jsx)("span",{className:"rounded bg-blue-50 px-2 py-1 text-blue-700",children:"Protected record"})]}),"exam"!==e.category&&m.length>0&&(0,l.jsxs)("select",{"aria-label":`Checklist item for ${e.name}`,value:e.requirementId||"",onChange:a=>(async(e,a)=>{try{const l=n.map(t=>
1t.id===e?{...t,requirementId:a||null}:t);await(0,c.mZ)((0,c.H9)(r.db,"students",t.id),{documents:l}),i(l),null===s||void 0===s||s(),$(a?"Document checklist updated":"Checklist assignment removed","success")}catch(l){$(l.message||"Unable to update the document checklist","error")}})(e.id,a.target.value),className:"mt-1.5 max-w-full rounded border border-slate-300 bg-white px-2 py-1 text-[11px] text-slate-700",children:[(0,l.jsx)("option",{value:"",children:"Not matched to checklist"}),m.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]})]})]}),(0,l.jsxs)("div",{className:"flex items-center space-x-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,l.jsx)("button",{onClick:()=>M(e),className:"p-1.5 hover:bg-gray-200 rounded transition-colors",title:"Download",children:(0,l.jsx)(Ce.A,{className:"w-4 h-4 text-gray-600"})}),(0,l.jsx)("button",{onClick:()=>(async e=>{try{if(e.restrictedToStaff||"exam"===e.category&&e.storagePath){const s=window.open("","_blank"),a=await(0,r.Ij)("getStaffStudentDocument",{studentId:t.id,documentId:e.id}),l=Uint8Array.from(atob(a.contentBase64),e=>e.charCodeAt(0)),n=URL.createObjectURL(new Blob([l],{type:a.type||e.type||"application/pdf"}));s?s.location.replace(n):window.open(n,"_blank","noopener,noreferrer"),setTimeout(()=>URL.revokeObjectURL(n),12e4)}else{if(null===e||void 0===e||!e.url)throw new Error("The stored file is unavailable.");window.open(e.url,"_blank","noopener,noreferrer")}}catch(s){console.error("Document preview failed:",s),$(s.message||"Unable to open this document.","error")}})(e),className:"p-1.5 hover:bg-gray-200 rounded transition-colors",title:"View in Browser",children:(0,l.jsx)(ge.A,{className:"w-4 h-4 text-gray-600"})}),"exam"!==e.category&&(0,l.jsx)("button",{onClick:()=>(async e=>{try{const s=e.shareableId||`share_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,a=n.map(t=>t.id===e.id?{...t,shared:!0,shareableId:s}:t);await(0,c.mZ)((0,c.H9)(r.db,"students",t.id),{documents:a});const l=`${window.location.origin}/shared/document/${t.id}/${s}`;A(l),w(e),k(!0),i(a)}catch(s){console.error("Error sharing document:",s),$("Error generating share link","error")}})(e),className:"p-1.5 hover:bg-gray-200 rounded transition-colors",title:"Share",children:(0,l.jsx)(Ae.A,{className:"w-4 h-4 text-gray-600"})}),"exam"!==e.category&&(0,l.jsx)("button",{onClick:()=>(async e=>{try{try{const t=(0,xe.KR)(r.IG,e.storagePath);await(0,xe.XR)(t)}catch(s){"storage/object-not-found"!==s.code&&console.warn("Storage delete warning:",s.message)}const a=n.filter(t=>t.id!==e.id);await(0,c.mZ)((0,c.H9)(r.db,"students",t.id),{documents:a,"documentStats.totalDocuments":a.length}),i(a),$("Document deleted successfully","success")}catch(a){console.error("Error deleting document:",a),$("Error deleting document","error")}})(e),className:"p-1.5 hover:bg-red-100 rounded transition-colors",title:"Delete",children:(0,l.jsx)(ie.A,{className:"w-4 h-4 text-red-600"})})]})]},e.id)}):(0,l.jsxs)("div",{className:"text-center py-8",children:[(0,l.jsx)(he.A,{className:"w-12 h-12 mx-auto text-gray-300 mb-3"}),(0,l.jsx)("p",{className:"text-sm text-gray-500 font-medium",children:"No documents uploaded yet"}),(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Upload licenses, certificates, and other important files"})]})})]})}),(0,l.jsx)(B,{})]})}
1,ft=e=>{let{notes:t,onAddNote:s,onEditNote:a,onDeleteNote:r}=e;const n=e=>{const t={general:"bg-gray-100 text-gray-800",academic:"bg-blue-100 text-blue-800",administrative:"bg-purple-100 text-purple-800",medical:"bg-red-100 text-red-800",behavioral:"bg-yellow-100 text-yellow-800",financial:"bg-green-100 text-green-800"};return t[e]||t.general},i=e=>{const t={low:"border-l-gray-400",normal:"border-l-blue-400",high:"border-l-orange-400",urgent:"border-l-red-400"};return t[e]||t.normal},o=e=>new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"});return(0,l.jsx)(Je,{title:"Student Notes",icon:_e.A,headerAction:(0,l.jsxs)(U.$,{size:"sm",onClick:s,className:"bg-blue-600 hover:bg-blue-700 text-xs px-3 py-1.5",children:[(0,l.jsx)(He.A,{className:"w-3.5 h-3.5 mr-1"}),"Add Note"]}),compact:!1,children:(0,l.jsx)("div",{className:"space-y-3",children:0===t.length?(0,l.jsxs)("div",{className:"text-center py-8",children:[(0,l.jsx)(_e.A,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),(0,l.jsx)("p",{className:"text-gray-500 text-sm",children:"No notes yet"}),(0,l.jsx)("p",{className:"text-gray-400 text-xs",children:'Click "Add Note" to create the first note'})]}):t.sort((e,t)=>new Date(t.createdAt)-new Date(e.createdAt)).map(e=>(0,l.jsxs)("div",{className:`bg-white border-l-4 ${i(e.priority)} rounded-r-lg border border-gray-200 p-4 hover:shadow-sm transition-shadow`,children:[(0,l.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsxs)("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${n(e.category)}`,children:[(0,l.jsx)(Ge.A,{className:"w-3 h-3 mr-1"}),e.category.charAt(0).toUpperCase()+e.category.slice(1)]}),"normal"!==e.priority&&(0,l.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium "+("urgent"===e.priority?"bg-red-100 text-red-800":"high"===e.priority?"bg-orange-100 text-orange-800":"bg-gray-100 text-gray-800"),children:e.priority.toUpperCase()})]}),(0,l.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,l.jsx)("button",{onClick:()=>a(e),className:"text-gray-400 hover:text-blue-600 transition-colors",title:"Edit note",children:(0,l.jsx)(ne.A,{className:"w-4 h-4"})}),(0,l.jsx)("button",{onClick:()=>r(e.id),className:"text-gray-400 hover:text-red-600 transition-colors",title:"Delete note",children:(0,l.jsx)(ie.A,{className:"w-4 h-4"})})]})]}),(0,l.jsx)("p",{className:"text-gray-800 text-sm leading-relaxed mb-3 whitespace-pre-wrap",children:e.content}),(0,l.jsxs)("div",{className:"flex items-center justify-between text-xs text-gray-500",children:[(0,l.jsxs)("span",{children:["By ",e.createdBy]}),(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsxs)("span",{children:["Created: ",o(e.createdAt)]}),e.updatedAt!==e.createdAt&&(0,l.jsxs)("span",{children:["\u2022 Updated: ",o(e.updatedAt)]})]})]})]},e.id))})})},vt=e=>{let{isOpen:t,onClose:s,onSave:a,noteData:r,setNoteData:n,isEditing:i}=e;if(!t)return null;return(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[(0,l.jsx)("div",{className:"px-6 py-4 border-b border-gray-200",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:i?"Edit Note":"Add New Note"}),(0,l.jsx)("button",{onClick:s,className:"text-gray-400 hover:text-gray-600 transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]})}),(0,l.jsxs)("div",{className:"px-6 py-4 space-y-4",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Category"}),(0,l.jsx)("select",{value:r.category,onChange:e=>n({...r,category:e.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[{value:"general",label:"General"},{value:"academic",label:"Academic"},{value:"administrative",label:"Administrative"},{value:"medical",label:"Medical"},{value:"behavioral",label:"Behavioral"},{value:"financial",label:"Financial"}].map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Priority"}),(0,l.jsx)("select",{value:r.priority,onChange:e=>n({...r,priority:e.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[{value:"low",label:"Low"},{value:"normal",label:"Normal"},{value:"high",label:"High"},{value:"urgent",label:"Urgent"}].map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Note Content"}),(0,l.jsx)("textarea",{value:r.content,onChange:e=>n({...r,content:e.target.value}),placeholder:"Enter your note here...",rows:6,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 resize-vertical"})]})]}),(0,l.jsxs)("div",{className:"px-6 py-4 border-t border-gray-200 flex justify-end space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:s,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:a,className:"bg-blue-600 hover:bg-blue-700",disabled:!r.content.trim(),children:i?"Update Note":"Add Note"})]})]})})},yt=()=>{var e;const{studentId:t}=(0,I.g)(),s=(0,I.Zp)(),{showConfirm:n}=(0,D.M)(),[i,o]=(0,I.ok)(),[d,m]=(0,a.useState)(null),[x,g]=(0,a.useState)(!1),[b,f]=(0,a.useState)([]),[v,y]=(0,a.useState)(!0),[j,N]=(0,a.useState)(null),{showToast:w}=(0,C.d)(),{showLoading:S,hideLoading:A}=(0,H.M)();(0,a.useEffect)(()=>{const e=i.get("payment");"success"===e?(w("Payment processed successfully! It may take a moment to reflect in the balance.","success"),i.delete("payment"),o(i,{replace:!0})):"cancelled"===e&&(w("Payment was cancelled.","error"),i.delete("payment"),o(i,{replace:!0}))},[]);const[k,E]=(0,a.useState)(!1),[P,R]=(0,a.useState)(!1),[M,O]=(0,a.useState)(!1),[q,W]=(0,a.useState)(!1),[J,Q]=(0,a.useState)(!1),[X,ae]=(0,a.useState)(!1),[ne,ie]=(0,a.useState)(!1),[me,xe]=(0,a.useState)(!1),[he,pe]=(0,a.useState)(null),[be,fe]=(0,a.useState)(""),[ye,je]=(0,a.useState)(!1),[Ne,we]=(0,a.useState)(!1),[Se,Ae]=(0,a.useState)(!1),[De,Pe]=(0,a.useState)(!1),[$e,Ie]=(0,a.useState)(null),Te=(0,a.useRef)(null),[Me,Oe]=(0,a.useState)((new Date).toISOString().split("T")[0]),[Le,_e]=(0,a.useState)(""),[He,Ge]=(0,a.useState)(""),[We,dt]=(0,a.useState)(""),[pt,yt]=(0,a.useState)(!1),[jt,Nt]=(0,a.useState)((new Date).getFullYear()),[wt,St]=(0,a.useState)((new Date).getMonth()),At=(e,t)=>{Nt(e),St(t)},[Ct,Dt]=(0,a.useState)([]),[kt,Et]=(0,a.useState)(!1),[Pt,$t]=(0,a.useState)(null),[Ft,It]=(0,a.useState)({content:"",category:"general",priority:"normal"}),[Rt,Tt]=(0,a.useState)(!1),[Mt,Ot]=(0,a.useState)(!1),[Ut,Lt]=(0,a.useState)(!1),[Bt,zt]=(0,a.useState)(!1),[_t,Ht]=(0,a.useState)(null),[Gt,qt]=(0,a.useState)(!1),Yt=(0,a.useRef)(!0),Vt=(0,a.useRef)(!1),[Zt,Wt]=(0,a.useState)("overview"),Jt=[{id:"overview",name:"Overview",icon:h.A,description:"Personal & Program Enrollment"},{id:"academic",name:"Academic Progress",icon:ce.A,description:"Program Exams & Documents"},{id:"financial",name:"Financial & Housing",icon:Be.A,description:"Payments & Accommodation"}],Qt=(null===d||void 0===d||null===(e=d.paymentDetails)||void 0===e?void 0:e.charges)||[],Kt=d?(0,T.Jp)(d,b):null,Xt=function(e){var t,s,a,r,l,n,i,o,d,c,m,u,x,h,g,p,b,f;let v=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Qt;const y=[],j=(0,V.xn)(e.programId);y.push({description:`${e.courseType||e.programName||j.courseName} Tuition`,amount:(0,_.s1)(e,"courseFee"),type:"registration",id:"program-tuition",cancellable:!1}
1),!0!==(null===(t=e.accommodationDetails)||void 0===t?void 0:t.required)||null!==(s=e.accommodationDetails)&&void 0!==s&&s.cancelled||y.push({description:"Accommodation Fee",amount:(0,_.s1)(e,"accommodationFee"),type:"registration",id:"accommodation",cancellable:!0}),!0!==(null===(a=e.optionalFees)||void 0===a?void 0:a.narRegistration)||null!==(r=e.cancelledServices)&&void 0!==r&&r.narRegistration||y.push({description:"NAR Registration",amount:(0,_.s1)(e,"narRegistrationFee"),type:"registration",id:"nar-registration",cancellable:!0}),!0!==(null===(l=e.optionalFees)||void 0===l?void 0:l.stateExamRegistration)||null!==(n=e.cancelledServices)&&void 0!==n&&n.stateExamRegistration||y.push({description:"State Exam Registration",amount:(0,_.s1)(e,"stateExamRegistrationFee"),type:"registration",id:"state-exam-registration",cancellable:!0}),!0!==(null===(i=e.optionalFees)||void 0===i?void 0:i.stateExamFee)||null!==(o=e.cancelledServices)&&void 0!==o&&o.stateExamFee||y.push({description:"State Exam Fee",amount:(0,_.s1)(e,"stateExamFee"),type:"registration",id:"state-exam-fee",cancellable:!0}),!((null===(d=e.fees)||void 0===d?void 0:d.narRegistrationFee)>0)||y.find(e=>"nar-registration"===e.id)||null!==(c=e.cancelledServices)&&void 0!==c&&c.narRegistration||y.push({description:"NAR Registration",amount:e.fees.narRegistrationFee,type:"registration",id:"nar-registration",cancellable:!0}),!((null===(m=e.fees)||void 0===m?void 0:m.stateExamRegistrationFee)>0)||y.find(e=>"state-exam-registration"===e.id)||null!==(u=e.cancelledServices)&&void 0!==u&&u.stateExamRegistration||y.push({description:"State Exam Registration",amount:e.fees.stateExamRegistrationFee,type:"registration",id:"state-exam-registration",cancellable:!0}),!((null===(x=e.fees)||void 0===x?void 0:x.stateExamFee)>0)||y.find(e=>"state-exam-fee"===e.id)||null!==(h=e.cancelledServices)&&void 0!==h&&h.stateExamFee||y.push({description:"State Exam Fee",amount:e.fees.stateExamFee,type:"registration",id:"state-exam-fee",cancellable:!0}),!((null===(g=e.fees)||void 0===g?void 0:g.accommodationFee)>0)||y.find(e=>"accommodation"===e.id)||null!==(p=e.accommodationDetails)&&void 0!==p&&p.cancelled||y.push({description:"Accommodation Fee",amount:e.fees.accommodationFee,type:"registration",id:"accommodation",cancellable:!0}),(e.optionalServices||(null===(b=e.fees)||void 0===b?void 0:b.optionalServices)||[]).forEach((e,t)=>{null!==e&&void 0!==e&&e.name&&Number(e.amount)>=0&&y.push({description:e.name,amount:Number(e.amount),type:"registration",id:e.id||`optional-service-${t}`,cancellable:!1})}),e.customFees&&Array.isArray(e.customFees)&&e.customFees.forEach((e,t)=>{e.name&&e.amount>0&&y.push({description:e.name,amount:e.amount,type:"registration",id:`custom-${t}`,cancellable:!0})}),null!==(f=e.fees)&&void 0!==f&&f.customFees&&Array.isArray(e.fees.customFees)&&e.fees.customFees.forEach((e,t)=>{e.name&&e.amount>0&&y.push({description:e.name,amount:e.amount,type:"registration",id:`fees-custom-${t}`,cancellable:!0})});const N=[],w=new Set;y.forEach(e=>{w.has(e.description)||(w.add(e.description),N.push(e))});const S=N.reduce((e,t)=>e+t.amount,0),A=(v||[]).reduce((e,t)=>e+(t.amount||0),0),C=(0,T.q5)({...e,paymentDetails:{...e.paymentDetails,charges:v}});return{registrationFees:N,registrationTotal:S,additionalChargesTotal:A,calculatedTotal:C}},es=e=>{if(!e)return"";try{if(e&&"object"===typeof e&&e.toDate){return e.toDate().toISOString().split("T")[0]}if("string"===typeof e&&/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if("string"===typeof e&&e.includes("T"))return e.split("T")[0];const t=new Date(e);if(!isNaN(t.getTime()))return t.toISOString().split("T")[0]}catch(t){console.error("Error formatting date:",t)}return""},ts=e=>{if(e){const[t,s]=e.split("-").map(Number);Nt(t),St(s-1)}else{const e=new Date;Nt(e.getFullYear()),St(e.getMonth())}},ss=(0,a.useCallback)(async()=>{if(!t)return N("No student ID provided"),void y(!1);try{S("Loading student details...");const s=(0,c.H9)(r.db,"students",t),a=await(0,c.x7)(s);if(a.exists()){const s={id:a.id,...a.data()};m(s),!Yt.current&&Vt.current||(fe(s.status||"active"),Yt.current=!1),await os(s);const l=(0,c.P)((0,c.rJ)(r.db,"payments"),(0,c._M)("studentId","==",t)),n=(await(0,c.GG)(l)).docs.map(e=>({id:e.id,...e.data()}));f(n);try{const e=(0,c.P)((0,c.rJ)(r.db,"paymentAgreements"),(0,c._M)("studentId","==",t)),s=await(0,c.GG)(e);if(s.empty)Ht(null);else{const e=s.docs.map(e=>({id:e.id,...e.data()})),t=e.find(e=>"signed"===e.status);Ht(t||e[e.length-1])}}catch(e){console.warn("Could not load agreement:",e.message)}}else N("Student not found"),w("Student not found","error")}catch(s){console.error("Error fetching student:",s),N(s.message||"Error fetching student details"),w("Error loading student details","error")}finally{y(!1),A()}},[t,S,A,w]);(0,a.useEffect)(()=>{ss()},[ss]),(0,a.useEffect)(()=>
1{if(!t)return;const e=(0,c.aQ)((0,c.H9)(r.db,"students",t),e=>{e.exists()&&m({id:e.id,...e.data()})},e=>console.error("Student balance subscription failed",e)),s=(0,c.aQ)((0,c.P)((0,c.rJ)(r.db,"payments"),(0,c._M)("studentId","==",t)),e=>{f(e.docs.map(e=>({id:e.id,...e.data()})))},e=>console.error("Payment subscription failed",e));return()=>{e(),s()}},[t]);const as=(0,a.useCallback)(async()=>{if(t)try{const e=(0,c.H9)(r.db,"students",t),s=await(0,c.x7)(e);if(s.exists()){const e=s.data();Dt(e.notes||[])}}catch(j){console.error("Error loading notes:",j),w("Error loading notes","error")}},[t,w]);(0,a.useEffect)(()=>{d&&as()},[d,as]);const rs=async()=>{R(!0);try{const e=(0,c.H9)(r.db,"students",t);if(!(await(0,c.x7)(e)).exists())return w("Student not found","error"),void R(!1);await(0,c.mZ)(e,{isDeleted:!0,status:"deleted",deletedAt:(0,c.O5)(),updatedAt:(0,c.O5)()}),w("Student deleted successfully","success"),s("/dashboard/students/total")}catch(j){console.error("Error deleting student:",j),"permission-denied"===j.code?w("You do not have permission to delete students","error"):"not-found"===j.co
1de?w("Student not found","error"):w("Error deleting student. Please try again.","error")}finally{R(!1)}},ls=async()=>{try{await(0,c.mZ)((0,c.H9)(r.db,"students",t),{alert:null,updatedAt:(0,c.O5)()}),w("Alert deleted successfully","success"),ss()}catch(j){console.error("Error deleting alert:",j),w("Error deleting alert","error")}},ns=()=>{s(`/dashboard/payments/record/${t}`)},is=()=>{Ie(e=>{var t;return null!==e&&void 0!==e&&null!==(t=e.url)&&void 0!==t&&t.startsWith("blob:")&&window.URL.revokeObjectURL(e.url),null})},os=async e=>{if(null!==e&&void 0!==e&&e.sourceEnrollmentId)try{const t=await(async e=>{if(null===e||void 0===e||!e.sourceEnrollmentId)return null;const t=await(0,c.x7)((0,c.H9)(r.db,"enrollments",e.sourceEnrollmentId));if(!t.exists())return null;const s=t.data();if(!s.scheduleId)return null;const a=await(0,c.x7)((0,c.H9)(r.db,"classSchedules",s.scheduleId));if(!a.exists())return null;const l={id:a.id,...a.data()},n=l.seriesId||s.seriesId;let i=[l];n&&(i=(await(0,c.GG)((0,c.P)((0,c.rJ)(r.db,"classSchedules"),(0,c._M)("seriesId","==",n)))).docs.map(e=>({id:e.id,...e.data()})));const o=i.filter(e=>"cancelled"!==e.status).map(e=>({startDate:mt(e.startAt),endDate:mt(e.endAt)})).filter(e=>e.startDate&&e.endDate).sort((e,t)=>e.startDate-t.startDate);return o.length?{scheduleId:s.scheduleId,seriesId:n||null,startDate:o[0].startDate,completionDate:o[o.length-1].endDate}:null})(e);if(!t)return;const s=await(async(e,t)=>(0,c.c4)(r.db,async s=>{const a=(0,c.H9)(r.db,"students",e),l=await s.get(a);if(!l.exists())return{};const n=l.data(),i={},o={courseStartDate:t.startDate,expectedCompletionDate:t.completionDate};return Object.entries(o).forEach(e=>{var t,s;let[a,r]=e;const l=B[a];"manual"!==n[l]&&r&&(((null===(t=n[a])||void 0===t||null===(s=t.toDate)||void 0===s?void 0:s.call(t))||new Date(n[a]||0)).getTime()===r.getTime()&&"class_schedule"===n[l]||(i[a]=r.toISOString(),i[l]="class_schedule"))}),Object.keys(i).length&&(i.scheduleId=t.scheduleId,i.scheduleSeriesId=t.seriesId||null,i.updatedAt=(0,c.O5)(),s.update(a,i)),i}))(e.id,t);Object.keys(s).length&&m(t=>(null===t||void 0===t?void 0:t.id)===e.id?{...t,...s}:t)}catch(j){console.error("Error synchronizing class schedule dates:",j)}};if(v)return(0,l.jsx)("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)(Z.A,{size:"large"}),(0,l.jsx)("p",{className:"mt-4 text-gray-600 font-medium",children:"Loading student details..."})]})});if(j)return(0,l.jsx)("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8 max-w-md w-full mx-4",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-4 mb-4",children:[(0,l.jsx)(Fe.A,{className:"h-10 w-10 text-red-500"}),(0,l.jsx)("h2",{className:"text-xl font-bold text-gray-900",children:"Error Loading Student"})]}),(0,l.jsx)("p",{className:"text-red-600 mb-6",children:j}),(0,l.jsx)(U.$,{onClick:()=>s("/dashboard"),className:"w-full",children:"Return to Dashboard"})]})});if(!d)return(0,l.jsx)("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8 max-w-md w-full mx-4",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-4 mb-4",children:[(0,l.jsx)(Fe.A,{className:"h-10 w-10 text-amber-500"}),(0,l.jsx)("h2",{className:"text-xl font-bold text-gray-900",children:"Student Not Found"})]}),(0,l.jsx)("p",{className:"text-gray-600 mb-6",children:"The student you are looking for does not exist or has been removed."}),(0,l.jsx)(U.$,{onClick:()=>s("/dashboard"),className:"w-full",children:"Return to Dashboard"})]})});const ds=async()=>{if(We)if(d&&d.id){yt(!0);try{await z(d.id,"expectedCompletionDate",We),w("Expected completion date updated successfully","success"),ss(),je(!1)}catch(j){console.error("Error updating completion date:",j),w(`Error updating completion date: ${j.message}`,"error")}finally{yt(!1)}}else w("Error: Student information not found","error");else w("Please select a date","error")},cs=()=>ye?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",onClick:e=>{e.target===e.currentTarget&&je(!1)},children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md",onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)("div",{className:"bg-blue-600 text-white px-6 py-4 rounded-t-lg flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold",children:"Set Expected Completion Date"}),(0,l.jsx)("button",{onClick:()=>je(!1),className:"p-1 hover:bg-blue-700 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsx)(K,{value:We,onChange:e=>dt(e.target.value),label:"Expected Completion Date",placeholder:"Select completion date",alwaysShowCalendar:!0,viewYear:jt,viewMonth:wt,onViewDateChange:At}),(0,l.jsx)("p",{className:"mt-2 text-xs text-gray-500",children:"Your saved date overrides the linked schedule for this student."})]}),(0,l.jsxs)("div",{className:"flex space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:()=>je(!1),className:"flex-1",disabled:pt,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:ds,className:"flex-1 bg-blue-600 hover:bg-blue-700",disabled:pt||!We,children:pt?"Saving...":"Save Date"})]})]})]})}):null,ms=async()=>
1{if(Le)if(d&&d.id){yt(!0);try{await z(d.id,"registrationDate",Le),w("Registration date updated successfully","success"),ss(),we(!1)}catch(j){console.error("Error updating registration date:",j),w(`Error updating registration date: ${j.message}`,"error")}finally{yt(!1)}}else w("Error: Student information not found","error");else w("Please select a date","error")},us=()=>Ne?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",onClick:e=>{e.target===e.currentTarget&&we(!1)},children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md relative z-50",onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)("div",{className:"bg-blue-600 text-white px-6 py-4 rounded-t-lg flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold",children:"Set Registration Date"}),(0,l.jsx)("button",{onClick:()=>we(!1),className:"p-1 hover:bg-blue-700 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsx)("div",{className:"mb-4",children:(0,l.jsx)(K,{value:Le,onChange:e=>_e(e.target.value),label:"Registration Date",placeholder:"Select registration date",alwaysShowCalendar:!0,viewYear:jt,viewMonth:wt,onViewDateChange:At})}),(0,l.jsxs)("div",{className:"flex space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:()=>we(!1),className:"flex-1",disabled:pt,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:ms,className:"flex-1 bg-blue-600 hover:bg-blue-700",disabled:pt||!Le,children:pt?"Saving...":"Save Date"})]})]})]})}):null,xs=async()=>{if(He)if(d&&d.id){yt(!0);try{await z(d.id,"courseStartDate",He),w("Course start date updated","success"),ss(),Ae(!1)}catch(j){console.error("Error updating course start date:",j),w(`Error updating course start date: ${j.message}`,"error")}finally{yt(!1)}}else w("Error: Student information not found","error");else w("Please select a date","error")},hs=()=>Se?(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",onClick:e=>{e.target===e.currentTarget&&Ae(!1)},children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md relative z-50",onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)("div",{className:"bg-blue-600 text-white px-6 py-4 rounded-t-lg flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold",children:"Set Course Start Date"}),(0,l.jsx)("button",{onClick:()=>Ae(!1),className:"p-1 hover:bg-blue-700 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsx)("div",{className:"mb-4",children:(0,l.jsx)(K,{value:He,onChange:e=>Ge(e.target.value),label:"Course Start Date",placeholder:"Select course start date",alwaysShowCalendar:!0,viewYear:jt,viewMonth:wt,onViewDateChange:At})}),(0,l.jsxs)("div",{className:"flex space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:()=>Ae(!1),className:"flex-1",disabled:pt,children:"Cancel"}),(0,l.jsx)(U.$,{onClick:xs,className:"flex-1 bg-blue-600 hover:bg-blue-700",disabled:pt||!He,children:pt?"Saving...":"Save Date"})]})]})]})}):null;return(0,l.jsxs)("div",{className:`min-h-screen ${(()=>{if(null===d||void 0===d||!d.alert)return"bg-gray-50";switch(d.alert.severity){case"critical":return"bg-red-50/30";case"warning":return"bg-orange-50/30";case"info":return"bg-blue-50/30";case"success":return"bg-green-50/30";default:return"bg-gray-50"}})()} transition-colors duration-300`,children:[(0,l.jsx)(st,{isOpen:k,onClose:()=>E(!1),onConfirm:()=>{E(!1),Q(!0),W(!0)},studentName:Ve(d.fullName),isDeleting:P}),(0,l.jsx)(te.A,{isOpen:q,onClose:()=>{W(!1),Q(!1),qt(!1)},onSuccess:()=>{W(!1),J?(Q(!1),rs()):Gt&&(qt(!1),ls())},title:Gt?"Alert Deletion Authentication":"Student Deletion Authentication"}),(0,l.jsx)(tt,{isOpen:M,onClose:()=>O(!1),student:d,onSave:ss}),(0,l.jsx)(et,{isOpen:X,onClose:()=>ae(!1),student:d,onChargeAdded:ss}),(0,l.jsx)(at,{isOpen:me,onClose:()=>{xe(!1),pe(null)},student:d,employerToEdit:he}),(0,l.jsx)(Xe,{isOpen:ne,onClose:()=>ie(!1),payments:b,student:d,onPaymentEdited:ss}),(0,l.jsx)(rt,{isOpen:Mt,onClose:()=>Ot(!1),student:d}),(0,l.jsx)(lt,{isOpen:Ut,onClose:()=>Lt(!1),student:d}),(0,l.jsx)(cs,{}),(0,l.jsx)(se.A,{isOpen:x,student:d,onClose:()=>g(!1),onUpdated:e=>m(t=>({...t,promiseToPay:e}))}),(0,l.jsx)(us,{}),(0,l.jsx)(hs,{}),$e&&(0,l.jsx)("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-slate-950/70 p-3 sm:p-6",onClick:e=>{e.target===e.currentTarget&&is()},children:(0,l.jsxs)("div",{className:"flex h-[92vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl",children:[(0,l.jsxs)("div",{className:"flex flex-col gap-3 border-b border-slate-200 px-4 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-6",children:[(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("p",{className:"text-xs font-bold uppercase tracking-wider text-blue-700",children:"Latest official receipt"}),(0,l.jsx)("h3",{className:"truncate text-base font-bold text-slate-900 sm:text-lg",children:$e.name})]}),(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsxs)(U.$,{variant:"outline",onClick:async()=>
1{if(null!==$e&&void 0!==$e&&$e.url)try{const e=document.createElement("a");e.href=$e.url,e.download=$e.name,e.style.display="none",document.body.appendChild(e),e.click(),e.remove(),w("Receipt download started","success")}catch(j){w("Unable to download the receipt","error")}},className:"flex-1 sm:flex-none",children:[(0,l.jsx)(Ce.A,{className:"mr-2 h-4 w-4"}),"Download Latest Receipt"]}),(0,l.jsxs)(U.$,{onClick:()=>{if(null!==$e&&void 0!==$e&&$e.url)try{var e;const t=null===(e=Te.current)||void 0===e?void 0:e.contentWindow;if(t)return t.focus(),void t.print()}catch(j){w("Unable to open the print dialog. Please try again.","error")}},className:"flex-1 bg-blue-700 hover:bg-blue-800 sm:flex-none",children:[(0,l.jsx)(ze.A,{className:"mr-2 h-4 w-4"}),"Print"]}),(0,l.jsx)("button",{onClick:is,className:"rounded-lg p-2 text-slate-500 hover:bg-slate-100 hover:text-slate-800","aria-label":"Close receipt preview",children:(0,l.jsx)(p.A,{className:"h-6 w-6"})})]})]}),(0,l.jsx)("div",{className:"min-h-0 flex-1 bg-slate-200 p-2 sm:p-4",children:(0,l.jsx)("iframe",{ref:Te,src:$e.url,title:`Receipt preview: ${$e.name}`,className:"h-full w-full rounded-lg border-0 bg-white shadow-inner"})})]})}),De&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md",children:[(0,l.jsxs)("div",{className:"bg-green-600 text-white px-6 py-4 rounded-t-lg flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold",children:"Mark Student as Graduated"}),(0,l.jsx)("button",{onClick:()=>Pe(!1),className:"p-1 hover:bg-green-700 rounded-lg transition-colors",children:(0,l.jsx)(p.A,{className:"w-6 h-6"})})]}),(0,l.jsxs)("div",{className:"p-6",children:[(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsxs)("p",{className:"text-sm text-gray-600 mb-4",children:["Are you sure you want to mark ",(0,l.jsx)("strong",{children:Ve(d.fullName)})," as graduated?"]}),(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Graduation Date"}),(0,l.jsx)("input",{type:"date",value:Me,onChange:e=>Oe(e.target.value),className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500"})]}),(0,l.jsxs)("div",{className:"flex space-x-3",children:[(0,l.jsx)(U.$,{variant:"outline",onClick:()=>Pe(!1),className:"flex-1",children:"Cancel"}),(0,l.jsxs)(U.$,{onClick:async()=>{if(d)try{S("Updating graduation status...");const e=(0,c.H9)(r.db,"students",d.id);await(0,c.mZ)(e,{status:"graduated",graduationDate:Me,updatedAt:(0,c.O5)()}),w("Student graduated successfully!","success"),Pe(!1),d.email&&(0,Y.NU)({studentId:d.id,studentName:Ve(d.fullName),studentEmail:d.email,courseName:d.courseType||d.programName||(0,V.xn)(d.programId).courseName,graduationDate:new Date(Me).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}).then(()=>{console.log("Graduation email sent to:",d.email)}).catch(e=>{console.error("Failed to send graduation email (non-blocking):",e)})}catch(j){console.error("Error graduating student:",j),w("Error graduating student","error")}finally{A()}},className:"flex-1 bg-green-600 hover:bg-green-700",children:[(0,l.jsx)(ke.A,{className:"w-4 h-4 mr-2"}),"Mark as Graduated"]})]})]})]})}),(0,l.jsx)("div",{className:"bg-white border-b border-gray-200 shadow-sm",children:(0,l.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:(0,l.jsxs)("div",{className:"flex items-center justify-between py-3",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsx)("button",{onClick:()=>s(-1),className:"p-1.5 rounded-lg hover:bg-gray-100 transition-colors","aria-label":"Back",children:(0,l.jsx)(qe.A,{className:"w-5 h-5 text-gray-600"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h1",{className:"text-xl font-bold text-slate-900",children:Ve(d.fullName)}),(0,l.jsxs)("p",{className:"text-sm text-slate-600 font-medium",children:["Student ID: ",t.slice(-8)]})]})]}),(0,l.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsxs)("select",{value:be,onChange:e=>{console.log("Dropdown changed:",e.target.value),console.log("Current student status:",d.status),console.log("Will show Update button:",e.target.value!==d.status),fe(e.target.value),Vt.current=!0},className:"px-2.5 py-1.5 bg-white text-gray-900 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 cursor-pointer",children:[(0,l.jsx)("option",{value:"active",children:"Active"}),(0,l.jsx)("option",{value:"inactive",children:"Inactive"}),(0,l.jsx)("option",{value:"completed",children:"Completed"}),(0,l.jsx)("option",{value:"graduated",children:"Graduated"}),(0,l.jsx)("option",{value:"withdrawn",children:"Withdrawn"}),(0,l.jsx)("option",{value:"suspended",children:"Suspended"}),(0,l.jsx)("option",{value:"onleave",children:"On Leave"})]}),be!==d.status&&(0,l.jsx)(U.$,{size:"sm",onClick:()=>{console.log("Update button clicked"),(async()=>
1{if(console.log("handleStatusUpdate called",{studentStatus:be,currentStatus:d.status}),be&&be!==d.status)try{console.log("Updating student status to:",be),await(0,r.Ij)("updateStudentStatus",{studentId:t,status:be}),Vt.current=!1,w("Student status updated successfully","success"),ss()}catch(j){console.error("Error updating status:",j),w("Error updating student status","error")}else console.log("Status update skipped - no change or empty status")})()},className:"bg-blue-600 hover:bg-blue-700 text-white text-xs px-3 py-1.5",children:"Update"})]}),(0,l.jsx)(Qe,{onEdit:()=>O(!0),onDelete:()=>E(!0)})]})]})})}),(0,l.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6",children:[(0,l.jsx)(oe,{alert:d.alert,onAdd:()=>Tt(!0),onEdit:()=>Tt(!0),onDelete:()=>{qt(!0),W(!0)},canEdit:!0}),(0,l.jsx)("div",{className:"bg-gray-50/30 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-3 mb-6 rounded-lg",children:(0,l.jsx)("div",{className:"border-b border-gray-200",children:(0,l.jsx)("nav",{className:"-mb-px flex flex-col sm:flex-row sm:space-x-8 space-y-2 sm:space-y-0","aria-label":"Tabs",children:Jt.map(e=>{const t=e.icon;let s=0;var a;"academic"===e.id?((0,F.$o)(d,"nar")||s++,(0,F.$o)(d,"cpr")||s++,"not_started"===(null===(a=d.certificateCollection)||void 0===a?void 0:a.status)&&s++):"financial"===e.id&&Kt.balance>0&&(s=1);return(0,l.jsxs)("button",{onClick:()=>Wt(e.id),className:`\n group inline-flex items-center px-3 sm:px-1 py-3 sm:py-4 border-b-2 font-medium text-sm transition-colors w-full sm:w-auto justify-center sm:justify-start\n ${Zt===e.id?"border-blue-600 text-blue-600 bg-blue-50 sm:bg-transparent":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 hover:bg-gray-50 sm:hover:bg-transparent"}\n `,children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(t,{className:`\n -ml-0.5 mr-2 h-5 w-5\n ${Zt===e.id?"text-blue-600":"text-gray-400 group-hover:text-gray-500"}\n `}),(0,l.jsx)("span",{children:e.name}),s>0&&(0,l.jsx)("span",{className:`\n ml-2 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ${Zt===e.id?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-600 group-hover:bg-gray-200"}\n `,children:s})]}),(0,l.jsx)("span",{className:"hidden lg:inline-block ml-2 text-xs text-gray-400",children:e.description})]},e.id)})})})}),(0,l.jsxs)("div",{className:"mt-6",children:["overview"===Zt&&(0,l.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(it,{student:d,onPhotoUpload:async e=>{const s=await(async(e,t)=>{if(!e)throw new Error("Student information is missing. Reload and try again.");u(t);const s=await(0,r.nr)(t,e);if(null===s||void 0===s||!s.success||!s.url)throw new Error((null===s||void 0===s?void 0:s.message)||(null===s||void 0===s?void 0:s.error)||"Photo upload failed. Please try again.");if(!s.url.startsWith("https://"))throw new Error("The photo upload did not return a saved image URL. Please try again.");return await(0,c.mZ)((0,c.H9)(r.db,"students",e),{profilePhoto:s.url,updatedAt:(0,c.O5)()}),s.url})(t,e);m(e=>(null===e||void 0===e?void 0:e.id)===t?{...e,profilePhoto:s}:e),w("Photo saved successfully","success")},alert:null===d||void 0===d?void 0:d.alert}),(0,l.jsx)(ot,{student:d}),(0,l.jsx)(ct,{student:d,onEditRegistrationDate:()=>{const e=es(null===d||void 0===d?void 0:d.registrationDate);_e(e),ts(e),we(!0)},onEditCourseStartDate:()=>{const e=es(null===d||void 0===d?void 0:d.courseStartDate);Ge(e),ts(e),Ae(!0)},onEditCompletionDate:()=>{const e=es(null===d||void 0===d?void 0:d.expectedCompletionDate);dt(e),ts(e),je(!0)},onGraduate:()=>Pe(!0),onOpenPromise:()=>g(!0)}),(0,l.jsx)(ft,{notes:Ct,onAddNote:()=>Et(!0),onEditNote:e=>{$t(e),It({content:e.content,category:e.category,priority:e.priority}),Et(!0)},onDeleteNote:async e=>{try{const s=Ct.filter(t=>t.id!==e);await(0,c.mZ)((0,c.H9)(r.db,"students",t),{notes:s,updatedAt:(0,c.O5)()}),Dt(s),w("Note deleted successfully","success")}catch(j){console.error("Error deleting note:",j),w("Error deleting note","error")}}})]}),(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(Je,{title:"Quick Balance",icon:Be.A,headerAction:(0,l.jsx)(Ze,{status:Kt.paymentStatus,type:"payment"}),compact:!0,children:(0,l.jsx)(L,{student:d,payments:b,onViewDetails:()=>Wt("financial"),onRecordPayment:ns})}),(0,l.jsx)(Je,{title:"Send Documents",icon:Re.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"Send uploaded documents and certificates via email."}),(0,l.jsxs)("button",{onClick:()=>Ot(!0),className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition-colors",children:[(0,l.jsx)(Re.A,{className:"w-4 h-4"}),"Send to Employer"]}),(()=>{const e=Kt.balance,t=e>0,s=!(null!==d&&void 0!==d&&d.email),a=t||s;return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{onClick:()=>Lt(!0),disabled:a,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold rounded-lg transition-colors "+(a?"bg-gray-200 text-gray-400 cursor-not-allowed":"text-white bg-green-600 hover:bg-green-700"),children:[(0,l.jsx)(Re.A,{className:"w-4 h-4"}),"Send to Student"]}),t&&(0,l.jsxs)("p",{className:"text-xs text-amber-600 mt-1.5 flex items-center",children:[(0,l.jsx)(le.A,{className:"w-3.5 h-3.5 mr-1 flex-shrink-0"}
1),"Student must clear outstanding balance ($",e.toFixed(2),") before receiving documents."]}),s&&!t&&(0,l.jsx)("p",{className:"text-xs text-red-500 mt-1.5",children:"No email address on file for this student."})]})})()]})}),(0,l.jsx)($,{student:d,onCompleted:ss}),((e,t)=>{const s=Kt.balance;if(s<=0)return null;const a=!(null!==d&&void 0!==d&&d.email),r="signed"===(null===_t||void 0===_t?void 0:_t.status),i="pending"===(null===_t||void 0===_t?void 0:_t.status),o=null===(e=d.paymentDetails)||void 0===e?void 0:e.interestAutomation,c=null===_t||void 0===_t?void 0:_t.dueDate,m=null!==c&&void 0!==c&&c.toDate?c.toDate():new Date("string"===typeof c&&/^\d{4}-\d{2}-\d{2}$/.test(c)?`${c}T12:00:00`:c),u=r&&!isNaN(m.getTime())?{overdue:new Date>m,dueDate:m,agrBalance:Number(_t.outstandingBalance||0),interest:((null===(t=d.paymentDetails)||void 0===t?void 0:t.charges)||[]).filter(e=>"agreement_interest"===e.type&&e.agreementId===_t.id).reduce((e,t)=>e+Number(t.amount||0),0),accruedBalance:Math.max(0,s)}:null,x=async()=>{if(a)return void w("Student has no email address on file","error");if(await n(`Send a payment agreement for $${s.toFixed(2)} to ${d.email}?\n\nThe student will receive an email with a link to review and sign the agreement.`,{title:"Send Payment Agreement",confirmText:"Send Agreement"})){zt(!0);try{await(0,Y.r9)({studentId:d.id}),w(`Payment agreement sent to ${d.email}`,"success"),ss()}catch(e){console.error("Error sending agreement:",e),w(e.message||"Failed to send agreement","error")}finally{zt(!1)}}};return(0,l.jsx)(Je,{title:"Payment Agreement",icon:ve.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:["review_required"===(null===o||void 0===o?void 0:o.status)&&(0,l.jsxs)("p",{className:"rounded-lg bg-amber-50 p-3 text-sm text-amber-900",children:["Automatic interest needs review: ",o.reason]}),r?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 p-2.5 bg-green-50 border border-green-200 rounded-lg",children:[(0,l.jsx)(ke.A,{className:"w-5 h-5 text-green-600 flex-shrink-0"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-semibold text-green-800",children:"Agreement Signed"}),(0,l.jsxs)("p",{className:"text-xs text-green-600",children:["Signed by ",_t.signedName," on ",_t.signedAt?new Date(_t.signedAt.toDate?_t.signedAt.toDate():_t.signedAt).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"N/A"]})]})]}),(null===u||void 0===u?void 0:u.overdue)&&(0,l.jsxs)("div",{className:"p-2.5 bg-red-50 border border-red-200 rounded-lg",children:[(0,l.jsx)("p",{className:"text-xs font-semibold text-red-800 mb-1",children:"Overdue \u2014 Recorded Interest"}),(0,l.jsxs)("div",{className:"text-xs text-red-700 space-y-0.5",children:[(0,l.jsxs)("p",{children:["Original balance: ",(0,l.jsxs)("strong",{children:["$",u.agrBalance.toFixed(2)]})]}),(0,l.jsxs)("p",{children:["Interest included in balance: ",(0,l.jsxs)("strong",{className:"text-red-800",children:["$",u.interest.toFixed(2)]})]}),(0,l.jsxs)("p",{children:["Current total owed: ",(0,l.jsxs)("strong",{className:"text-red-900",children:["$",u.accruedBalance.toFixed(2)]})]}),(0,l.jsxs)("p",{className:"mt-1",children:["Updated daily at 8 AM Pacific and after payment changes.",null!==o&&void 0!==o&&o.asOfDate?` Calculated through ${o.asOfDate}.`:" Awaiting the first automatic update."]}),(0,l.jsxs)("p",{className:"text-red-500 mt-1",children:["Due date was ",u.dueDate.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})]})]})]}),!(null!==u&&void 0!==u&&u.overdue)&&u&&(0,l.jsx)("div",{className:"p-2.5 bg-amber-50 border border-amber-200 rounded-lg",children:(0,l.jsxs)("p",{className:"text-xs text-amber-700",children:["Payment due by ",(0,l.jsx)("strong",{children:u.dueDate.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}),". 15% monthly interest applies after this date."]})}),(0,l.jsx)("div",{className:"flex gap-2",children:_t.pdfUrl&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("a",{href:_t.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold text-white bg-blue-600 hover:bg-blue-700 rounded-lg transition-colors",children:[(0,l.jsx)(ge.A,{className:"w-4 h-4"}),"View Agreement"]}),(0,l.jsxs)("a",{href:_t.pdfUrl,download:`Payment Agreement - ${d.fullName}.pdf`,className:"flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold text-slate-700 bg-slate-100 hover:bg-slate-200 border border-slate-300 rounded-lg transition-colors",children:[(0,l.jsx)(Ce.A,{className:"w-4 h-4"}),"Download"]})]})})]}):i?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 p-2.5 bg-amber-50 border border-amber-200 rounded-lg",children:[(0,l.jsx)(Ee.A,{className:"w-5 h-5 text-amber-600 flex-shrink-0"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-semibold text-amber-800",children:"Agreement Pending Signature"}),(0,l.jsxs)("p",{className:"text-xs text-amber-600",children:["Sent to ",_t.studentEmail||d.email," \u2014 awaiting student signature"]})]})]}),(0,l.jsx)("button",{onClick:x,disabled:Bt||a,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold rounded-lg transition-colors text-white bg-amber-600 hover:bg-amber-700 disabled:opacity-50",children:Bt?"Resending...":"Resend Agreement"})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("p",{className:"text-sm text-slate-500",children:["Send a payment agreement to the student for their outstanding balance of ",(0,l.jsxs)("strong",{className:"text-red-600",children:["$",s.toFixed(2)]}),". The agreement includes 30-day payment terms with 15% monthly compounding interest on late payments."]}),(0,l.jsx)("button",{onClick:x,disabled:Bt||a,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-semibold rounded-lg transition-colors "+(a?"bg-gray-200 text-gray-400 cursor-not-allowed":"text-white bg-amber-600 hover:bg-amber-700 disabled:opacity-50"),children:Bt?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("svg",{className:"animate-spin h-4 w-4 text-white",f
1ill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Sending..."]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(ve.A,{className:"w-4 h-4"}),"Send Payment Agreement"]})}),a&&(0,l.jsx)("p",{className:"text-xs text-red-500",children:"No email address on file for this student."})]})]})})})(),(0,l.jsxs)(Je,{title:"Optional Services",icon:ke.A,compact:!0,children:[(()=>{const e=Xt(d).registrationFees.filter(e=>e.cancellable);return e.length?(0,l.jsx)("div",{className:"space-y-3",children:e.map(e=>(0,l.jsxs)("div",{className:"flex items-center justify-between gap-3 rounded bg-slate-50 p-2.5",children:[(0,l.jsx)("span",{className:"text-sm font-semibold text-slate-800",children:e.description}),(0,l.jsxs)("div",{className:"shrink-0 text-right",children:[(0,l.jsxs)("span",{className:"block text-sm font-bold text-slate-900",children:["$",Number(e.amount||0).toFixed(2)]}),(0,l.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wide text-emerald-700",children:"Selected"})]})]},e.id))}):(0,l.jsx)("p",{className:"rounded bg-slate-50 p-3 text-sm text-slate-500",children:"No optional services were selected during registration."})})(),(0,l.jsx)(U.$,{size:"sm",variant:"outline",onClick:()=>Wt("financial"),className:"mt-4 w-full text-sm",children:"Manage Optional Services"})]}),(0,l.jsx)(nt,{student:d,onAddEmployment:()=>{pe(null),xe(!0)},onEditEmployment:e=>{pe(e),xe(!0)}})]})]}),"academic"===Zt&&(0,l.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(ue,{student:{...d,id:t},Card:Je}),(0,l.jsx)(xt,{student:d,onUpdateStatus:ss})]}),(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(Je,{title:"Course Timeline",icon:Ee.A,compact:!0,children:(0,l.jsx)(Ke,{student:d})}),(0,l.jsx)(bt,{student:d,onDocumentUpdate:ss})]})]}),"financial"===Zt&&(0,l.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(ut,{student:d,charges:Qt,payments:b,onRecordPayment:ns,onAddCharge:()=>ae(!0),onDownloadReceipt:async()=>{try{S("Emailing current receipt...");const e=await(0,r.Ij)("emailStudentAccountReceipt",{studentId:t});w(`Current receipt emailed to ${e.email}`,"success")}catch(j){console.error("Error emailing receipt:",j),w(j.message||"Unable to email the receipt","error")}finally{A()}}}),(0,l.jsx)(gt,{payments:b,student:d,onViewAllPayments:()=>ie(!0),onPaymentEdited:ss})]}),(0,l.jsxs)("div",{className:"space-y-5",children:[(0,l.jsx)(ht,{student:d,onUpdateAccommodationStatus:ss}),(0,l.jsx)(Je,{title:"Quick Actions",icon:Ye.A,compact:!0,children:(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsxs)(U.$,{onClick:ns,className:"w-full bg-blue-700 hover:bg-blue-800 text-base font-bold py-3.5 shadow-lg hover:shadow-xl",children:[(0,l.jsx)(re.A,{className:"w-6 h-6 mr-2.5"}),"Record New Payment"]}),(0,l.jsxs)(U.$,{variant:"outline",onClick:()=>ae(!0),className:"w-full text-base font-bold py-3.5 border-2 border-slate-400 hover:border-slate-500 hover:bg-slate-50",children:[(0,l.jsx)(re.A,{className:"w-6 h-6 mr-2.5"}),"Add Additional Charge"]}),(0,l.jsxs)(U.$,{variant:"outline",onClick:async()=>{try{var e;S("Preparing current receipt...");const s=await(0,c.x7)((0,c.H9)(r.db,"students",t));if(!s.exists())throw new Error("Student record not found.");const a={id:s.id,...s.data()},l=Array.isArray(null===(e=a.paymentDetails)||void 0===e?void 0:e.charges)?a.paymentDetails.charges:[];{const e=(0,c.P)((0,c.rJ)(r.db,"payments"),(0,c._M)("studentId","==",t)),s=(await(0,c.GG)(e)).docs.map(e=>({id:e.id,...e.data()})),n=new Set(["cancelled","void","refunded","reversed"]),i=s.filter(e=>!n.has(String(e.status||"completed").toLowerCase())),o=i.reduce((e,t)=>e+(Number(t.amount)||0),0),d=[...i].sort((e,t)=>{const s=e=>{var t,s,a;return(null===e||void 0===e||null===(t=e.toDate)||void 0===t||null===(s=t.call(e))||void 0===s||null===(a=s.getTime)||void 0===a?void 0:a.call(s))||new Date(e||0).getTime()||0};return s(t.createdAt||t.paymentDate||t.date)-s(e.createdAt||e.paymentDate||e.date)}),{calculatedTotal:m,registrationFees:u}=Xt(a,l),x=d[0]||{id:`ACCOUNT-${Date.now()}`,amount:0,paymentMethod:"N/A",createdAt:new Date,status:"pending"},h={isAccountStatement:!0,student:{...a,activeServices:u,paymentDetails:{...a.paymentDetails||{},charges:l,totalAmount:m,totalPaid:o,balance:Math.max(0,m-o)}},payment:x,balance:{totalAmount:m,previousBalance:m,remaining:Math.max(0,m-o),totalPaid:o,lastPaymentDate:x.createdAt||x.paymentDate||x.date||null}},g=await(0,ee._M)(h),p=window.URL.createObjectURL(g.output("blob")),b=String(a.fullName||t).replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"");return void Ie(e=>{var s;return null!==e&&void 0!==e&&null!==(s=e.url)&&void 0!==s&&s.startsWith("blob:")&&window.URL.revokeObjectURL(e.url),{url:p,name:(0,G.t3)(`Latest-Receipt-${b||t}.pdf`)}})}}catch(j){console.error("Error generating receipt:",j),w("Error generating receipt","error")}finally{A()}},className:"w-full text-base font-bold py-3.5 border-2 border-slate-400 hover:border-slate-500 hover:bg-slate-50",children:[(0,l.jsx)(Ce.A,{className:"w-6 h-6 mr-2.5"}),"Download Receipt"]}),(0,l.jsxs)(U.$,{variant:"outline",onClick:()=>s(`/dashboard/student/${t}/accommodation`),className:"w-full text-base font-bold py-3.5 border-2 border-slate-400 hover:border-slate-500 hover:bg-slate-50",children:[(0,l.jsx)(Ue.A,{className:"w-6 h-6 mr-2.5"}),"Manage Accommodation"]})]})})]})]})]})]}),(0,l.jsx)(vt,{isOpen:kt,onClose:()=>{Et(!1),$t(null),It({content:"",category:"general",priority:"normal"})},onSave:Pt?async()=>
1{if(Ft.content.trim())try{const e=Ct.map(e=>e.id===Pt.id?{...e,content:Ft.content.trim(),category:Ft.category,priority:Ft.priority,updatedAt:(new Date).toISOString()}:e);await(0,c.mZ)((0,c.H9)(r.db,"students",t),{notes:e,updatedAt:(0,c.O5)()}),Dt(e),$t(null),It({content:"",category:"general",priority:"normal"}),Et(!1),w("Note updated successfully","success")}catch(j){console.error("Error updating note:",j),w("Error updating note","error")}else w("Please enter note content","error")}:async()=>{if(Ft.content.trim())try{const e={id:Date.now().toString(),content:Ft.content.trim(),category:Ft.category,priority:Ft.priority,createdAt:(new Date).toISOString(),createdBy:"Admin",updatedAt:(new Date).toISOString()},s=[...Ct,e];await(0,c.mZ)((0,c.H9)(r.db,"students",t),{notes:s,updatedAt:(0,c.O5)()}),Dt(s),It({content:"",category:"general",priority:"normal"}),Et(!1),w("Note added successfully","success")}catch(j){console.error("Error adding note:",j),w("Error adding note","error")}else w("Please enter note content","error")},noteData:Ft,setNoteData:It,isEditing:!!Pt}),(0,l.jsx)(de,{isOpen:Rt,onClose:()=>Tt(!1),onSave:async e=>{try{var s;await(0,c.mZ)((0,c.H9)(r.db,"students",t),{alert:{message:e.message,severity:e.severity||"critical",createdAt:(null===d||void 0===d||null===(s=d.alert)||void 0===s?void 0:s.createdAt)||(new Date).toISOString(),updatedAt:(new Date).toISOString()},updatedAt:(0,c.O5)()}),w("Alert saved successfully","success"),ss()}catch(j){console.error("Error saving alert:",j),w("Error saving alert","error")}},existingAlert:null===d||void 0===d?void 0:d.alert})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.