import { View, Text } from "react-native"; import { Feather } from "@expo/vector-icons"; import { ReactNode } from "react"; import { useThemeStore } from "../stores/ThemeStore"; import { CardBase } from "./CardBase"; import { isMultiDayEvent, formatDateWithWeekday, formatDateWithWeekdayShort, formatTime, formatRecurrenceRule, } from "@calchat/shared"; type EventCardBaseProps = { className?: string; title: string; startTime: Date; endTime: Date; description?: string; recurrenceRule?: string; children?: ReactNode; }; function formatDuration(start: Date, end: Date): string { const startDate = new Date(start); const endDate = new Date(end); const diffMs = endDate.getTime() - startDate.getTime(); const diffMins = Math.round(diffMs / 60000); if (diffMins < 60) { return `${diffMins} min`; } const hours = Math.floor(diffMins / 60); const mins = diffMins % 60; if (mins === 0) { return hours === 1 ? "1 Std" : `${hours} Std`; } return `${hours} Std ${mins} min`; } export const EventCardBase = ({ className, title, startTime, endTime, description, recurrenceRule, children, }: EventCardBaseProps) => { const { theme } = useThemeStore(); const multiDay = isMultiDayEvent(startTime, endTime); return ( {/* Date */} {multiDay ? ( {formatDateWithWeekdayShort(startTime)} →{" "} {formatDateWithWeekday(endTime)} ) : ( {formatDateWithWeekday(startTime)} )} {/* Time with duration */} {multiDay ? ( {formatTime(startTime)} → {formatTime(endTime)} ) : ( {formatTime(startTime)} - {formatTime(endTime)} ( {formatDuration(startTime, endTime)}) )} {/* Recurring indicator */} {recurrenceRule && ( {formatRecurrenceRule(recurrenceRule)} )} {/* Description */} {description && ( {description} )} {/* Action buttons slot */} {children} ); }; export default EventCardBase;