import { getClient } from "@/app/client";
import { EventContainer } from "@/components/events/EventContainer";
import {
  futureEventsQuery,
  EventFragment,
  EventCategory,
  EventOrganizer,
} from "@/lib/event";
import { PageHeader } from "@/components/general/PageHeader";
import { Suspense } from "react";
import { VenueFragment } from "@/gql/graphql";

export default async function Page() {
  const { data, error } = await getClient().query(futureEventsQuery, {});
  const events = (data?.events?.futureEvents ?? []) as EventFragment[];
  const eventCategories = (data?.eventCategories ?? []) as EventCategory[];
  const eventOrganizers = (data?.eventOrganizers ?? []) as EventOrganizer[];
  const venues = (data?.venues ?? []) as VenueFragment[];

  return (
    <main className="site-main" id="main">
      <PageHeader heading="Dette skjer på Chateau Neuf" align="left" />
      <Suspense>
        <EventContainer
          events={events}
          eventCategories={eventCategories}
          eventOrganizers={eventOrganizers}
          venues={venues}
        />
      </Suspense>
    </main>
  );
}
