import { mountInertiaRoot } from './bootstrap-lite'
import React from 'react'
import { createInertiaApp } from '@inertiajs/react'

const pages = import.meta.glob([
  './Pages/Academy/**/*.jsx',
  '!./Pages/Academy/**/__tests__/**',
  '!./Pages/Academy/**/*.test.jsx',
])

function resolvePage(name) {
  const path = `./Pages/${name}.jsx`
  const page = pages[path]

  if (!page) {
    throw new Error(`Unknown academy page: ${path}`)
  }

  return page().then((module) => module.default)
}

createInertiaApp({
  resolve: resolvePage,
  setup({ el, App, props }) {
    mountInertiaRoot(el, App, props)
  },
})
