import { __ } from '@wordpress/i18n' import { useMemo } from 'react' import { buildCalendarUrls } from './calendarLinks' import type { BookingDataForCalendar, FirstEventFallback } from './types' import { ReactComponent as IconGoogle } from '../../../../../../public/images/icon-brand-google.svg' import { ReactComponent as IconOutlook } from '../../../../../../public/images/icon-brand-outlook.svg' import { ReactComponent as IconYahoo } from '../../../../../../public/images/icon-brand-yahoo.svg' import { ReactComponent as IconApple } from '../../../../../../public/images/icon-brand-apple.svg' import './AddToCalendar.scss' export interface AddToCalendarProps { bookingData: BookingDataForCalendar | null | undefined userTimezone: string sectionTitle?: string isIcalAvailable: boolean fallbackFirstEvent?: FirstEventFallback | null } export const AddToCalendar = ({ bookingData, userTimezone, sectionTitle, isIcalAvailable, fallbackFirstEvent, }: AddToCalendarProps) => { const calendarLinks = useMemo( () => buildCalendarUrls( bookingData, userTimezone, fallbackFirstEvent ), [bookingData, userTimezone, fallbackFirstEvent] ) const hasApple = Boolean(bookingData?.ical_url) const hasAnyLink = hasApple || calendarLinks.google || calendarLinks.outlook || calendarLinks.yahoo if (!isIcalAvailable || !hasAnyLink) { return null } const title = sectionTitle || __('Add to Calendar', 'webba-booking-lite') return (

{title}

{calendarLinks.google && ( Google )} {calendarLinks.outlook && ( Outlook )} {calendarLinks.yahoo && ( Yahoo )} {hasApple && ( Apple )}
) }