import { getTranslations } from 'next-intl/server';
import { Container } from '@/components/ui/container';
import { Reveal } from '@/components/ui/reveal';
import { BlogListing } from '@/components/listing/blog-listing';
import { getPublishedPosts, getTags } from '@/lib/queries';
import { buildMetadata } from '@/lib/seo';
import type { Locale } from '@/i18n/config';

export async function generateMetadata({ params: { locale } }: { params: { locale: Locale } }) {
  const t = await getTranslations({ locale, namespace: 'nav' });
  return buildMetadata({
    locale,
    path: '/blog',
    title: t('blog'),
    description:
      locale === 'ar'
        ? 'مقالات حول الطاقة الشمسية والاستدامة.'
        : "Articles sur l'énergie solaire, l'installation et la durabilité."
  });
}

export default async function BlogPage({ params: { locale } }: { params: { locale: Locale } }) {
  const [posts, tags] = await Promise.all([getPublishedPosts(locale), getTags(locale)]);

  return (
    <Container className="py-16">
      <Reveal variant="up">
        <h1 className="font-display text-3xl font-semibold">
          {locale === 'ar' ? 'المدونة' : 'Blog'}
        </h1>
      </Reveal>
      <BlogListing posts={posts} tags={tags} locale={locale} />
    </Container>
  );
}
