import './bootstrap'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { createInertiaApp } from '@inertiajs/react'

const pages = import.meta.glob('./Pages/Moderation/**/*.jsx')

createInertiaApp({
  resolve: (name) => {
    const page = pages[`./Pages/${name}.jsx`]

    if (!page) {
      throw new Error(`Unknown moderation page: ./Pages/${name}.jsx`)
    }

    return page().then((module) => module.default)
  },
  setup({ el, App, props }) {
    const root = createRoot(el)
    root.render(<App {...props} />)
  },
})