'use client'; import { useEffect, useState } from 'react'; type Player = { id: string; first_name: string; last_name: string; position: string; team: string; status: string; }; type DoctorNote = { doctor_name: string; rating: string; explanation: string; }; const POSITIONS = ['QB', 'RB', 'WR', 'TE', 'FLEX', 'K', 'DEF']; const DOCTORS = ['Gabriel', 'Jimmy', 'Mikey', 'Tekky']; const SUPABASE_URL = 'https://ebdnuydfgbzhlvkaxrvj.supabase.co'; const SUPABASE_KEY = 'sb_publishable_4b1DqAbsw88I9pQV0qM90A_iWQcT4Qe'; export default function Home() { const [currentView, setCurrentView] = useState<'landing' | 'clinic'>('landing'); const [authModalOpen, setAuthModalOpen] = useState(false); const [activeDoctor, setActiveDoctor] = useState(null); const [activeTab, setActiveTab] = useState('QB'); const [players, setPlayers] = useState([]); const [selectedPlayerId, setSelectedPlayerId] = useState(''); const [loading, setLoading] = useState(true); const [doctorNotes, setDoctorNotes] = useState>({}); const [editingRating, setEditingRating] = useState('DRAFT'); const [editingExplanation, setEditingExplanation] = useState(''); // Fetch players using Supabase REST API useEffect(() => { if (currentView !== 'clinic') return; async function fetchPlayers() { setLoading(true); let url = `${SUPABASE_URL}/rest/v1/players?select=*`; if (activeTab === 'FLEX') { url += `&position=in.(RB,WR,TE)`; } else { url += `&position=eq.${activeTab}`; } url += `&limit=200`; try { const res = await fetch(url, { headers: { 'apikey': SUPABASE_KEY, 'Authorization': `Bearer ${SUPABASE_KEY}` } }); const data = await res.json(); if (Array.isArray(data) && data.length > 0) { setPlayers(data); setSelectedPlayerId(data[0].id); } else { setPlayers([]); setSelectedPlayerId(''); } } catch (err) { console.error('Error fetching players:', err); } setLoading(false); } fetchPlayers(); }, [activeTab, currentView]); // Fetch doctor notes and votes when player changes useEffect(() => { if (!selectedPlayerId) return; async function fetchNotes() { try { const res = await fetch(`${SUPABASE_URL}/rest/v1/doctor_notes?player_id=eq.${selectedPlayerId}&select=doctor_name,rating,explanation`, { headers: { 'apikey': SUPABASE_KEY, 'Authorization': `Bearer ${SUPABASE_KEY}` } }); const data = await res.json(); const notesMap: Record = {}; if (Array.isArray(data)) { data.forEach((note: DoctorNote) => { notesMap[note.doctor_name] = note; }); } setDoctorNotes(notesMap); if (activeDoctor && notesMap[activeDoctor]) { setEditingRating(notesMap[activeDoctor].rating); setEditingExplanation(notesMap[activeDoctor].explanation); } else { setEditingRating('DRAFT'); setEditingExplanation(''); } } catch (err) { console.error('Error fetching notes:', err); } } fetchNotes(); }, [selectedPlayerId, activeDoctor]); const handleSaveNote = async (ratingToSave: string) => { if (!activeDoctor || !selectedPlayerId) { setAuthModalOpen(true); return; } setEditingRating(ratingToSave); const explanationToSave = editingExplanation || 'No diagnostic notes logged.'; try { // Upsert doctor vote await fetch(`${SUPABASE_URL}/rest/v1/doctor_votes`, { method: 'POST', headers: { 'apikey': SUPABASE_KEY, 'Authorization': `Bearer ${SUPABASE_KEY}`, 'Content-Type': 'application/json', 'Prefer': 'resolution=merge-duplicates' }, body: JSON.stringify({ player_id: selectedPlayerId, doctor_name: activeDoctor, verdict: ratingToSave }) }); // Upsert doctor notes await fetch(`${SUPABASE_URL}/rest/v1/doctor_notes`, { method: 'POST', headers: { 'apikey': SUPABASE_KEY, 'Authorization': `Bearer ${SUPABASE_KEY}`, 'Content-Type': 'application/json', 'Prefer': 'resolution=merge-duplicates' }, body: JSON.stringify({ player_id: selectedPlayerId, doctor_name: activeDoctor, rating: ratingToSave, explanation: explanationToSave }) }); setDoctorNotes((prev) => ({ ...prev, [activeDoctor]: { doctor_name: activeDoctor, rating: ratingToSave, explanation: explanationToSave } })); } catch (err) { console.error('Error saving vote/note:', err); } }; const selectedPlayer = players.find((p) => p.id === selectedPlayerId); return (
{/* VIEW 1: LANDING PAGE */} {currentView === 'landing' && (
Professional Dynasty Medical Board

Diagnose. Draft. Dominate.

Welcome to Roster Doctors. The definitive clinical audit suite for high-stakes dynasty fantasy football leagues. Review player medicals, record clinical diagnosis notes, and sync collective expert verdicts across the board.

👨‍⚕️

Multi-Doctor Panel

Clock in as Dr. Gabriel, Jimmy, Mikey, or Tekky to lock in distinct team medical evaluations and notes.

📋

Consensus Verdicts

Evaluate prospects instantly with real-time DRAFT, STASH, or FADE ratings synced securely.

Live Search & Roster

Filter through complete positional depth charts and rookie classes instantly on the fly.

)} {/* VIEW 2: CLINIC WORKSPACE */} {currentView === 'clinic' && (
{POSITIONS.map((pos) => ( ))}
{loading ? (
Loading roster database...
) : (
)}
{selectedPlayer && (
Player { (e.target as HTMLElement).style.display = 'none'; }} />

{selectedPlayer.first_name} {selectedPlayer.last_name}

{selectedPlayer.team || 'FA'} {selectedPlayer.position} • {selectedPlayer.status || 'Active'}
{activeDoctor ? `Dr. ${activeDoctor}'s Verdict` : 'Sign in to log verdict'}