import { useState } from "react"; import { useStore } from "../store"; export default function SettingsPanel({ onClose }: { onClose: () => void }) { const { profiles, activeProfileId, setActiveProfile, createProfile, deleteProfile, syncGuides, syncing, syncProgress, } = useStore(); const [newName, setNewName] = useState(""); const [profileError, setProfileError] = useState(""); const [syncErrors, setSyncErrors] = useState([]); const [syncDone, setSyncDone] = useState(false); async function handleCreate() { const name = newName.trim(); if (!name) return; if (profiles.find(p => p.name === name)) { setProfileError("Un profil avec ce nom existe déjà."); return; } await createProfile(name); setNewName(""); setProfileError(""); } async function handleDelete(id: string) { if (profiles.length <= 1) { setProfileError("Vous ne pouvez pas supprimer le dernier profil."); return; } await deleteProfile(id); } async function handleSync() { setSyncErrors([]); setSyncDone(false); const result = await syncGuides(); setSyncErrors(result.errors); setSyncDone(true); } const { current = 0, total = 0, label = "" } = syncProgress ?? {}; const syncPct = total > 0 ? Math.round((current / total) * 100) : 0; return (
{/* Header */}
Paramètres
{/* Scrollable content */}
{/* ── Profils ── */}
Profils
{profiles.map(profile => { const isActive = profile.id === activeProfileId; return (
{profiles.length > 1 && ( )}
); })}
{ setNewName(e.target.value); setProfileError(""); }} onKeyDown={e => e.key === "Enter" && handleCreate()} placeholder="Nouveau profil…" style={{ flex: 1, background: "#161b22", 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")} />
{profileError &&

{profileError}

}
{/* ── Synchronisation ── */}
Synchronisation

Met à jour tous les guides depuis Google Sheets.

{syncing && syncProgress && (
{label} {current}/{total} — {syncPct}%
)} {syncDone && !syncing && (
{syncErrors.length === 0 ? "✓ Synchronisation terminée." : `⚠ ${syncErrors.length} erreur(s) :\n${syncErrors.join("\n")}`}
)}
); } function SectionTitle({ children }: { children: React.ReactNode }) { return (
{children}
); }