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

const title = `Insights & Resources | ${SITE_NAME}`;
const description =
  "Insights, resources, and practical updates from the PrestaShop team.";
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/insights-and-resources`,
    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 InsightsAndResources = async () => {
  const currentPage = 1;
  const perPage = parseInt(process.env.BLOG_PAGINATION_PER_PAGE!) || 6;
  const posts = await getCachedPSPosts(currentPage, perPage);

  return (
    <>
      <PageTitle
        title={"Practical updates, ideas, and real-world eCommerce learnings."}
        supporting_title={"INSIGHTS & RESOURCES"}
      />
      <TwoColumn
        left_content={
          "We share trends, implementation notes, and practical content from our PrestaShop work to help teams make clearer product and technical decisions."
        }
        right_content={
          "Expect direct guidance, grounded case examples, and content built around what actually works in delivery."
        }
      />
      <Listing posts={posts.posts} postBasePath="/insights-and-resources">
        <div className="mt-sm col-span-full flex items-center justify-center">
          <Pagination
            totalPages={Math.ceil(posts._paging.total / perPage)}
            currentPage={currentPage}
            basePath="/insights-and-resources"
          />
        </div>
      </Listing>
    </>
  );
};

export default InsightsAndResources;
