import React, { useEffect, useMemo, useState } from « react »;
import { motion } from « framer-motion »;
import { Button } from « @/components/ui/button »;
import { Card, CardContent } from « @/components/ui/card »;
import { Input } from « @/components/ui/input »;
import { UserPlus, Shuffle, RotateCcw, Trash2, Users, HelpCircle, ClipboardPaste, UserCheck, Settings } from « lucide-react »;
const DEFAULT_QUESTIONS = [
« Quel est votre projet en une phrase ? »,
« Quel est votre plus grand défi actuellement ? »,
« De quoi auriez-vous besoin dans les 3 prochains mois ? »,
« Quelle compétence pouvez-vous offrir aux autres entrepreneurs ? »,
« Quel conseil auriez-vous aimé recevoir au démarrage ? »,
« Quelle rencontre pourrait vous faire avancer ? »,
« Quel est votre prochain objectif concret ? »,
« Qu’est-ce qui vous différencie de vos concurrents ? »,
« Quelle erreur vous a le plus appris ? »,
« Si vous aviez une heure d’aide gratuite, sur quoi la demanderiez-vous ? »,
« Quel client idéal cherchez-vous à rencontrer ? »,
« Qu’est-ce qui vous bloque aujourd’hui ? »
];
function loadState() {
try {
const raw = localStorage.getItem(« speed-dating-questions-state-v2 »);
return raw ? JSON.parse(raw) : null;
} catch {
return null;
}
}
export default function SpeedDatingQuestionsApp() {
const saved = useMemo(() => loadState(), []);
const [participants, setParticipants] = useState(saved?.participants || [« Participant 1 », « Participant 2 »]);
const [currentUser, setCurrentUser] = useState(saved?.currentUser || « »);
const [questionsText, setQuestionsText] = useState(saved?.questionsText || DEFAULT_QUESTIONS.join(« \n »));
const [history, setHistory] = useState(saved?.history || {});
const [newParticipant, setNewParticipant] = useState(« »);
const [bulkParticipants, setBulkParticipants] = useState(« »);
const [currentQuestion, setCurrentQuestion] = useState(saved?.currentQuestion || « »);
const [adminMode, setAdminMode] = useState(saved?.adminMode ?? true);
const questions = useMemo(() => {
return questionsText
.split(« \n »)
.map((q) => q.trim())
.filter(Boolean);
}, [questionsText]);
const usedForCurrentUser = history[currentUser] || [];
const availableQuestions = questions.filter((q) => !usedForCurrentUser.includes(q));
useEffect(() => {
localStorage.setItem(
« speed-dating-questions-state-v2 »,
JSON.stringify({ participants, currentUser, questionsText, history, currentQuestion, adminMode })
);
}, [participants, currentUser, questionsText, history, currentQuestion, adminMode]);
function chooseUser(name) {
setCurrentUser(name);
setCurrentQuestion(« »);
}
function changeUser() {
setCurrentUser(« »);
setCurrentQuestion(« »);
}
function addParticipant() {
const name = newParticipant.trim();
if (!name || participants.includes(name)) return;
setParticipants((prev) => […prev, name]);
setNewParticipant(« »);
}
function importParticipantsFromSheet() {
const names = bulkParticipants
.split(/\n|\t|,|;/)
.map((name) => name.trim())
.filter(Boolean);
const uniqueNewNames = names.filter((name) => !participants.includes(name));
if (uniqueNewNames.length === 0) return;
setParticipants((prev) => [...prev, ...uniqueNewNames]);
setBulkParticipants("");
}
function removeParticipant(name) {
const remaining = participants.filter((p) => p !== name);
setParticipants(remaining);
setHistory((prev) => {
const copy = { …prev };
delete copy[name];
return copy;
});
if (currentUser === name) {
setCurrentUser(« »);
setCurrentQuestion(« »);
}
}
function drawQuestion() {
if (!currentUser || questions.length === 0) return;
let pool = availableQuestions;
let resetCycle = false;
if (pool.length === 0) {
pool = questions;
resetCycle = true;
}
const randomQuestion = pool[Math.floor(Math.random() * pool.length)];
setCurrentQuestion(randomQuestion);
setHistory((prev) => ({
...prev,
[currentUser]: resetCycle ? [randomQuestion] : [...(prev[currentUser] || []), randomQuestion]
}));
}
function resetCurrentUserHistory() {
if (!currentUser) return;
setHistory((prev) => ({ …prev, [currentUser]: [] }));
setCurrentQuestion(« »);
}
function resetAll() {
setHistory({});
setCurrentQuestion(« »);
}
if (!currentUser) {
return (
Speed dating entrepreneurs
Choisissez votre nom
Vous ne le ferez qu’une seule fois. Ensuite, l’application restera automatiquement sur votre profil.
))}
{participants.length === 0 &&
Aucun participant n’a encore été importé.
}
{adminMode && (
Copiez une colonne de noms depuis Google Sheets, puis collez-la ici.
onKeyDown={(e) => e.key === « Enter » && addParticipant()}
placeholder= »Nom du participant »
className= »rounded-2xl bg-white text-slate-900″
/>
Participants chargés : {participants.length}
)}
);
}
return (
Speed dating entrepreneurs
À vous de jouer, {currentUser}
Appuyez sur le bouton pour afficher votre prochaine question. Elle ne sera pas reposée à votre profil tant que toutes les questions n’auront pas été utilisées.
Question à traiter devant le groupe
{currentQuestion || « Appuyez sur le bouton pour tirer votre question. »}
{availableQuestions.length === 0 && questions.length > 0 && (
)}
Réglages animateur
{adminMode && (
Questions
Actions
)}
);
}