import { createRoot } from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { IS_SUPABASE_MODE } from '@/lib/config'
import { loadData } from '@/data/portalBids'
import { loadDecisions } from '@/lib/decisions'
import { loadFeedback } from '@/lib/feedback'
import { loadWorkflows } from '@/lib/workflow'
import { loadRoster } from '@/lib/roster'

// Render IMMEDIATELY (2026-07-21 perf: the old flow blocked even the login
// screen behind every data fetch). In live mode the bootstrap does NOT run
// here: pre-auth every query comes back empty under RLS, and the wasted
// round-trips raced the login screen for bandwidth — AuthGate runs the real
// load once a session exists (2026-08-27 perf). Fixture mode keeps the
// startup load; there is no login screen in front of it.
createRoot(document.getElementById("root")!).render(<App />);
if (!IS_SUPABASE_MODE) {
  void loadData()
    .then(() => Promise.all([loadDecisions(), loadFeedback(), loadWorkflows(), loadRoster()]))
    .catch((e) => console.error("[PortalPro] background bootstrap failed", e));
}
