import { createInertiaApp } from '@inertiajs/react'
import { createRoot } from 'react-dom/client'
import '@/css/app.css'

const appName = '{{ project_name.title() }}'

document.addEventListener('DOMContentLoaded', () => {
  createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => {
      const pages = import.meta.glob('./pages/**/page.{% if use_typescript %}tsx{% else %}jsx{% endif %}', { eager: true })
      return pages[`./pages/${name}/page.{% if use_typescript %}tsx{% else %}jsx{% endif %}`]
    },
    setup({ el, App, props }) {
      createRoot(el).render(<App {...props} />)
    },
  progress: {
    color: '#4B5563',
  },
})
})