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

  let name = $state('');
  let disabled = $state(false);

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

<form onsubmit={handleSubmit}>
  <input type="text" placeholder="create channel" bind:value={name} {disabled} />
  <button type="submit">&#x2795;</button>
</form>
