import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

// Auto-redirect to correct login based on which app this is
// Set by the HTML entry point (admin.html / coach.html / student.html)
declare global {
  interface Window {
    APP_ROLE?: 'admin' | 'coach' | 'student';
  }
}

const role = window.APP_ROLE;
if (role && !window.location.hash.includes('/app')) {
  const routes: Record<string, string> = {
    admin: '#/admin',
    coach: '#/coach',
    student: '#/student',
  };
  window.location.hash = routes[role] || '#/admin';
}

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)
