import { ViteReactSSG } from 'vite-react-ssg';
import { routes } from './routes';
import './index.css';
import './i18n/i18n';

// 邀请码：在任何路由重定向发生前，尽早从 URL 捕获并持久化，
// 否则 /register?aff=xxx 落地时会被通配重定向到 / 而丢失，导致注册/OAuth 无法带上 aff_code。
// 仅浏览器执行；预渲染（Node）无 window/localStorage。
if (typeof window !== 'undefined') {
  try {
    const aff = new URLSearchParams(window.location.search).get('aff');
    if (aff) localStorage.setItem('aff', aff);
  } catch {}
}

export const createRoot = ViteReactSSG({ routes });
