import PageTitle from "@/blocks/PageTitle";
import Pagination from "@/components/Pagination/Pagination";
import type { Metadata } from "next";
import Listing from "@/components/Listing/Listing";
import TwoColumn from "@/blocks/TwoColumn";
import { getCachedPosts } from "@/services/wp";
import { DEFAULT_OG_IMAGE, SITE_NAME } from "@/utils/constants";
import BreadcrumbLayout from "@/layouts/BreadcrumbLayout";

const title = `Insights | ${SITE_NAME}`;
const description = "This is where you can catch up on news, events, tips, tricks & various other bits and pieces from members of the Teapot team.";

const image = DEFAULT_OG_IMAGE;

export const metadata: Metadata = {
  metadataBase: new URL(process.env.SITE_URL),
  title: title,
  description: description,
  alternates: {
    canonical: "/insights",
  },
  openGraph: {
    title: title,
    description: description,
    url: `${process.env.SITE_URL}insights`,
    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 Insights = async () => {
  const currentPage = 1;
  const perPage = parseInt(process.env.BLOG_PAGINATION_PER_PAGE!) || 6;
  const siteUrl = process.env.SITE_URL || "https://teapot.agency";

  const posts = await getCachedPosts(currentPage, perPage);

  return (
    <BreadcrumbLayout
      siteUrl={siteUrl}
      items={[
        { label: "Home", href: "/" },
        { label: "Insights", href: "/insights" },
      ]}
    >
      <PageTitle
        title={
          "A deep dive into tech, trends and teachable moments."
        }
        supporting_title={"INSIGHTS"}
      />
      <TwoColumn
        left_content={
          "As we move toward a future of collaboration and growth, Teapot embraces the essence of thought leadership. In the ever-changing, and ever-challenging, digital world it is increasingly important to share authenticity, empowerment, and influence."
        }
        right_content={
          "We hope to foster genuine curiosity and a focus on passion and experience into our narrative, though insights that challenge the status quo, provoke creativity and nurture meaningful connections within our industry."
        }
      />
      <Listing posts={posts.posts}>
        <div className="mt-sm col-span-full flex items-center justify-center">
          <Pagination
            totalPages={Math.ceil(posts._paging.total / perPage)}
            currentPage={currentPage}
          />
        </div>
      </Listing>
    </BreadcrumbLayout>
  );
};

export default Insights;
