import { graphql } from "@/gql";
import { VenueFragment, VenueIndexFragment } from "@/gql/graphql";
import { getClient } from "@/app/client";
import { VenueList } from "@/components/venues/VenueList";
import { PageHeader } from "@/components/general/PageHeader";
import { Blocks } from "@/components/blocks/Blocks";

const VenueIndexDefinition = graphql(`
  fragment VenueIndex on VenueIndex {
    ... on VenueIndex {
      title
      lead
      body {
        ...Blocks
      }
    }
  }
`);

const VenueFragmentDefinition = graphql(`
  fragment Venue on VenuePage {
    __typename
    id
    slug
    title
    body {
      ...Blocks
    }
    featuredImage {
      ...Image
    }
    showAsBookable
    floor
    preposition
    capabilityAudio
    capabilityAudioVideo
    capabilityBar
    capabilityLighting
    capacityLegal
    capacityStanding
    capacitySitting
  }
`);

export default async function Page() {
  const venueIndexQuery = graphql(`
    query venueIndex {
      index: venueIndex {
        ... on VenueIndex {
          ...VenueIndex
        }
      }
      venues: pages(contentType: "venues.VenuePage") {
        ... on VenuePage {
          ...Venue
        }
      }
    }
  `);
  const { data, error } = await getClient().query(venueIndexQuery, {});
  const index = (data?.index ?? []) as VenueIndexFragment;
  const venues = (data?.venues ?? []) as VenueFragment[];

  return (
    <main className="site-main" id="main">
      <PageHeader heading={index.title} lead={index.lead} />
      <Blocks blocks={index.body} />
      <VenueList venues={venues} />
    </main>
  );
}
