1 import { filterFutureNotifications, sortNotificationsByAscendingTrigger } from '@proton/shared/lib/calendar/alarms';
2 import { triggerToModel } from '@proton/shared/lib/calendar/alarms/notificationModel';
3 import { ICAL_ALARM_ACTION, NOTIFICATION_TYPE_API } from '@proton/shared/lib/calendar/constants';
4 import { getSupportedAlarmAction } from '@proton/shared/lib/calendar/icsSurgery/valarm';
5 import { getIsAlarmComponent } from '@proton/shared/lib/calendar/vcalHelper';
6 import type { NotificationModel } from '@proton/shared/lib/interfaces/calendar/Notification';
7 import type { VcalVeventComponent } from '@proton/shared/lib/interfaces/calendar/VcalModel';
8 import generateUID from '@proton/utils/generateUID';
9 import unary from '@proton/utils/unary';
11 export const propertiesToNotificationModel = (
12 { components = [] }: Partial<VcalVeventComponent> = {},
14 ): NotificationModel[] => {
15 const modelNotifications = components.filter(unary(getIsAlarmComponent)).map(({ trigger, action }) => {
17 getSupportedAlarmAction(action).value === ICAL_ALARM_ACTION.EMAIL
18 ? NOTIFICATION_TYPE_API.EMAIL
19 : NOTIFICATION_TYPE_API.DEVICE;
22 id: generateUID('notification'),
24 trigger: trigger ? trigger.value : {},
30 // Filter out future alarms
31 return sortNotificationsByAscendingTrigger(filterFutureNotifications(modelNotifications));