<script>
import { emit, listen } from '@tauri-apps/api/event';
import queue from './lib/queue.js';
import Home from './views/Home.svelte';
import Approve from './views/Approve.svelte';
import ShowApproved from './views/ShowApproved.svelte';
import ShowDenied from './views/ShowDenied.svelte';

const VIEWS = {
    Home: Home,
    Approve: Approve,
    ShowApproved: ShowApproved,
    ShowDenied: ShowDenied,
};


let currentView = Home;
function navigate(event) {
    currentView = VIEWS[event.detail.target];
}

listen('credentials-request', (event) => {
    queue.put(1)
});

let requests = queue();
</script>

{#if currentView === Home}
    <svelte:component this={currentView} on:navigate={navigate} {requests} />
{:else}
    <svelte:component this={currentView} on:navigate={navigate} />
{/if}
