import { useState } from 'react'; import { Match } from '../api/client'; import styles from './DevPanel.module.css'; const DEV_USERS = [ { id: 1, name: 'Ronny M.', role: 'Editor' }, { id: 2, name: 'Max M.', role: 'Viewer' }, { id: 3, name: 'Anna S.', role: 'Viewer' }, ]; const TIME_PRESETS = [ { label: 'In 2 Std.', minutes: 120 }, { label: 'In 10 Min.', minutes: 10 }, { label: 'Jetzt +1 Min.', minutes: 1 }, { label: 'Läuft (−30)', minutes: -30 }, { label: 'Beendet (−120)', minutes: -120 }, ]; const STATUS_PRESETS = [ { label: 'TIMED', status: 'TIMED', scoreHome: null, scoreAway: null }, { label: 'LIVE', status: 'IN_PLAY', scoreHome: 0, scoreAway: 0 }, { label: 'Pause', status: 'PAUSED', scoreHome: 1, scoreAway: 0 }, { label: '2:1 Fertig', status: 'FINISHED', scoreHome: 2, scoreAway: 1 }, { label: '0:0 Fertig', status: 'FINISHED', scoreHome: 0, scoreAway: 0 }, ]; interface Props { currentUser: number; onUserChange: (userId: number) => void; matches: Match[]; onRefresh: () => void; } export default function DevPanel({ currentUser, onUserChange, matches, onRefresh }: Props) { const [open, setOpen] = useState(false); const [selectedMatch, setSelectedMatch] = useState(''); const [busy, setBusy] = useState(false); const [log, setLog] = useState([]); function addLog(msg: string) { setLog(prev => [`${new Date().toLocaleTimeString('de-DE')} ${msg}`, ...prev].slice(0, 8)); } async function applyTime(minutes: number) { if (!selectedMatch) return; setBusy(true); try { await fetch(`/api/dev/match/${selectedMatch}/set-time`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ minutesFromNow: minutes }), }); addLog(`✓ Spiel #${selectedMatch}: Zeit → ${minutes > 0 ? `+${minutes}` : minutes} Min.`); onRefresh(); } catch (e) { addLog(`✗ Fehler: ${(e as Error).message}`); } finally { setBusy(false); } } async function applyStatus(status: string, scoreHome: number | null, scoreAway: number | null) { if (!selectedMatch) return; setBusy(true); try { await fetch(`/api/dev/match/${selectedMatch}/set-status`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ status, scoreHome, scoreAway }), }); addLog(`✓ Spiel #${selectedMatch}: Status → ${status}`); onRefresh(); } catch (e) { addLog(`✗ Fehler: ${(e as Error).message}`); } finally { setBusy(false); } } async function resetTips() { setBusy(true); try { await fetch('/api/dev/reset-tips', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: `dev-user-00${currentUser}` }), }); addLog(`✓ Tipps von User ${currentUser} gelöscht`); onRefresh(); } catch (e) { addLog(`✗ Fehler: ${(e as Error).message}`); } finally { setBusy(false); } } async function resetMatch(all: boolean) { setBusy(true); try { const body = all ? {} : { matchId: selectedMatch }; const res = await fetch('/api/dev/reset-match', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); const data = await res.json() as { count?: number; matchId?: number }; if (all) { addLog(`✓ ${data.count ?? 0} Spiele zurückgesetzt (TIMED)`); } else { addLog(`✓ Spiel #${selectedMatch} zurückgesetzt (TIMED)`); } onRefresh(); } catch (e) { addLog(`✗ Fehler: ${(e as Error).message}`); } finally { setBusy(false); } } // Nur erste 20 Spiele zur Auswahl anbieten const selectableMatches = matches.slice(0, 20); return (
{/* Toggle Button */} {open && (
🧪 Simulations-Modus
{/* User Switcher */}
Aktiver User
{DEV_USERS.map(u => ( ))}
{/* Match Selector */}
Spiel auswählen
{/* Zeit-Manipulation */}
Anstoßzeit setzen
{TIME_PRESETS.map(p => ( ))}
{/* Status-Manipulation */}
Status setzen
{STATUS_PRESETS.map(p => ( ))}
{/* Reset */}
Zurücksetzen
{/* Log */} {log.length > 0 && (
{log.map((l, i) =>
{l}
)}
)}
)}
); }