import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.tsx';
import './index.css';
import 'tippy.js/dist/tippy.css';
import { Capacitor } from '@capacitor/core';
import { StatusBar, Style } from '@capacitor/status-bar';
import { handleSSOToken } from './lib/sso';

if (Capacitor.isNativePlatform()) {
  StatusBar.setStyle({ style: Style.Default }).catch(() => {});
  if (Capacitor.getPlatform() === 'ios') {
    StatusBar.setOverlaysWebView({ overlay: true }).catch(() => {});
  }
}

// Handle inbound SSO token before rendering — must be awaited so the session
// is established before any component reads auth state.
handleSSOToken().then(() => {
  createRoot(document.getElementById('root')!).render(
    <StrictMode>
      <App />
    </StrictMode>
  );
});
