import Courses from "./courses";
import { getStaticPage } from "../../../lib/directQueries/allqueries";

const PAGE_SLUG = 'courses';

export async function generateMetadata() {
  const response = await getStaticPage(PAGE_SLUG);
  const page = response?.data;

  return {
    title: page?.meta_title || "Popular Study Abroad Courses | Find Your Program",
    description: page?.meta_description || "Explore top study abroad courses in 2026-27. Find programs in medicine, engineering, business & IT. Compare durations, fees & entry requirements.",
    openGraph: {
      title: page?.meta_title || "Popular Study Abroad Courses | Find Your Program",
      description: page?.meta_description || "Explore top study abroad courses in 2026-27. Find programs in medicine, engineering, business & IT. Compare durations, fees & entry requirements.",
      url: `${process.env.NEXT_PUBLIC_APP_URL}/${PAGE_SLUG}`,
      siteName: process.env.NEXT_PUBLIC_APP_WEBSITE_NAME,
      type: "website",
    },
    twitter: {
      card: "summary_large_image",
      title: page?.meta_title || "Popular Study Abroad Courses | Find Your Program",
      description: page?.meta_description || "Explore top study abroad courses in 2026-27. Find programs in medicine, engineering, business & IT. Compare durations, fees & entry requirements.",
    },
    alternates: {
      canonical: `${process.env.NEXT_PUBLIC_APP_URL}/${PAGE_SLUG}`,
    },
    robots: {
      index: true,
      follow: true,
      nocache: false,
      googleBot: {
        index: true,
        follow: true,
        noimageindex: false,
        "max-video-preview": -1,
        "max-image-preview": "large",
        "max-snippet": -1,
      },
    },
  };
}

export default async function CoursesPage() {
  const response = await getStaticPage(PAGE_SLUG);
  const pageData = response?.data || null;

  return (
    <>
      <Courses pageData={pageData} />
    </>
  );
}