/**
 * Return a readable date time
 * e.G. Samstag 13-01-2024, 12:00 Uhr
 * With endDate (same day): Samstag 13-01-2024, 12:00 Uhr bis 14:00 Uhr
 * With endDate (other day): Samstag 13-01-2024, 12:00 Uhr bis 15-01-2024, 14:00 Uhr
 */
export const readableDateTime = (date: string, endDate?: string | null) => {
  const dateObj = new Date(date);
  const dayName = dateObj.toLocaleDateString("de-DE", { weekday: "long" });
  const normalDate = dateObj.toLocaleDateString("de-DE", { dateStyle: "medium" });
  const time = dateObj.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" });
  const base = `${dayName} ${normalDate}, ${time} Uhr`;
  if (!endDate) return base;

  const endObj = new Date(endDate);
  const endTime = endObj.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" });

  const isSameDay =
    dateObj.toLocaleDateString("de-DE", { timeZone: "Europe/Berlin" }) ===
    endObj.toLocaleDateString("de-DE", { timeZone: "Europe/Berlin" });

  if (isSameDay) return `${base} bis ${endTime} Uhr`;

  const endNormalDate = endObj.toLocaleDateString("de-DE", { dateStyle: "medium" });
  return `${base} bis ${endNormalDate}, ${endTime} Uhr`;
}