<script>
    import { goto } from '$app/navigation';
    import { setup } from '$lib/apiServer';

    import LogIn from '$lib/components/LogIn.svelte';

    let disabled;
    let username;
    let password;

    async function onSubmit() {
        disabled = true;
        const response = await setup(username, password);
        if (200 <= response.status && response.status < 300) {
            username = '';
            password = '';
            goto('/');
        }
        disabled = false;
    }
</script>

<LogIn bind:disabled bind:username bind:password legend="set up" on:submit={onSubmit} />
