|
| 1 | +import {DurationType} from '@helpers/formatDuration'; |
| 2 | +import Icon, {OverlayedIcon} from './icon'; |
| 3 | +import {findMatchingAutoDeleteIconOption} from './sidebarLeft/tabs/autoDeleteMessages/options'; |
| 4 | + |
| 5 | +const shiftedIcons = [DurationType.Days, DurationType.Years] |
| 6 | + |
| 7 | +const typeToIcon: Partial<Record<DurationType, Icon>> = { |
| 8 | + [DurationType.Hours]: 'auto_delete_circle_hours', |
| 9 | + [DurationType.Days]: 'auto_delete_circle_days', |
| 10 | + [DurationType.Weeks]: 'auto_delete_circle_weeks', |
| 11 | + [DurationType.Months]: 'auto_delete_circle_months', |
| 12 | + [DurationType.Years]: 'auto_delete_circle_years' |
| 13 | +}; |
| 14 | + |
| 15 | +const durationToIcon: Partial<Record<number, Icon>> = { |
| 16 | + 1: 'auto_delete_circle_1', |
| 17 | + 2: 'auto_delete_circle_2', |
| 18 | + 3: 'auto_delete_circle_3', |
| 19 | + 4: 'auto_delete_circle_4', |
| 20 | + 5: 'auto_delete_circle_5', |
| 21 | + 6: 'auto_delete_circle_6', |
| 22 | + 7: 'auto_delete_circle_7', |
| 23 | + 8: 'auto_delete_circle_8' |
| 24 | +}; |
| 25 | + |
| 26 | +export function createAutoDeleteIcon(period?: number) { |
| 27 | + const defaultResult = () => Icon('auto_delete_circle_clock'); |
| 28 | + |
| 29 | + if(!period) return defaultResult(); |
| 30 | + |
| 31 | + const option = findMatchingAutoDeleteIconOption(period); |
| 32 | + if(!option) return defaultResult(); |
| 33 | + |
| 34 | + const durationIcon = durationToIcon[option.duration]; |
| 35 | + const typeIcon = typeToIcon[option.type]; |
| 36 | + |
| 37 | + if(!durationIcon || !typeIcon) return defaultResult(); |
| 38 | + |
| 39 | + const isShifted = shiftedIcons.includes(option.type); |
| 40 | + |
| 41 | + return OverlayedIcon( |
| 42 | + [ |
| 43 | + 'auto_delete_circle_empty', |
| 44 | + { |
| 45 | + icon: durationIcon, |
| 46 | + className: isShifted ? 'auto-delete-icon--shifted' : undefined |
| 47 | + }, |
| 48 | + { |
| 49 | + icon: typeIcon, |
| 50 | + className: isShifted ? 'auto-delete-icon--shifted' : undefined |
| 51 | + } |
| 52 | + ], |
| 53 | + ); |
| 54 | +} |
0 commit comments