import { __ } from "@wordpress/i18n"; import { useSidebar } from "../../../components/Sidebar/SidebarContext"; import { Button } from "../../../components/Button/Button"; import { wbkFormat } from "../../../components/Form/utils/dateTime"; import type { IConnectedCalendarAttendee, IEvent } from "../types"; import "./ConnectedCalendarEventDetails.scss"; type ConnectedCalendarEventDetailsProps = { event: IEvent; settings?: Record; }; const getProviderLabel = (provider?: string) => { if (provider === "google") { return __("Google Calendar", "webba-booking-lite"); } if (provider === "outlook") { return __("Outlook Calendar", "webba-booking-lite"); } return __("Connected calendar", "webba-booking-lite"); }; const formatAttendeeStatus = (status?: string) => { if (!status) { return ""; } const labels: Record = { accepted: __("Accepted", "webba-booking-lite"), declined: __("Declined", "webba-booking-lite"), tentative: __("Tentative", "webba-booking-lite"), needsAction: __("Needs action", "webba-booking-lite"), }; return labels[status] || status; }; const formatEventDateTime = ( date: Date | undefined, settings?: Record ) => { if (!date) { return ""; } const dateFormat = settings?.date_format || "M j, Y"; const timeFormat = settings?.time_format || "g:i a"; const timezone = settings?.timezone || ""; const unix = Math.floor(date.getTime() / 1000); return `${wbkFormat(unix, dateFormat, timezone)} ${wbkFormat( unix, timeFormat, timezone )}`; }; export const ConnectedCalendarEventDetails = ({ event, settings, }: ConnectedCalendarEventDetailsProps) => { const sidebar = useSidebar(); const attendees = Array.isArray(event.attendees) ? event.attendees : []; const description = (event.description || "").trim(); return (

{event.title || __("Connected calendar event", "webba-booking-lite")}

{getProviderLabel(event.provider)}

{__("Start", "webba-booking-lite")} {formatEventDateTime(event.start, settings)}
{__("End", "webba-booking-lite")} {formatEventDateTime(event.end, settings)}
{event.calendarName && (
{__("Calendar", "webba-booking-lite")} {event.calendarName}
)} {description && (
{__("Details", "webba-booking-lite")} {description}
)} {attendees.length > 0 && (
{__("Attendees", "webba-booking-lite")}
    {attendees.map((attendee: IConnectedCalendarAttendee, index) => { const name = attendee.displayName || attendee.email; const status = formatAttendeeStatus(attendee.responseStatus); return (
  • {name} {attendee.displayName && attendee.email && ( {attendee.email} )} {status && ( {status} )}
  • ); })}
)}
); };