<!--
ScheduleTogether Frontend
Copyright (C) 2024, Zervó Zadachin

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License version 3 for more details.

This program is built in two major frameworks, and incorporates external libraries for certain functionalities.
These frameworks and libraries are covered by their respective licenses, and their usage
agreements are as outlined in their respective documentation or source
code.

This program uses assets and resources provided by third parties, and are likely not covered by this copyright notice. 
See their respective directories and relevant notices.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<template>
  <div class="text-h4 text-center">
    Sign in
  </div>
  <br>
  <v-form
    v-model="form"
    @submit.prevent="onSubmit"
  >
    <v-text-field
      v-model="email"
      :readonly="loading"
      :rules="[required]"
      variant="outlined"
      class="mb-2"
      label="Email"
      clearable
    />

    <v-text-field
      v-model="password"
      :readonly="loading"
      :rules="[required]"
      variant="outlined"
      label="Password"
      :append-inner-icon="passwordvis ? 'mdi-eye-outline' : 'mdi-eye-off-outline'"
      :type="passwordvis ? 'text' : 'password'"
      placeholder="Enter your password"
      clearable
      @click:append-inner="() => (passwordvis = !passwordvis)"
    />

    <br>

    <v-btn
      :disabled="!form"
      :loading="loading"
      color="primary"
      size="large"
      type="submit"
      variant="elevated"
      block
    >
      Sign In
    </v-btn>
  </v-form>
</template>

<script setup lang="ts">
  import { ref } from 'vue'

  const form = ref<boolean>(false);
  const email = ref<string | null>(null);
  const password = ref<string | null>(null);
  const passwordvis = ref<boolean>(false);
  const loading = ref<boolean>(false);

  function onSubmit () {
    if (!form.value) return

    loading.value = true

    setTimeout(() => (loading.value = false), 2000)
  }
  
  function required (v: never) {
    return !!v || 'Field is required'
  }
</script>