import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { User } from 'src/app/models/user.model';
import * as countries_json from "../../../../assets/data/country_codes.json";
import { HitAWodService } from 'src/app/services/hit-a-wod.service';

@Component({
  selector: 'app-new-user-dialog',
  templateUrl: './new-user-dialog.component.html',
  styleUrls: ['./new-user-dialog.component.css']
})
export class NewUserDialogComponent implements OnInit {

  @Input() company_id:number;
  @Output() close:EventEmitter<User> = new EventEmitter();

  user:User = new User();
  accept:Boolean = false;
  countries:any = countries_json;

  constructor(private api:HitAWodService) { }

  ngOnInit(): void {

  }

  isDisabled() {
    if(this.user.name == null) return true;
    if(this.user.surnames == null) return true;
    if(this.user.email == null) return true;
    if(this.user.nif == null) return true;
    if(this.user.gender == null) return true;
    if(this.user.date_of_birth == null) return true;
    if(this.user.address == null) return true;
    if(this.user.zipcode == null) return true;
    if(this.user.poblacio == null) return true;
    if(this.user.country == null) return true;
    if(!this.accept) return true;

    return false;
  }

  createUser() {
    this.api.registerUser(this.user).subscribe(
      data => {
        this.close.emit(data);
      }
    );
  }

}
