import { Component, OnInit,Input } from '@angular/core';
import {RestaurantesService} from "../../restaurantes.service";

@Component({
  selector: 'app-modal-usuario',
  templateUrl: './modal-usuario.component.html',
  styleUrls: ['./modal-usuario.component.scss']
})
export class ModalUsuarioComponent implements OnInit {

  @Input() user: any;
  user_add: any = null;
  usuarios: any;

  possible_roles = [
    {id: 'global_admin', name: 'Administrador Global'},
    {id: 'admin', name: 'Administrador'},
    {id: 'recaudador', name: 'Recaudador'},
    {id: 'productor', name: 'Productor'},
    {id: 'mesero', name: 'Mesero'},
  ];

  constructor(private restaurantServ: RestaurantesService) { 
    this.user_add = {
      nombre: null,
      username: null,
      email: null,
      password: null,
      roles: [],
      restaurant: null,
    }
  }

  ngOnInit(): void {
    this.recuperarUsuarios();
  }

  recuperarUsuarios(){
    this.restaurantServ.mostrarUsuarios().subscribe(result => this.usuarios = result)
  }

  AgregarUsu(){
    this.restaurantServ.agregarUsu(this.user_add).subscribe(this.recuperarUsuarios)
  }

  eliminarUsu(id:any){
    if(confirm("Esta seguro de eliminar este registro?")){
      this.restaurantServ.eliminarUsu(id).subscribe();
    }
  }

  modificarUsu(id:any){
    this.restaurantServ.moficiarUsu(this.user).subscribe();
  }


}
