1 import type { RequireSome } from '../../interfaces';
5 VcalVtimezoneComponent,
7 } from '../../interfaces/calendar';
8 import { ICAL_METHOD } from '../constants';
9 import { serialize } from '../vcal';
11 interface CreateExportIcsParams {
13 eventsWithSummary: VcalVeventComponent[];
14 vtimezones?: VcalVtimezoneComponent[];
15 calendar: VisualCalendar;
19 type ExportVcal = RequireSome<VcalVcalendar, 'components'> & {
20 'X-WR-TIMEZONE': { value: string };
21 'X-WR-CALNAME': { value: string };
22 'X-WR-CALDESC'?: { value: string };
25 export const createExportIcs = ({
31 }: CreateExportIcsParams): string => {
32 const exportVcal: ExportVcal = {
33 component: 'vcalendar',
34 components: [...vtimezones, ...eventsWithSummary],
35 prodid: { value: prodId },
36 version: { value: '2.0' },
37 method: { value: ICAL_METHOD.PUBLISH },
38 calscale: { value: 'GREGORIAN' },
39 'X-WR-TIMEZONE': { value: defaultTzid },
40 'X-WR-CALNAME': { value: calendar.Name },
43 if (calendar.Description) {
44 exportVcal['X-WR-CALDESC'] = { value: calendar.Description };
47 return serialize(exportVcal);