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

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

	let username = $state(''),
		password = $state('');
	let pending = false;
	let disabled = $derived(pending);

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

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