import PageTitle from "@/blocks/PageTitle";
import Container from "@/components/Container/Container";
import Section from "@/components/Section/Section";
import type { Metadata } from "next";
import { Fragment } from "react";
import Card from "@/components/Card/Card";
import { getCachedCaseStudies } from "@/services/wp";
import { DEFAULT_OG_IMAGE, SITE_NAME } from "@/utils/constants";


const title = `Work | ${SITE_NAME}`;
const description = "Discover how Teapot has helped multiple businesses in a variety of industries to achieve their goals through our work.";
const image = DEFAULT_OG_IMAGE;

export const metadata: Metadata = {
  metadataBase: new URL(process.env.SITE_URL),
  title: title,
  description: description,
  alternates: {
    canonical: "/work",
  },
  openGraph: {
    title: title,
    description: description,
    url: `${process.env.SITE_URL}work`,
    siteName: SITE_NAME,
    images: [
      {
        url: image,
        width: 1200,
        height: 630,
      },
    ],
    locale: "en_GB",
    type: "website",
  },
  twitter: {
    card: "summary_large_image",
    title: title,
    description: description,
    images: [image],
  },
};

const Work = async () => {
  const studies = await getCachedCaseStudies(15);

  return (
    <>
      <PageTitle
        title={"A closer look at our favourite work."}
        supporting_title={"WORK"}
      />
      <Container>
        <Section
          gridArea="wide"
          className="grid auto-rows-auto grid-cols-1 lg:grid-cols-3 gap-y-sm gap-x-md"
        >
          {studies.map((study: any, index: number) => (
            <Fragment key={index}>
              <Card
                href={`/work/${study.slug}`}
                imageUrl={study.featured_image.source}
                title={study.title.rendered}
                excerpt={study.excerpt.rendered || ""}
              />
            </Fragment>
          ))}
        </Section>
      </Container>
    </>
  );
};

export default Work;
