import { Component, inject, OnInit } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { User } from './models/user';
import {FormsModule}  from '@angular/forms'
import { UserService } from './services/user.service';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, FormsModule],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent implements OnInit {
  
  title = 'RTI';

  user: User = new User()

  allUsers: User[] = []

  private userService = inject(UserService)

  ngOnInit(): void {
    this.userService.getUser().subscribe(data=>{
      this.user = data
    })

    this.userService.getAllUsers().subscribe(data=>{
      this.allUsers = data
    })
  }

  username = ""
  password = ""

  login(){
    this.userService.login(this.username, this.password).subscribe(data=>{
      if(data==null){
        alert("No")
      }
      else{
        alert("Yes")
      }
    })
  }


}
