1 import isTruthy from '@proton/utils/isTruthy';
3 import type { SimpleMap } from '../interfaces';
4 import type { VcalVeventComponent } from '../interfaces/calendar';
5 import type { GetVTimezonesMap } from '../interfaces/hooks/GetVTimezonesMap';
6 import { getPropertyTzid } from './vcalHelper';
9 vevents?: VcalVeventComponent[];
11 getVTimezonesMap: GetVTimezonesMap;
13 export const getUniqueVtimezones = async ({ vevents = [], tzids = [], getVTimezonesMap }: Params) => {
14 const uniqueTzidsMap = [...tzids, ...vevents].reduce<SimpleMap<boolean>>((acc, item) => {
15 if (typeof item === 'string') {
19 const { dtstart, dtend } = item;
20 const startTzid = getPropertyTzid(dtstart);
22 acc[startTzid] = true;
24 const endTzid = dtend ? getPropertyTzid(dtend) : undefined;
30 const vtimezoneObjects = Object.values(await getVTimezonesMap(Object.keys(uniqueTzidsMap))).filter(isTruthy);
32 return vtimezoneObjects.map(({ vtimezone }) => vtimezone);