import { useState } from "react"; import { useStore } from "../store"; export default function ProfileModal({ onClose, blocking }: { onClose: () => void; blocking?: boolean }) { const { profiles, activeProfileId, setActiveProfile, createProfile, deleteProfile } = useStore(); const [newName, setNewName] = useState(""); const [error, setError] = useState(""); async function handleCreate() { const name = newName.trim(); if (!name) return; if (profiles.find(p => p.name === name)) { setError("Un profil avec ce nom existe déjà."); return; } await createProfile(name); setNewName(""); setError(""); if (blocking) onClose(); } async function handleDelete(id: string) { if (profiles.length <= 1) { setError("Vous ne pouvez pas supprimer le dernier profil."); return; } await deleteProfile(id); } return (
{ if (!blocking && e.target === e.currentTarget) onClose(); }}>

{blocking ? "Bienvenue — créez votre profil" : "Profils"}

{!blocking && ( )}
{/* Profile list — masquée en mode blocking (aucun profil existant) */} {!blocking && (
{profiles.map(profile => (
{profiles.length > 1 && ( )}
))}
)} {/* Create new profile */}

Nouveau profil

{ setNewName(e.target.value); setError(""); }} onKeyDown={e => e.key === "Enter" && handleCreate()} placeholder="Nom du profil…" style={{ flex: 1, background: "#0d1117", border: "1px solid #2d3748", borderRadius: "6px", padding: "7px 10px", color: "#e2e8f0", fontSize: "12px", outline: "none", }} onFocus={e => (e.target.style.borderColor = "#f0c040")} onBlur={e => (e.target.style.borderColor = "#2d3748")} />
{error &&

{error}

}
); }