1/**
2 * Gets a display label for a file type from various input formats
3 *
4 * Handles:
5 * - MIME types: 'application/pdf' → 'PDF'
6 * - AttachmentType values: 'PDF', 'AUDIO' → 'PDF', 'AUDIO'
7 * - File names: 'document.pdf' → 'PDF'
8 * - Unknown: returns 'FILE'
9 *
10 * @param input - MIME type, AttachmentType value, or file name
11 * @returns Formatted file type label (uppercase)
12 */
13export function getFileTypeLabel(input: string | undefined): string {
14 if (!input) return 'FILE';
15
16 // Handle MIME types (contains '/')
17 if (input.includes('/')) {
18 const subtype = input.split('/').pop();
19 if (subtype) {
20 // Handle special cases like 'vnd.ms-excel' → 'EXCEL'
21 if (subtype.includes('.')) {
22 return subtype.split('.').pop()?.toUpperCase() || 'FILE';
23 }
24 return subtype.toUpperCase();
25 }
26 }
27
28 // Handle file names (contains '.')
29 if (input.includes('.')) {
30 const ext = input.split('.').pop();
31 if (ext) return ext.toUpperCase();
32 }
33
34 // Handle AttachmentType or other plain strings
35 return input.toUpperCase();
36}