import React, { useEffect } from 'react'
import { render } from 'react-dom'
import { createInertiaApp } from '@inertiajs/inertia-react'
import { InertiaProgress } from '@inertiajs/progress'
import { NextUIProvider } from '@nextui-org/react';

import { Provider } from 'react-redux'
import store, {persistor} from './redux/store';
import { PersistGate } from 'redux-persist/integration/react';


const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Event Mall';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: name => import(`./Pages/${name}`),
    setup({ el, App, props }) {
        render(
            <NextUIProvider>
                <Provider store={store} >
                    <PersistGate loading={null} persistor={persistor} >
                        <App {...props} />
                    </PersistGate>
                </Provider>
            </NextUIProvider>
            , el)
    },
})

InertiaProgress.init({color: '#F7941D', showSpinner: true});
