import { createInertiaApp } from '@inertiajs/vue3';
import { createApp, h } from 'vue';
import KviewUiHost from '@/components/KviewUiHost.vue';
import type { SharedPageProps } from '@/types/inertia';

export const bootstrapInertia = (): void => {
    void createInertiaApp<SharedPageProps>({
        pages: {
            path: './Pages',
            extension: '.vue',
            lazy: true,
        },
        title: (title) => title ? `${title} · kView INVESTOR` : 'kView INVESTOR',
        progress: {
            color: '#1245fc',
            showSpinner: false,
        },
        setup({ el, App, props, plugin }) {
            if (!el) {
                return;
            }

            createApp({
                render: () => h(KviewUiHost, {
                    initialUi: props.initialPage.props.ui,
                }, {
                    default: () => h(App, props),
                }),
            })
                .use(plugin)
                .mount(el);
        },
    });
};
