<script lang="ts">
  import { loggedin } from '../store.js';
  import welcome from '$lib/images/svelte-welcome.webp';
	import welcome_fallback from '$lib/images/svelte-welcome.png';
	import Login from './Login.svelte';

  let isLoggedIn: Boolean;

	loggedin.subscribe(value => {
		isLoggedIn = value;
	});

  function login() {
    loggedin.set(true);
  }

  function logout() {
    loggedin.set(false);
  }
</script>

<svelte:head>
	<title>Ruderassistent - ASKÖ Ruderverein Donau Linz</title>
</svelte:head>

  {#if isLoggedIn}
    <p>Here comes the list</p>
    <button on:click={logout} class="btn btn-primary">
      Jetzt ausloggen
    </button>
  {:else}
  <div class="w-full max-w-md space-y-8">
    <div>
      <img class="mx-auto h-16 w-auto" src="https://rudernlinz.at/wp-content/uploads/2021/02/cropped-logo.png" alt="Logo Ruderassistent">
      <h1 class="mt-6 h1">Ruderassistent</h1>
    </div>

    <form class="mt-8 space-y-6" method="post" action="/auth">
      <input type="hidden" name="remember" value="true">
      <div class="-space-y-px rounded-md shadow-sm">
        <div>
          <div>
            <label for="name" class=" sr-only ">Name</label>
            <input id="name" name="name" type="input" value="" class="input rounded-t-md" placeholder="Name">
          </div>
        </div>
        <div>   
          <div>
            <label for="password" class=" sr-only ">Passwort</label>
            <input id="password" name="password" type="password" value="" class="input rounded-b-md" placeholder="Passwort">
          </div>
        </div>
      </div>

      <div>
        <button on:click={login} type="submit" class="group relative flex w-full justify-center btn btn-primary">
          <span class="absolute inset-y-0 left-0 flex items-center pl-3">
            <svg class="h-5 w-5 text-primary-300 group-hover:text-primary-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
              <path fill-rule="evenodd" d="M10 1a4.5 4.5 0 00-4.5 4.5V9H5a2 2 0 00-2 2v6a2 2 0 002 2h10a2 2 0 002-2v-6a2 2 0 00-2-2h-.5V5.5A4.5 4.5 0 0010 1zm3 8V5.5a3 3 0 10-6 0V9h6z" clip-rule="evenodd" />
            </svg>            
          </span>
          Einloggen
        </button>
      </div>
    </form>
  </div>
  {/if}
