import React from 'react'
import { createRoot, hydrateRoot } from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import { App } from './App'

const rootEl = document.getElementById('root')
const initialData = window.__INITIAL_DATA__ || null
const initialUrl = window.location.pathname + window.location.search

const app = (
  <BrowserRouter>
    <App initialData={initialData} initialUrl={initialUrl} />
  </BrowserRouter>
)

if (rootEl && rootEl.children.length > 0) {
  hydrateRoot(rootEl, app)
} else if (rootEl) {
  createRoot(rootEl).render(app)
}
