<script lang="ts">
	import { goto } from '$app/navigation';
	import { applicationStore } from '$lib/ApplicationsStore.svelte';
	import { post, preventDefault } from '$lib/utils';
	import NavBar from '../NavBar.svelte';

	const text = $state({
		text: ''
	});

	async function submit() {
		try {
			await post('application/text', text);
			applicationStore.loadApplications(true);
			goto('/');
		} catch (e) {
			console.log(e);
		}
	}
</script>

<NavBar />

<div class="flex justify-center h-4/6">
	<form onsubmit={preventDefault(submit)} class="card p-5 rounded-lg w-2/5">
		<fieldset>
			<label for="text" class="flabel">Text</label>
			<textarea id="text" class="finput h-96" bind:value={text.text}></textarea>
		</fieldset>
		<div class="btns">
			<button class="btn-confirm"> Submit </button>
		</div>
	</form>
</div>
