import { Metadata } from "next";

import { CORE_ENDPOINTS } from "@/constants/api-mappings/external-api-mapping";
import { getOptions } from "@/services/general-actions";
import OpportunitiesList from "@/components/pages/participant/opportunities/opportunities-list";
import { retrieveUserSession } from "@/lib/user-session";

export const metadata: Metadata = {
  title: "Find your next paid research study",
  description:
    "Explore current paid research opportunities including online interviews, focus groups, and surveys. Connect with studies tailored to your profile and availability, and earn rewards by contributing valuable insights - all from the convenience of your home.",
  openGraph: {
    title: "Find your next paid research study",
    description:
      "Explore current paid research opportunities including online interviews, focus groups, and surveys. Connect with studies tailored to your profile and availability, and earn rewards by contributing valuable insights - all from the convenience of your home.",
    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: "Find your next paid research study",
    images: "/global-assets/pfr-logo-og-participant.svg",
    description:
      "Explore current paid research opportunities including online interviews, focus groups, and surveys. Connect with studies tailored to your profile and availability, and earn rewards by contributing valuable insights - all from the convenience of your home.",
  },
};

export default async function OpportunitiesListPage() {
  const { userId } = (await retrieveUserSession()) || {};

  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,
  };

  return <OpportunitiesList options={options} userId={userId} />;
}
