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

// Migrate localStorage keys from old naming
function migrateKeys() {
  const migrations = [
    ['eysines_players', 'baseballista_players'],
    ['eysines_matches', 'baseballista_matches'],
    ['eysines_schedule', 'baseballista_schedule'],
    ['eysines_seed_version', 'baseballista_seed_version'],
  ]
  for (const [oldKey, newKey] of migrations) {
    const data = localStorage.getItem(oldKey)
    if (data && !localStorage.getItem(newKey)) {
      localStorage.setItem(newKey, data)
      localStorage.removeItem(oldKey)
    }
  }
}

migrateKeys()
seedIfNeeded()

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