import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { AngularMaterialModule } from '../../shared/module/angular-material.module'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-contact-dialog', imports: [AngularMaterialModule, CommonModule, FormsModule], template: `

Select Contact

{{getContactLabel(contact)}} `, styles: [` mat-radio-group { display: flex; flex-direction: column; gap: 12px; } mat-radio-button { margin: 4px 0; } `] }) export class ContactDialogComponent { selectedContact: any | null = null; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: { contacts: any[] } ) { } get contacts() { return this.data.contacts; } onSelect(): void { this.dialogRef.close(this.selectedContact); } onCancel(): void { this.dialogRef.close(); } getContactLabel(contact: any): string { if (!contact) { return 'No contact information available'; } // Build name parts, filtering out null/undefined/empty strings const nameParts = [ contact.firstName, contact.middleInitial, contact.lastName ].filter(part => part != null && part.trim() !== ''); // Build contact info parts const contactInfoParts = [ contact.email, contact.phone ].filter(part => part != null && part.trim() !== ''); // Combine all non-empty parts const allParts = [ nameParts.join(' '), // Join name parts with single spaces ...contactInfoParts // Add email and phone if they exist ].filter(part => part.trim() !== ''); return allParts.join(', ') || ''; } }