import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { GoldForm } from '../components/GoldForm'

const el = document.getElementById('gold-app')
if (el) {
  const cEl = document.getElementById('gold-characters-data')
  const oEl = document.getElementById('gold-options-data')
  const characters: string[] = cEl ? JSON.parse(cEl.textContent || '[]') : []
  const options = oEl ? JSON.parse(oEl.textContent || '[]') : []
  createRoot(el).render(
    <StrictMode>
      <GoldForm url={el.dataset.url || ''} csrfToken={el.dataset.csrf || ''} characters={characters} options={options} />
    </StrictMode>,
  )
}
