// Home screen — create tournament + recent rail const { useState, useRef, useEffect } = React; function HomeScreen({ onCreate, recent, onDelete }) { const [title, setTitle] = useState(''); const [name, setName] = useState(''); const [rules, setRules] = useState(''); const [winsNeeded, setWinsNeeded] = useState(2); const [bgColor, setBgColor] = useState('#05080e'); const [fighters, setFighters] = useState([]); const [draft, setDraft] = useState(''); const [err, setErr] = useState(''); const [registrationMode, setRegistrationMode] = useState(false); const [confirmDeleteId, setConfirmDeleteId] = useState(null); const [cloneId, setCloneId] = useState(null); // id do torneio para clonar const [cloning, setCloning] = useState(false); const inputRef = useRef(null); async function handleClone(id, withPlayers) { setCloning(true); try { const res = await fetch(`/api/tournaments/${id}/clone`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ withPlayers }), }); const data = await res.json(); if (res.ok) { window.location.href = `/champion/${data.id}`; } } catch {} finally { setCloning(false); setCloneId(null); } } function addFighter() { const v = draft.trim(); if (!v) return; if (fighters.some(f => f.toLowerCase() === v.toLowerCase())) { setErr('Esse participante já está na lista'); setTimeout(() => setErr(''), 2200); return; } setFighters([...fighters, v]); setDraft(''); inputRef.current?.focus(); } function removeFighter(i) { setFighters(fighters.filter((_, j) => j !== i)); } function loadDemo() { setName('Quartas Q3 — Time de Produto'); setFighters(['Camila Tavares', 'Rafael Bento', 'Helena Souza', 'Diogo Martins', 'Mariana Reis', 'Bruno Costa', 'Léo Andrade', 'Gustavo Lima']); } const canCreate = registrationMode ? name.trim().length > 0 : fighters.length >= 2; const rounds = Math.ceil(Math.log2(Math.max(fighters.length, 2))); const matchCount = canCreate && !registrationMode ? Math.pow(2, rounds) - 1 : 0; return (
{/* Left: form */}
01 Novo campeonato

Monte um chaveamento em segundos.

Adicione os participantes, sorteie automaticamente e clique para avançar cada combate. Sem login. Sem fricção.

setName(e.target.value)} placeholder="Ex: Copa do Time Q3" className="input" />
setTitle(e.target.value)} placeholder="Ex: Liga interna · finais" className="input" />
{[ { label: 'Melhor de 1', value: 1 }, { label: 'Melhor de 3', value: 2 }, { label: 'Melhor de 5', value: 3 }, { label: 'Melhor de 7', value: 4 }, ].map(opt => ( ))}
setBgColor(e.target.value)} className="bg-color-picker" title="Escolha a cor da arena" /> {bgColor}