import { Metadata } from "next";
import { notFound } from "next/navigation";

import { CORE_ENDPOINTS } from "@/constants/api-mappings/external-api-mapping";
import { getOldOpportunities } from "@/services/opportunities";
import { getOptions } from "@/services/general-actions";
import PastOpportunitiesList from "@/components/pages/participant/opportunities/past-opportunities";

export const revalidate = 3600;

export const metadata: Metadata = {
  title: "Past research opportunities",
  description:
    "See previous paid research studies and projects that our participants took part in and got paid for. Learn more about the types of research we offer.",
  openGraph: {
    title: "Past research opportunities",
    description:
      "See previous paid research studies and projects that our participants took part in and got paid for. Learn more about the types of research we offer.",
    images: [
      {
        url: "/global-assets/pfr-logo-og-participant.svg",
        alt: "People for Research logo, featuring a person inside a circle, representing a focus on human-centered research and activities.",
        width: 200,
        height: 150,
      },
    ],
  },
  twitter: {
    card: "summary_large_image",
    title: "Past research opportunities",
    images: "/global-assets/pfr-logo-og-participant.svg",
    description:
      "See previous paid research studies and projects that our participants took part in and got paid for. Learn more about the types of research we offer.",
  },
};

export default async function OpportunitiesListPage() {
  notFound();

  const optionEndpoints = [
    CORE_ENDPOINTS.options.currency,
    CORE_ENDPOINTS.options.typeOfStudy,
    CORE_ENDPOINTS.options.paymentMethod,
    CORE_ENDPOINTS.options.jobTopic,
    CORE_ENDPOINTS.options.formatOfResearch,
  ];

  const [
    currencyOptions,
    typeOfStudyOptions,
    paymentMethods,
    jobTopicOptions,
    formatOfResearchOptions,
  ] = await Promise.all(
    optionEndpoints.map((endpoint) => getOptions(endpoint)),
  );

  const options = {
    currencyOptions,
    typeOfStudyOptions,
    paymentMethods,
    jobTopicOptions,
    formatOfResearchOptions,
  };

  const opportunityList = await getOldOpportunities();

  return (
    <PastOpportunitiesList listOfOpps={opportunityList} options={options} />
  );
}
