import type { EmailBrand, EmailComposerContext, EmailHistoryItem, EmailTemplateDefinition, } from "@/components/templates/email-composer" import type { AdminPerson, AdminPersonType } from "@/lib/mock/admin-directory" const AUDIENCE: Record< AdminPersonType, { label: string; noun: string; icon: string; separateByDefault?: boolean } > = { student: { label: "Students", noun: "student", icon: "fa-user-graduate", separateByDefault: true }, faculty: { label: "Faculty", noun: "faculty member", icon: "fa-chalkboard-user", }, staff: { label: "Staff", noun: "staff member", icon: "fa-user-tie" }, } const SIGN = "

The Office of Clinical Education

" const BLANK: EmailTemplateDefinition = { id: "blank", label: "Blank email", subject: "", body: "


", header: "none", footer: "none" } /** One template from a greeting-free list of paragraphs; every letter opens with the first name. */ function letter( id: string, label: string, description: string, subject: string, paragraphs: string[], extra: Partial = {}, ): EmailTemplateDefinition { return { id, label, description, subject, body: `

Hi {{first_name}},

${paragraphs.map(text => `

${text}

`).join("")}${SIGN}`, ...extra, } } const TEMPLATES: Record = { student: [ letter( "student-welcome", "Welcome and next steps", "Greets a new student with their program, cohort and first steps.", "Welcome to {{program}}, {{first_name}}", ["Welcome to the {{program}} program. Your cohort is {{cohort}}. Sign in to Exxat to confirm your details and review your first steps."], { isDefault: true, attachments: [{ name: "Student Handbook.pdf", size: 2_202_009 }] }, ), letter("student-reminder", "Profile reminder", "Nudges students to finish their profile by a deadline.", "Please finish your profile", ["Your profile is missing a few details. Please sign in and finish it by Friday."]), letter("student-orientation", "Orientation invitation", "Invites students to orientation with date, place and what to bring.", "Orientation for {{program}}", ["Orientation for {{program}} is coming up. Please arrive 15 minutes early and bring photo ID.", "Reply to this email if you cannot attend."], { attachments: [{ name: "Orientation Packet.pdf", size: 1_048_576 }] }), letter("student-compliance", "Compliance documents due", "Asks for outstanding immunization and screening records.", "Documents needed before your placement", ["We are still missing some compliance documents. Please upload them in Exxat before the deadline so your placement is not delayed."], { attachments: [{ name: "Compliance Checklist.pdf", size: 524_288 }] }), letter("student-placement", "Placement confirmed", "Confirms a placement and lists the next steps.", "Your placement is confirmed", ["Your placement for {{program}} is confirmed. Check Exxat for the site, dates and shift, and reach out if anything looks wrong."]), letter("student-schedule-change", "Schedule change", "Tells a student their schedule has changed.", "Your schedule has changed", ["Your schedule for {{program}} has changed. Please review the new dates in Exxat today."]), letter("student-hours", "Hours and timesheet reminder", "Reminds students to log hours before the weekly cutoff.", "Log your hours by Friday", ["Please log this week's hours in Exxat by Friday at 5:00 PM so your preceptor can approve them."]), letter("student-evaluation", "Evaluation reminder", "Asks students to complete their end-of-rotation evaluation.", "Complete your evaluation", ["Your end-of-rotation evaluation is open. It takes about ten minutes and helps us improve placements."]), letter("student-survey", "Placement survey", "Collects feedback on a placement site.", "Tell us about your placement", ["We would value your feedback on your placement site. The survey is short and anonymous."]), letter("student-clearance", "Clearance cleared", "Confirms a student is cleared to start.", "You are cleared to start", ["Good news: your clearance is complete and you can start your placement as scheduled."]), letter("student-missing", "Missing information", "Asks for details missing from a student's record.", "We need a few details from you", ["Some information on your record is missing. Please sign in and complete it so we can finish your placement."]), letter("student-holiday", "Holiday and closure notice", "Lets students know about site closures.", "Site closure notice", ["Your placement site will be closed on some days. Please check your schedule in Exxat for the exact dates."]), letter("student-graduation", "Graduation requirements", "Explains what is still needed to graduate.", "Graduation requirements for {{cohort}}", ["Here is what is still needed for {{cohort}} to graduate. Please review your checklist in Exxat."]), letter("student-reachout", "Check-in from the office", "A friendly check-in to open a conversation.", "Checking in", ["We wanted to check in and see how your placement is going. Reply any time if you need support."]), BLANK, ], faculty: [ letter("faculty-update", "Term update", "Shares what is happening before a term starts.", "Term update for {{program}}", ["A short update for {{program}} before the term begins. Please confirm your availability in Exxat."], { isDefault: true }), letter("faculty-availability", "Availability request", "Asks faculty to confirm when they can supervise.", "Please confirm your availability", ["We are building the schedule for {{program}}. Please confirm your availability in Exxat this week."]), letter("faculty-assignment", "Student assignment", "Tells a faculty member which students they will oversee.", "Your student assignments", ["Your student assignments for {{program}} are ready. Review them in Exxat and let us know about any conflicts."]), letter("faculty-evaluation", "Evaluation request", "Asks faculty to complete student evaluations.", "Student evaluations are open", ["Student evaluations for {{program}} are now open. Please complete them by the end of the month."]), letter("faculty-site-visit", "Site visit scheduling", "Coordinates a site visit with faculty.", "Schedule your site visit", ["Please pick a time for your site visit. You can book it in Exxat."]), letter("faculty-compliance", "Faculty compliance reminder", "Reminds faculty to renew their own credentials.", "Your credentials need attention", ["One or more of your credentials is expiring soon. Please update them in Exxat."]), letter("faculty-meeting", "Program meeting invitation", "Invites faculty to a program meeting.", "Invitation: {{program}} meeting", ["You are invited to the {{program}} faculty meeting. Details are in Exxat."]), letter("faculty-thanks", "Thank you", "A short thank-you after a placement ends.", "Thank you", ["Thank you for supporting our students this term. Your time makes a real difference."]), BLANK, ], staff: [ letter("staff-notice", "Office notice", "A quick notice for the team.", "Notice from the Office of Clinical Education", ["A quick notice for your team."], { isDefault: true }), letter("staff-onboarding", "New team member", "Welcomes a new staff member.", "Welcome to the team", ["Welcome to the team. Your Exxat account is ready, so sign in to get started."]), letter("staff-training", "Training invitation", "Invites staff to a training session.", "Training session invitation", ["You are invited to a training session on the new placement workflow. Please reply to confirm."]), letter("staff-deadline", "Deadline reminder", "Reminds staff of an upcoming deadline.", "Reminder: deadline this Friday", ["This is a reminder that the placement report is due this Friday."]), letter("staff-coverage", "Coverage request", "Asks for help covering a task.", "Can you help cover?", ["We need help covering a few tasks next week. Reply if you can take one."]), letter("staff-update", "Process update", "Explains a change in how the office works.", "A change to our process", ["We are changing how placement requests are handled. Here is what changes for you."]), BLANK, ], } const HISTORY: EmailHistoryItem[] = [ { id: "hist-1", audience: "student", subject: "Welcome to your program", body: `

Hi there,

Welcome. Your orientation details are in Exxat.

${SIGN}`, sentAt: "Oct 28, 2026 · 9:00 AM", sentBy: "Office of Clinical Education", recipientsLabel: "12 students", status: "sent", }, { id: "hist-2", audience: "student", subject: "Profile reminder", body: `

Please finish your profile.

${SIGN}`, sentAt: "Nov 12, 2026 · 8:00 AM", sentBy: "Office of Clinical Education", recipientsLabel: "5 students", status: "scheduled", }, ] /** Maps a list of directory people to a composer context. A new hub needs only this shape. */ export function buildPeopleEmailContext( type: AdminPersonType, people: AdminPerson[], source: string, /** Other groups reachable from the same page. With any, the composer opens on Recipients. */ others: { type: AdminPersonType; people: AdminPerson[] }[] = [], /** From `useEmailBrand()`: the school avatar and product logo the shell already draws. */ brand: EmailBrand, ): EmailComposerContext { const groups = [{ type, people }, ...others] return { source, audiences: groups.map(g => ({ id: g.type, ...AUDIENCE[g.type] })), recordNoun: "placement", recipients: groups.flatMap(g => g.people.map((person, index) => ({ id: person.id, audience: g.type, name: person.name, email: person.email, fields: { program: person.program, cohort: person.cohort || person.department, last_name: person.name.trim().split(/\s+/).slice(1).join(" "), email: person.email, person_code: person.personCode, sender_office: "Office of Clinical Education", }, // Prototype data so the Recipients page shows its attention states. records: g.type === "faculty" ? (index % 2 === 0 ? 2 : 1) : 1, lastEmailed: index === 2 ? "Emailed Oct 28" : undefined, blockedReason: g.type === "faculty" && index === 1 ? "No students assigned to this placement" : undefined, }))), mergeFields: [ { key: "first_name", label: "Recipient first name", tone: 1, description: "First name of whoever gets the email, so one message greets everyone personally." }, { key: "last_name", label: "Recipient last name", tone: 1, description: "Last name of whoever gets the email." }, { key: "name", label: "Recipient full name", tone: 1, description: "Full name of whoever gets the email." }, { key: "email", label: "Recipient email", tone: 1, description: "The address this email is sent to." }, { key: "program", label: "Program", tone: 4, description: "The program the person belongs to, from the directory." }, { key: "cohort", label: "Cohort or department", tone: 4, description: "A student's cohort, or a faculty or staff member's department." }, { key: "person_code", label: "Person ID", tone: 4, description: "The workspace ID products use to refer to this person." }, { key: "sender_name", label: "Sender name", tone: 3, description: "The name the email is sent from." }, { key: "sender_office", label: "Sender office", tone: 3, description: "The office the email is sent on behalf of." }, ], templates: Object.fromEntries(groups.map(g => [g.type, TEMPLATES[g.type]])), senders: [{ name: "Coordinator", email: "coordinator@exxat.example", tag: "Coordinator" }], history: HISTORY.filter(item => groups.some(g => g.type === item.audience)), sender: { name: "Office of Clinical Education", email: "clinical-education@exxat.example", replyTo: "coordinator@exxat.example", me: "himanshu@exxat.example", brand, }, } }