import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms'
import { UserService } from '../services/user.service';
import { Router, RouterLink } from '@angular/router';

@Component({
  selector: 'app-login',
  standalone: true,
  imports: [FormsModule, RouterLink],
  templateUrl: './login.component.html',
  styleUrl: './login.component.css'
})
export class LoginComponent {

  private userService = inject(UserService)
  private router = inject(Router)

  username = ""
  password = ""
  message = ""

  login(){
    this.userService.login(this.username, this.password).subscribe(data=>{
      if(data){
        this.router.navigate(['books'])
      }
      else{
        this.message = "Error"
      }
    })
  }
}
