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 { DEFAULT_OG_IMAGE, SITE_NAME } from "@/utils/constants";
import { getCachedPSCaseStudies } from "@/services/prestashop-wp";

const title = `Case Studies | ${SITE_NAME}`;
const description =
  "Discover how we help eCommerce teams solve real delivery and growth challenges.";
const image = DEFAULT_OG_IMAGE;

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

const CaseStudies = async () => {
  const studies = await getCachedPSCaseStudies(30);

  return (
    <>
      <PageTitle
        title={"Real outcomes from complex eCommerce delivery."}
        supporting_title={"CASE STUDIES"}
      />
      <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={`/case-studies/${study.slug}`}
                imageUrl={study.featured_image?.source}
                title={study.title.rendered}
                excerpt={study.excerpt.rendered || ""}
              />
            </Fragment>
          ))}
        </Section>
      </Container>
    </>
  );
};

export default CaseStudies;
