// app/(main)/page.js
import Hero from '../components/organisms/Hero';
import PopularUniversities from "../components/organisms/PopularUniversities";
import PopularCourses from "../components/organisms/PopularCourses";
import LatestArticles from "../components/organisms/LatestArticles";
import BrowseCourses from "../components/organisms/BrowseCourses";
import StudentReviews from "../components/organisms/StudentReviews";
import YouTubeVideos from "../components/YouTubeVideos";
import CountryList from "../components/molecules/country";
import PartnersSection from "../components/organisms/PartnersSection";
import SuccessStories from "../components/organisms/SuccessStories";
import ScholarshipsSection from "../components/organisms/ScholarshipsSection";

import {getPopularCourses, getPopularUniversities, getBrowseCoursesData, getFeaturedScholarshipsWithQualifications, getFeaturedYouTubeVideos, getFeaturedStudentReviews, getFeaturedSuccessStories, getFeaturedBlogs, getFeaturedPartners } from "../../lib/directQueries/allqueries";
import FAQSection from '../components/FAQSection';


export async function generateMetadata() {
  const baseUrl = process.env.NEXT_PUBLIC_APP_URL_DOMAIN;
  
  return {
    title: "Study Abroad Admission - Apply Free to Top Universities Worldwide",
    description: "Universities Page study abroad consultants offer expert international education services to help you find the best countries and programs to study abroad.",
    keywords: [
      "study abroad", "university admission", "scholarships", "MBBS abroad",
      "visa consultants", "overseas education", "study overseas"
    ],
    alternates: {
      canonical: baseUrl,
    },
    openGraph: {
      title: "Study Abroad Admission - Apply Free to Top Universities Worldwide",
      description: "Universities Page study abroad consultants offer expert international education services to help you find the best countries and programs to study abroad.",
      url: baseUrl,
      siteName: process.env.NEXT_PUBLIC_APP_WEBSITE_NAME,
      images: [
        {
          url: `${baseUrl}/assets/hero.webp`,
          width: 1200,
          height: 630,
          alt: "Study Abroad Opportunities",
        },
      ],
      type: "website",
    },
    twitter: {
      card: "summary_large_image",
      title: "Study Abroad Admission - Apply Free to Top Universities Worldwide",
      description: "Universities Page study abroad consultants offer expert international education services to help you find the best countries and programs to study abroad.",
      images: [
        {
          url: `${baseUrl}/assets/hero.webp`,
          width: 1200,
          height: 630,
          alt: "Study Abroad Opportunities",
        },
      ],
    },
    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 fetchData() {
  const [courseData, uniData, browseData, scholarshipsData, videoData, reviewsData, storiesData, blogData, partnersData] = await Promise.all([
    getPopularCourses(),
    getPopularUniversities(),
    getBrowseCoursesData(),
    getFeaturedScholarshipsWithQualifications(),
    getFeaturedYouTubeVideos(),
    getFeaturedStudentReviews(),
    getFeaturedSuccessStories(),
    getFeaturedBlogs(),
    getFeaturedPartners() 
  ]);

  return { 
    uniData, 
    courseData, 
    blogData, 
    storiesData,
    browseData,
    reviewsData: reviewsData.data || [],
    partnersData: partnersData.data || [],
    scholarshipsData: scholarshipsData.data || [],
    videoData: videoData.data || []
  };
}

export default async function Home() {
  const { 
    uniData, 
    courseData, 
    blogData, 
    storiesData,
    browseData,
    reviewsData,
    partnersData,
    scholarshipsData,
    videoData
  } = await fetchData();

  const faqs = [
      {
        question: "What services do international education consultants provide?",
        answer: "Our international education consultants help students explore Higher Education Abroad, Study Abroad Programs, and Overseas Education Opportunities. From university selection to application guidance, they ensure students make informed decisions about their study abroad journey.",
      },
      {
        question: "Why should I work with Study abroad consultants?",
        answer: "Study abroad consultants offer expert advice on program choices, scholarships, and visa processes. They simplify complex steps, helping students focus on academics while accessing trusted Global Education Services.",
      },
      {
        question: "How can Universities Page consultants abroad help me?",
        answer: "Our Universities Page consultants abroad guide students through application processes, student visa requirements, and admission documentation. They connect you with top-ranked universities worldwide and offer personalized support for a smooth study abroad experience.",
      },
      {
        question: "How do international education consultants assist with university applications?",
        answer: "International education consultants provide step-by-step guidance on university applications, helping with essays, recommendation letters, and document submission. They ensure your profile matches the requirements of top universities for Higher Education Abroad.",
      },
      {
        question: "Can Study abroad consultants help me find scholarships?",
        answer: "Yes! Study abroad consultants identify scholarship opportunities, guide you in preparing applications, and provide advice on eligibility, deadlines, and documentation. This ensures students maximize funding for Overseas Education Opportunities.",
      },
      {
        question: "What support do Universities Page consultants abroad offer for student visas?",
        answer: "Our Universities Page consultants abroad offer expert Student Visa & Admission Services, including guidance on visa applications, document verification, and interview preparation, making the process smooth and stress-free.",
      },
      {
        question: "Why choose Study abroad consultants over self-guided applications?",
        answer: "Study abroad consultants save time, reduce errors, and increase acceptance chances. With professional advice on admissions, scholarships, and visas, you're guided through every step for a successful Higher Education Abroad journey.",
      },
      {
        question: "Are Universities Page consultants abroad trustworthy for global education guidance?",
        answer: "Yes! Our Universities Page consultants abroad have extensive experience helping students apply to top universities worldwide. They provide end-to-end Global Education Services, from course selection to admission and visa support, ensuring a seamless study abroad experience.",
      }
    ];

  // Extract the arrays from the nested structure
  const levelsData = browseData.data?.levels || [];
  const universitiesData = browseData.data?.universities || [];
  const subjectsData = browseData.data?.subjects || [];

  return (
    <>
      <Hero />

      <div>
        <CountryList />
        <PopularCourses data={courseData} />
        <PopularUniversities data={uniData} />
        <BrowseCourses 
          levels={levelsData} 
          universities={universitiesData} 
          subjects={subjectsData} 
        />
        <ScholarshipsSection scholarshipsData={scholarshipsData} />
        <YouTubeVideos videoData={videoData} />
        <StudentReviews reviewsData={reviewsData} />
        <SuccessStories stories={storiesData.data} />
        <FAQSection faqs={faqs} />
        <LatestArticles data={blogData} />
        <PartnersSection partnersData={partnersData} />
      </div>
    </>
  );
}