<template>
    <div class="login">
      <h2 class="mb-4">Luca Girişi</h2>
      <form @submit.prevent="login">
        <div class="form-group">
          <label for="username">Kullanıcı Adı:</label>
          <input type="text" id="username" class="form-control" v-model="username" required>
        </div>
        <div class="form-group">
          <label for="password">Şifre:</label>
          <input type="password" id="password" class="form-control" v-model="password" required>
        </div>
        <button style="margin-top: 15px;" type="submit" class="btn btn-primary">Login</button>
      </form>
    </div>
  </template>
  
  <script>
  import {Login} from "../../bindings/main/LoginService.js";
  export default {
    data() {
      return {
        username: '',
        password: ''
      };
    },
    methods: {
        
      login() {
        let that = this
        Login(this.username, this.password).then((resultValue) => {
          let value = resultValue;
          console.log("entered")
          if(value.LoggedIn)
          {
            that.$router.push({ name: 'Dashboard' });
          }
        }).catch((err) => {
          console.log(err);
        });
        
      }
    }
  };
  </script>
<!-- 
<script setup>
import { ref, onMounted } from 'vue'
import {Login} from "../../bindings/main/LoginService";
import {Events} from "@wailsio/runtime";

const name = ref('')
const result = ref('Please enter your name below 👇')
const time = ref('Listening for Time event...')

const doLogin = () => {
  let localName = name.value;
  if (!localName) {
    localName = 'anonymous';
  }
  Login(localName).then((resultValue) => {
    result.value = resultValue;
  }).catch((err) => {
    console.log(err);
  });
}

onMounted(() => {
  Events.On('time', (timeValue) => {
    time.value = timeValue.data;
  });
})

defineProps({
  msg: String,
})

</script> -->
