import { getBestColor, getTitleStyle } from '@/components/Event/EventChip/EventChipUtils' import { Calendar } from '@/features/Calendars/CalendarTypes' import { defaultColors } from '@/utils/defaultColors' import { Box, Button, Card, CardHeader, Typography } from '@linagora/twake-mui' import RepeatIcon from '@mui/icons-material/Repeat' import VideocamIcon from '@mui/icons-material/Videocam' import React from 'react' import { useI18n } from 'twake-i18n' import { SearchEventResult } from './types/SearchEventResult' interface DateProps { startDate: Date endDate: Date t: (key: string) => string timeZone: string } interface TimeProps { startDate: Date endDate: Date allDay: boolean t: (key: string) => string timeZone: string } interface TitleProps { summary?: string isRecurrent: boolean t: (key: string) => string } interface OrganizerProps { organizer?: { cn?: string email?: string } } interface VideoJoinProps { url?: string t: (key: string) => string } interface MobileDateProps { startDate: Date t: (key: string) => string timeZone: string } interface MobileEventCardProps { eventData: SearchEventResult calendar: Calendar | undefined timeZone: string } export const RenderDate: React.FC = ({ startDate, endDate, t, timeZone }) => { const dayKey = (d: Date): string => d.toLocaleDateString('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone }) return ( {startDate.toLocaleDateString(t('locale'), { day: '2-digit', month: 'short', timeZone })} {dayKey(startDate) !== dayKey(endDate) && ( <> {' - '} {endDate.toLocaleDateString(t('locale'), { day: '2-digit', month: 'short', timeZone })} )} ) } export const RenderTime: React.FC = ({ startDate, endDate, allDay, t, timeZone }) => { if (allDay) return null return ( {startDate.toLocaleTimeString(t('locale'), { hour: '2-digit', minute: '2-digit', timeZone })} {' - '} {endDate.toLocaleTimeString(t('locale'), { hour: '2-digit', minute: '2-digit', timeZone })} ) } export const RenderTitle: React.FC = ({ summary, isRecurrent, t }) => ( {summary || t('event.untitled')} {isRecurrent && } ) export const RenderOrganizer: React.FC = ({ organizer }) => { if (!organizer?.cn && !organizer?.email) return null return ( {organizer.cn || organizer.email} ) } export const RenderText: React.FC<{ text?: string }> = ({ text }) => { if (!text) return null return ( {text.replace(/\n/g, ' ')} ) } export const RenderVideoJoin: React.FC = ({ url, t }) => { if (!url) return null return ( ) } export const RenderMobileDate: React.FC = ({ startDate, t, timeZone }) => ( {startDate.toLocaleDateString(t('locale'), { day: '2-digit', timeZone })} {startDate .toLocaleDateString(t('locale'), { weekday: 'short', timeZone }) .toUpperCase()} ) export const RenderMobileEventCard: React.FC = ({ eventData, calendar, timeZone }) => { const { t } = useI18n() if (!calendar) return null const startDate = new Date(eventData.data.start) const bestColor = calendar.color ? getBestColor(calendar.color as { light: string; dark: string }) : defaultColors[0].dark const titleStyle = getTitleStyle(bestColor, 'ACCEPTED', calendar, false) return ( {eventData.data.summary || t('event.untitled')} } subheader={ !eventData.data.allDay && ( {startDate.toLocaleTimeString(t('locale'), { hour: '2-digit', minute: '2-digit', timeZone: timeZone })} ) } /> ) }