<script>
	import { createChannel } from '$lib/apiServer';

	let name = '';
	let pending = false;
	$: disabled = pending;

	async function handleSubmit() {
		pending = true;
		const response = await createChannel(name);
		if (200 <= response.status && response.status < 300) {
			name = '';
		}
		pending = false;
	}
</script>

<form on:submit|preventDefault={handleSubmit} class="form form-row flex-nowrap">
	<input
		type="text"
		placeholder="create channel"
		bind:value={name}
		{disabled}
		class="input flex-auto h-6 w-9/12"
	/>
	<button type="submit" class="flex-none w-6 h-6">&#x2795;</button>
</form>

<style>
</style>
