import { getSiteSettings, getArticles } from '@/lib/directus'
import HeroSection from '@/components/home/HeroSection'
import ArticleGrid from '@/components/home/ArticleGrid'

export const revalidate = false

export default async function HomePage() {
  let heroArticle = null
  let latestArticles: import('@/lib/types').Article[] = []

  try {
    const [settings, articles] = await Promise.all([
      getSiteSettings(),
      getArticles({ limit: 13 }),
    ])
    heroArticle = settings.hero_article
    latestArticles = settings.hero_article
      ? articles.filter((a) => a.id !== settings.hero_article!.id)
      : articles.slice(0, 12)
  } catch {
    // Directus not available yet
  }

  return (
    <>
      {heroArticle && <HeroSection article={heroArticle} />}
      <ArticleGrid articles={latestArticles} title="Latest" />
    </>
  )
}
