import { CalendarShell } from "@/modules/calendar/components/calendar-shell";
import {
  getDefaultEventReminderOffsets,
  listCalendars,
  listEvents,
} from "@/modules/calendar/server/queries";
import { getCurrentSession } from "@/lib/session";
import type { CalView } from "@/modules/_core/themes";

export default async function CalendarPage() {
  const now = new Date();
  const from = new Date(now);
  from.setMonth(from.getMonth() - 2);
  const to = new Date(now);
  to.setMonth(to.getMonth() + 10);

  const [{ user }, calendars, events, defaultReminderOffsets] = await Promise.all([
    getCurrentSession(),
    listCalendars(),
    listEvents({ from, to, calendarIds: "all" }),
    getDefaultEventReminderOffsets(),
  ]);

  return (
    <CalendarShell
      calendars={calendars}
      events={events}
      defaultView={user.themeCalView as CalView}
      defaultReminderOffsets={defaultReminderOffsets}
    />
  );
}
