import VideosPage from "./videos-page";

export const metadata = {
  title: "Study Abroad Videos | Educational Resources & Guides",
  description: "Watch helpful videos about studying abroad, university admissions, scholarship tips, and student experiences. Get expert advice through our video library.",
  siteName: process.env.NEXT_PUBLIC_APP_WEBSITE_NAME,
  openGraph: {
    title: "Study Abroad Videos | Educational Resources & Guides",
    description: "Watch helpful videos about studying abroad, university admissions, scholarship tips, and student experiences. Get expert advice through our video library.",
    url: `${process.env.NEXT_PUBLIC_APP_URL}/videos`,
    siteName: process.env.NEXT_PUBLIC_APP_WEBSITE_NAME,
    locale: "en_US",
    type: "website",
  },
  twitter: {
    card: "summary_large_image",
    title: "Study Abroad Videos | Educational Resources & Guides",
    description: "Watch helpful videos about studying abroad, university admissions, scholarship tips, and student experiences. Get expert advice through our video library.",
  },
  alternates: {
    canonical: `${process.env.NEXT_PUBLIC_APP_URL}/videos`,
  },
  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,
    },
  },
};

async function fetchVideos() {
  const response = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/frontend/allvideos`, {
    method: "GET",
    cache: 'no-store'
  });

  const data = await response.json();
  return data;
}

async function fetchCountries() {
  const response = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/frontend/getcountriesforvideos`, {
    method: "GET",
    cache: 'no-store'
  });

  const data = await response.json();
  return data;
}

export default async function Videos() {
  const [videosData, countriesData] = await Promise.all([
    fetchVideos(),
    fetchCountries()
  ]);

  return (
    <>
      <VideosPage 
        videos={videosData.data} 
        countries={countriesData.data || []}
      />
    </>
  );
}