import { redirect } from 'next/navigation';
import { getServerSession } from 'next-auth';
import Link from 'next/link';
import { authOptions } from '@/lib/auth';
import { BrandName } from '@/components/ui/brand-name';
import type { Locale } from '@/i18n/config';

const links = [
  { href: '', label: 'Tableau de bord' },
  { href: '/products', label: 'Produits' },
  { href: '/categories', label: 'Catégories' },
  { href: '/services', label: 'Services' },
  { href: '/blog', label: 'Blog' },
  { href: '/authors', label: 'Auteurs' },
  { href: '/tags', label: 'Tags' },
  { href: '/projects', label: 'Réalisations' },
  { href: '/testimonials', label: 'Témoignages' },
  { href: '/faqs', label: 'FAQ' },
  { href: '/quotes', label: 'Demandes de devis' },
  { href: '/messages', label: 'Messages' }
];

export default async function AdminLayout({
  children,
  params: { locale }
}: {
  children: React.ReactNode;
  params: { locale: Locale };
}) {
  const session = await getServerSession(authOptions);

  if (!session) {
    redirect(`/${locale}/admin/login`);
  }

  return (
    <div className="flex min-h-screen bg-paper-100">
      <aside className="w-60 shrink-0 border-e border-graphite-800/10 bg-graphite-950 p-6 text-paper-50">
        <p className="text-xs font-semibold uppercase tracking-widest text-paper-100/40">Espace admin</p>
        <div className="mt-1 font-display text-lg font-semibold">
          <BrandName className="text-paper-50" accentClass="text-copper-400" />
        </div>
        <nav className="mt-8 space-y-1 text-sm">
          {links.map((link) => (
            <Link
              key={link.href}
              href={`/${locale}/admin${link.href}`}
              className="block rounded-lg px-3 py-2 text-paper-100/70 hover:bg-paper-50/5 hover:text-paper-50"
            >
              {link.label}
            </Link>
          ))}
        </nav>
      </aside>
      <div className="flex-1 p-8">{children}</div>
    </div>
  );
}
