import type {CustomerFragment} from 'customer-accountapi.generated'; /** First + last name when present; otherwise customer email. */ export function getCustomerDisplayName( customer: CustomerFragment | null | undefined, ): string { if (!customer) return ''; const n = [customer.firstName, customer.lastName] .filter(Boolean) .join(' ') .trim(); if (n) return n; return customer.emailAddress?.emailAddress?.trim() ?? ''; } /** Initials from name, or first two characters of email when name is missing. */ export function getCustomerInitials( customer: CustomerFragment | null | undefined, ): string { if (!customer) return 'U'; const a = (customer.firstName || '').trim().charAt(0); const b = (customer.lastName || '').trim().charAt(0); if (a && b) return (a + b).toUpperCase(); if (a) return a.toUpperCase(); if (b) return b.toUpperCase(); const email = customer.emailAddress?.emailAddress; if (email) return email.slice(0, 2).toUpperCase(); return '?'; }