import React, { useEffect, useState } from "react"; import { http } from "../lib/api"; import { X, User as UserIcon, Sparkles, Palette, ShieldCheck, AlertTriangle, Trash2, LogOut, Save, Moon, Sun, Monitor, Shield, CreditCard, FileText, Link2, } from "lucide-react"; import { toast } from "sonner"; import { SubscriptionSection } from "./SubscriptionPlans"; import AgentPermissionsPanel from "./AgentPermissionsPanel"; import AdminPanel from "./AdminPanel"; import ConnectedAccountsPanel from "./ConnectedAccountsPanel"; const THEME_OPTIONS = [ { id: "dark", label: "Sombre", Icon: Moon }, { id: "light", label: "Clair", Icon: Sun }, { id: "system", label: "Système", Icon: Monitor }, ]; const NAV_ITEMS = [ { id: "profile", label: "Profil", Icon: UserIcon }, { id: "connections", label: "Comptes connectés", Icon: Link2 }, { id: "subscription", label: "Abonnement", Icon: CreditCard }, { id: "appearance", label: "Apparence", Icon: Palette }, { id: "instructions", label: "Instructions", Icon: FileText }, { id: "agent", label: "Agent", Icon: Shield }, ]; export default function ProfileDrawer({ open, onClose, onLogout, themeMode, onThemeModeChange, agentOnline, desktopOnline, debugEvents, onClearDebugEvents, initialSection = "profile", }) { const [profile, setProfile] = useState(null); const [section, setSection] = useState("profile"); const [name, setName] = useState(""); const [addon, setAddon] = useState(""); const [saving, setSaving] = useState(false); const [confirmDelete, setConfirmDelete] = useState(""); useEffect(() => { if (!open) return; setSection(initialSection || "profile"); http.get("/profile").then((r) => { setProfile(r.data); setName(r.data.user.name || ""); setAddon(r.data.preferences.custom_prompt_addon || ""); }); }, [open, initialSection]); const save = async () => { setSaving(true); try { await http.patch("/profile", { name, custom_prompt_addon: addon, theme_mode: themeMode, }); toast.success("Profil enregistré"); } catch (e) { toast.error("Erreur"); } finally { setSaving(false); } }; const refreshProfile = async () => { const r = await http.get("/profile"); setProfile(r.data); }; const resetLicense = async () => { if (!window.confirm("Réinitialiser la licence ?")) return; await http.post("/profile/reset-license"); toast.success("Licence réinitialisée"); const r = await http.get("/profile"); setProfile(r.data); }; const deleteAccount = async () => { if (confirmDelete !== "SUPPRIMER") { toast.error("Tape SUPPRIMER pour confirmer"); return; } await http.delete("/profile"); onLogout(); }; if (!open) return null; const isAdmin = profile?.license?.is_admin; const navItems = isAdmin ? [...NAV_ITEMS, { id: "admin", label: "Admin", Icon: Sparkles }] : NAV_ITEMS; return ( <>
> ); } const Field = ({ label, children }) => (