<script>
    import 'bootstrap/dist/css/bootstrap.min.css'
    import '@adminkit/core/dist/css/app.css'
    import '@adminkit/core/dist/js/app.js'
    import 'bootstrap-icons/font/bootstrap-icons.css'
    import '../assets/colors.css'
    import Navbar from './Navbar.svelte'
    import Sidebar from './Sidebar.svelte'
    import Footer from './Footer.svelte'
    import Notifications from './Notifications.svelte'
    import { routes } from '$/routes/user.routes'
    import { Router, Route, createHistory } from 'svelte-navigator'
    import hashHistory from './hashHistory'
    import { onMount } from 'svelte'
    import { getInfoToken } from '$/services/login'
    import { storeSession } from '$/stores/session'


    let triggerEvent = false;
    const history = createHistory(hashHistory())

    onMount(() => {
        triggerEvent && document.dispatchEvent(new Event('DOMContentLoaded'));
    })

    async function begin() {
        try {
            $storeSession = await getInfoToken()
        } catch (error) {
            alert(error.message || error)
        }
    }
    begin()
</script>

<div class="wrapper">
    <Router {history} primary={false}>
        <Sidebar />

        <div class="main">
            <Navbar />

            <main class="content">
                <div class="container-fluid p-0">

                    {#each routes as r}
                        <Route path={r.path} component={r.component} />
                    {/each}

                </div>
            </main>

            <Footer />
        </div>
    </Router>
</div>

<Notifications />