import { type Coverage, getMedDisplayName, type Medication, type StockThresholds } from "../../types"; import { getStockStatus } from "../../utils/schedule"; type ReminderData = { status: { className: string; text: string }; lowStockMeds: Array<{ name: string; daysLeft: number; isCritical: boolean }>; lastStockSent: { medNames: string | null; date: string } | null; lastIntakeSent: { medName: string | null; takenBy: string | null; date: string } | null; }; type PrescriptionLowMed = { id: number; name: string; remainingRefills: number; threshold: number; }; type DashboardReminderSectionProps = { t: (key: string, options?: Record) => string; remindersLoading: boolean; anyRemindersEnabled: boolean; stockRemindersEnabled: boolean; intakeRemindersEnabled: boolean; prescriptionRemindersEnabled: boolean; reminderData: ReminderData; prescriptionLowMeds: PrescriptionLowMed[]; prescriptionStatus: { text: string; className: string } | null; meds: Medication[]; coverage: { all: Coverage[] }; stockThresholds: StockThresholds; sendingReminder: boolean; reminderResult: { success: boolean; message: string } | null; onSendManualReminder: () => void; onOpenMedicationDetail: (med: Medication) => void; }; function NotificationBellIcon() { return ( ); } export function DashboardReminderSection({ t, remindersLoading, anyRemindersEnabled, stockRemindersEnabled, intakeRemindersEnabled, prescriptionRemindersEnabled, reminderData, prescriptionLowMeds, prescriptionStatus, meds, coverage, stockThresholds, sendingReminder, reminderResult, onSendManualReminder, onOpenMedicationDetail, }: DashboardReminderSectionProps) { const getStatusTextClass = (statusClassName: string | undefined): string => { if (statusClassName === "danger") return "danger-text"; if (statusClassName === "warning") return "warning-text"; return ""; }; if (remindersLoading) { return (
{t("dashboard.reminders.active")}
); } if (!anyRemindersEnabled) { return null; } return (
{t("dashboard.reminders.active")} {stockRemindersEnabled && ( {reminderData.status.text} )} {prescriptionStatus && ( {prescriptionStatus.text} )}
{(reminderData.lowStockMeds.length > 0 || (prescriptionRemindersEnabled && prescriptionLowMeds.length > 0) || (stockRemindersEnabled && reminderData.lastStockSent) || (intakeRemindersEnabled && reminderData.lastIntakeSent)) && (
{stockRemindersEnabled && reminderData.lowStockMeds.length > 0 && (
{t("dashboard.reminders.needsRefill")}: {reminderData.lowStockMeds.map((med, idx) => { const medication = meds.find((m) => getMedDisplayName(m) === med.name); const cov = coverage.all.find((c) => c.name === med.name); const status = cov ? getStockStatus(cov.daysLeft, cov.medsLeft, stockThresholds, medication?.packageType) : null; const textClass = getStatusTextClass(status?.className); return ( {idx > 0 && ", "} medication && onOpenMedicationDetail(medication)} onKeyDown={(e) => { if ((e.key === "Enter" || e.key === " ") && medication) { onOpenMedicationDetail(medication); } }} > {med.name} {" "} {t("dashboard.reminders.daysLeft", { count: med.daysLeft, days: med.daysLeft })} ); })}
)} {prescriptionRemindersEnabled && prescriptionLowMeds.length > 0 && (
{t("dashboard.reminders.needsPrescriptionRefill")}: {prescriptionLowMeds.map((med, idx) => { const medication = meds.find((m) => m.id === med.id); const textClass = med.remainingRefills <= 0 ? "danger-text" : "warning-text"; return ( {idx > 0 && ", "} {t("prescription.remainingRefills")}: {med.remainingRefills} ยท {t("dashboard.reminders.usedBy")} :{" "} medication && onOpenMedicationDetail(medication)} onKeyDown={(e) => { if ((e.key === "Enter" || e.key === " ") && medication) { onOpenMedicationDetail(medication); } }} > {med.name} ); })}
)} {stockRemindersEnabled && reminderData.lastStockSent && (
{t("dashboard.reminders.lastStockSent")}: {reminderData.lastStockSent.medNames && (() => { const names = reminderData.lastStockSent?.medNames?.split(", ") ?? []; return names.map((name, idx) => { const medication = meds.find((m) => getMedDisplayName(m) === name); return ( {idx > 0 && ", "} {medication ? ( onOpenMedicationDetail(medication)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") onOpenMedicationDetail(medication); }} > {name} ) : ( {name} )} ); }); })()} {reminderData.lastStockSent.date}
)} {intakeRemindersEnabled && reminderData.lastIntakeSent && (
{t("dashboard.reminders.lastSent")}: {reminderData.lastIntakeSent.medName && (() => { const medication = meds.find((m) => getMedDisplayName(m) === reminderData.lastIntakeSent?.medName); return medication ? ( onOpenMedicationDetail(medication)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") onOpenMedicationDetail(medication); }} > {reminderData.lastIntakeSent?.medName} ) : ( {reminderData.lastIntakeSent?.medName} ); })()} {reminderData.lastIntakeSent.takenBy && ( ({reminderData.lastIntakeSent.takenBy}) )} {reminderData.lastIntakeSent.date}
)}
)} {((stockRemindersEnabled && reminderData.lowStockMeds.length > 0) || (prescriptionRemindersEnabled && prescriptionLowMeds.length > 0)) && (
{reminderResult && ( {reminderResult.message} )}
)}
); }