import { Component, Input, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { TeamInvite } from 'src/app/modules/teams/model/team-invite';

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

  @Input('teamInfo') teamInfo: TeamInvite | undefined;

  registerForm = new FormGroup({
    email: new FormControl('', [Validators.required, Validators.email]),
    password: new FormControl('', [Validators.required, Validators.minLength(6)]),
    lastName: new FormControl('', [Validators.required]),
    firstName: new FormControl('', [Validators.required]),
  });



  ngOnInit(): void {
    if (this.teamInfo) {
      let names = this.teamInfo.playerName.split(' ');
      if (names && names.length == 2) {
        this.registerForm.controls.firstName.patchValue(names[0])
        this.registerForm.controls.lastName.patchValue(names[1])
      }
    }
  }

  register() {

  }
}
