"use client"; import { useState } from "react"; import ImageSelector from "@/components/ImageSelector"; import UserManagement from "@/components/UserManagement"; import EventManagement from "@/components/EventManagement"; import FeedbackManagement from "@/components/FeedbackManagement"; interface SitePreferences { id: string; homeBackground: string | null; eventsBackground: string | null; leaderboardBackground: string | null; } interface AdminPanelProps { initialPreferences: SitePreferences; } type AdminSection = "preferences" | "users" | "events" | "feedbacks"; export default function AdminPanel({ initialPreferences }: AdminPanelProps) { const [activeSection, setActiveSection] = useState("preferences"); const [preferences, setPreferences] = useState( initialPreferences ); const [isEditing, setIsEditing] = useState(false); const [formData, setFormData] = useState({ homeBackground: initialPreferences.homeBackground || "", eventsBackground: initialPreferences.eventsBackground || "", leaderboardBackground: initialPreferences.leaderboardBackground || "", }); const handleEdit = () => { setIsEditing(true); }; const handleSave = async () => { try { const response = await fetch("/api/admin/preferences", { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(formData), }); if (response.ok) { const data = await response.json(); setPreferences(data); setIsEditing(false); } } catch (error) { console.error("Error updating preferences:", error); } }; const handleCancel = () => { setIsEditing(false); if (preferences) { setFormData({ homeBackground: preferences.homeBackground || "", eventsBackground: preferences.eventsBackground || "", leaderboardBackground: preferences.leaderboardBackground || "", }); } }; return (

ADMIN

{/* Navigation Tabs */}
{/* Mobile: Grid layout */}
{/* Desktop: Horizontal tabs */}
{activeSection === "preferences" && (

Préférences UI Globales

Images de fond du site

Ces préférences s'appliquent à tous les utilisateurs

{!isEditing && ( )}
{isEditing ? (
setFormData({ ...formData, homeBackground: url, }) } label="Background Home" /> setFormData({ ...formData, eventsBackground: url, }) } label="Background Events" /> setFormData({ ...formData, leaderboardBackground: url, }) } label="Background Leaderboard" />
) : (
Home: {preferences?.homeBackground ? (
Home background { e.currentTarget.src = "/got-2.jpg"; }} /> {preferences.homeBackground}
) : ( Par défaut )}
Events: {preferences?.eventsBackground ? (
Events background { e.currentTarget.src = "/got-2.jpg"; }} /> {preferences.eventsBackground}
) : ( Par défaut )}
Leaderboard: {preferences?.leaderboardBackground ? (
Leaderboard background { e.currentTarget.src = "/got-2.jpg"; }} /> {preferences.leaderboardBackground}
) : ( Par défaut )}
)}
)} {activeSection === "users" && (

Gestion des Utilisateurs

)} {activeSection === "events" && (

Gestion des Événements

)} {activeSection === "feedbacks" && (

Gestion des Feedbacks

)}
); }