import { Suspense } from "react";
import { redirect } from "next/navigation";
import { createSbServer } from "@/lib/supabaseServer";
import SignatureSalarieContent from "./SignatureSalarieContent";

export default async function SignatureSalariePage() {
  const sb = createSbServer();
  
  // Vérifier si on est en localhost
  const isLocalhost = process.env.NODE_ENV === 'development' || 
                      process.env.NEXT_PUBLIC_SITE_URL?.includes('localhost');
  
  // Récupérer le statut de maintenance uniquement si pas en localhost
  if (!isLocalhost) {
    const { data: maintenanceStatus } = await sb
      .from("maintenance_status")
      .select("*")
      .single();
    
    // Si en maintenance, rediriger vers la page de maintenance
    if (maintenanceStatus?.is_maintenance_mode) {
      redirect("/maintenance");
    }
  }

  return (
    <div className="min-h-screen bg-gray-50">
      <Suspense fallback={
        <div className="flex items-center justify-center min-h-screen">
          <div className="text-center">
            <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4"></div>
            <div className="text-gray-600">Chargement du formulaire de signature...</div>
          </div>
        </div>
      }>
        <SignatureSalarieContent />
      </Suspense>
    </div>
  );
}
