import { brandingPrimaryColor, renderShell, safeUrl, type BrandingShell } from '@/lib/email/shell'; interface InviteData { link: string; ttlHours: number; recipientName?: string; isSuperAdmin: boolean; /** Display name for the port — falls back to "Port Nimara" so the * pre-multi-tenant default still reads correctly. */ portName?: string; } interface RenderOpts { branding?: BrandingShell | null; } export function crmInviteEmail( data: InviteData, overrides?: RenderOpts, ): { subject: string; html: string; text: string; } { const portName = data.portName ?? 'Port Nimara'; const subject = `You're invited to the ${portName} CRM`; const greeting = data.recipientName ? `Dear ${escapeHtml(data.recipientName)},` : 'Welcome,'; const role = data.isSuperAdmin ? 'super administrator' : 'administrator'; const accent = brandingPrimaryColor(overrides?.branding); const body = `

Welcome to the ${escapeHtml(portName)} CRM

${greeting}

You've been invited to the ${escapeHtml(portName)} CRM as a ${role}. Click the button below to set your password and activate your account. The link expires in ${data.ttlHours} hours.

Set up your account

If the button doesn't work, paste this link into your browser:
${data.link}

Thank you,
${escapeHtml(portName)} CRM

`; const text = [ `Welcome to the ${portName} CRM`, '', `You've been invited as a ${role}.`, `Set up your account: ${data.link}`, '', `The link expires in ${data.ttlHours} hours.`, '', `Thank you,`, `${portName} CRM`, ].join('\n'); return { subject, html: renderShell({ title: subject, body, branding: overrides?.branding }), text, }; } function escapeHtml(str: string): string { return str .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); }