import { redirect } from 'next/navigation';
import { getCurrentUser } from '@/lib/auth';
import { hasPageAccess } from '@/lib/permissions';
import DashboardLayout from '@/components/DashboardLayout';
import DashboardContent from '@/components/DashboardContent';

export default async function DashboardPage() {
  const user = await getCurrentUser();

  if (!user) {
    redirect('/login');
  }

  // Vérifier les permissions
  const hasAccess = await hasPageAccess(user.id, '/dashboard');
  if (!hasAccess) {
    redirect('/dashboard/parametres'); // Rediriger vers une page accessible ou afficher une erreur
  }

  return (
    <DashboardLayout user={user}>
      <DashboardContent userName={user.name} />
    </DashboardLayout>
  );
}
