import { About } from "@/components/About";
import { ContactCta } from "@/components/ContactCta";
import { Hero } from "@/components/Hero";
import { Marquee } from "@/components/Marquee";
import { News } from "@/components/News";
import { Projects } from "@/components/Projects";
import { Services } from "@/components/Services";
import { SiteFooter } from "@/components/SiteFooter";
import { SiteHeader } from "@/components/SiteHeader";
import { contact, site } from "@/data/site";
import { getBlogs, getPortfolios, toDisplayNewsItem, toDisplayProject } from "@/lib/api";

const organizationJsonLd = {
  "@context": "https://schema.org",
  "@type": "Organization",
  name: site.name,
  url: site.url,
  slogan: site.tagline,
  foundingDate: "2000",
  address: {
    "@type": "PostalAddress",
    addressLocality: "قم",
    addressCountry: "IR",
    streetAddress: contact.address,
  },
  telephone: contact.phoneLinks,
  email: contact.email,
  sameAs: [contact.instagramUrl],
};

export default async function HomePage() {
  const [portfolios, newsPosts] = await Promise.all([getPortfolios(), getBlogs("news")]);
  const displayProjects = portfolios.map(toDisplayProject);
  const displayNews = newsPosts.slice(0, 3).map(toDisplayNewsItem);

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
      />

      <SiteHeader />

      <main>
        <Hero />
        <About />
        <Marquee />
        <Projects projects={displayProjects} />
        <Services />
        <News items={displayNews} />
        <ContactCta />
      </main>

      <SiteFooter />
    </>
  );
}
