export const dynamic = "force-dynamic";
import { cookies } from "next/headers";
import { createSbServer } from "@/lib/supabaseServer";
import { redirect } from "next/navigation";
import { Metadata } from "next";
import OffresPromoClient from "./OffresPromoClient";

export const metadata: Metadata = {
  title: "Offres promo | Staff | Espace Paie Odentas",
};

export default async function OffresPromoPage() {
  const sb = createSbServer();
  const { data: { user } } = await sb.auth.getUser();
  
  if (!user) {
    redirect("/signin");
  }

  // Vérifier que l'utilisateur est staff
  const { data: staffData } = await sb
    .from("staff_users")
    .select("is_staff")
    .eq("user_id", user.id)
    .maybeSingle();

  if (!staffData?.is_staff) {
    return (
      <main className="p-6">
        <h1 className="text-lg font-semibold">Accès refusé</h1>
        <p className="text-sm text-slate-600">Cette page est réservée au Staff.</p>
      </main>
    );
  }

  return <OffresPromoClient />;
}
