const formatDateTime = (value) => { if (value == null) return "N/A"; const d = value instanceof Date ? value : new Date(value); if (isNaN(d.getTime())) return "N/A"; return ( d.toLocaleString("de-DE", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", }) + " Uhr" ); }; export function loanMail(user, items, startDate, endDate, createdDate, note) { const brand = process.env.MAIL_BRAND_COLOR || "#0ea5e9"; const itemsHtml = Array.isArray(items) && items.length ? items .map( (i) => `${i}`, ) .join(" ") : 'Keine Gegenstände'; const row = (label, value, isLast = false) => ` ${label} ${value} `; const html = ` Neue Ausleihe
Neue Ausleihe erstellt – Details zur Buchung.

Neue Ausleihe

Es wurde soeben eine neue Ausleihe im System angelegt.

 

Details zur Ausleihe

${row("Benutzer", user || "N/A")} ${row("Gegenstände", itemsHtml)} ${row("Startdatum", formatDateTime(startDate))} ${row("Enddatum", formatDateTime(endDate))} ${row("Erstellt am", formatDateTime(createdDate))} ${row("Notiz", note || 'Keine Notiz', true)}
Ausleihe ansehen →

Diese E-Mail wurde automatisch vom Ausleihsystem gesendet.
Bitte antworten Sie nicht auf diese Nachricht.

`; const itemsText = Array.isArray(items) ? items.join(", ") : "N/A"; const text = [ "Neue Ausleihe erstellt", "-".repeat(30), `Benutzer: ${user || "N/A"}`, `Gegenstaende: ${itemsText}`, `Start: ${formatDateTime(startDate)}`, `Ende: ${formatDateTime(endDate)}`, `Erstellt: ${formatDateTime(createdDate)}`, `Notiz: ${note || "Keine Notiz"}`, "", "-> https://admin.insta.the1s.de/api", ].join("\n"); return { html, text }; }