import React from 'react'; import { Link } from '../../Link/Link'; import { CalendarDaysIcon, MapPinIcon, ChevronRightIcon, ClockIcon, } from '@heroicons/react/24/outline'; import { isSameDay, parseISO, getMonth, getDate } from 'date-fns'; import { Badge } from '../../Badge'; // import { rdsFontSizes } from '../../../utils/tailwindClasses'; // import { Badge } from '../../Badge'; // Set types for as props type BaseItemTypeProps = 'li' | 'div'; type TitleTypeProps = 'h2' | 'h3'; interface Tags { category: { id: number; name: string; slug: string }[]; audience: { id: number; name: string; slug: string }[]; } export interface EventItemProps { children?: React.ReactNode; fontSize?: 'base' | 'lg' | 'xl'; title?: string; link?: string; startDateTime?: string; endDateTime?: string; featuredImage?: string; description?: string; on_campus?: boolean; on_campus_building?: string | null; on_campus_room_number?: string | null; event_address?: string; tags?: Tags; } export interface ItemBaseProps { as?: keyof JSX.IntrinsicElements; } export interface BaseItemProps { as?: BaseItemTypeProps; } export interface TitleProps { as?: TitleTypeProps; } export const EventItem = ({ as: Component = 'div', link, title, startDateTime, endDateTime, featuredImage, on_campus, on_campus_building, on_campus_room_number, event_address, tags, }: ItemBaseProps & EventItemProps) => { const defaultImage = 'https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&q=80'; const getMonthName = (month: any, short: boolean = false) => { const d = new Date(); d.setMonth(month); const monthName = d.toLocaleString('default', { month: short ? 'short' : 'long', }); return monthName; }; const startDate = startDateTime && parseISO(startDateTime); const endDate = endDateTime && parseISO(endDateTime); const isEventSameDay = startDate && endDate && isSameDay(startDate, endDate); const eventStartMonth = startDate && getMonth(startDate); const eventStartDate = startDate && getDate(startDate); const eventEndDate = endDate && getDate(endDate); const formatTime = (date: any) => { var hours = date.getHours(); var minutes = date.getMinutes(); var ampm = hours >= 12 ? 'pm' : 'am'; hours = hours % 12; hours = hours ? hours : 12; minutes = minutes < 10 ? '0' + minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; }; const multiDayDisplay = () => { if (!isEventSameDay) { return (