import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { GeneralService } from '../../services/generalservice';

@Component({
  selector: 'app-login-register',
  standalone: false,
  templateUrl: './login-register.component.html',
  styleUrl: './login-register.component.css',
})
export class LoginRegisterComponent implements OnInit {
  @Output() registeredEventSubmit = new EventEmitter<any>();
  registerFrm!: FormGroup;
  currentStep = 1;

  constructor(){}

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

  setupFormControl(): void {
    this.registerFrm = new FormGroup({
      username: new FormControl('',[Validators.required, Validators.maxLength(100)]),
      userlastname: new FormControl('',[Validators.required, Validators.maxLength(100)]),
      email: new FormControl('',[Validators.required, Validators.email, Validators.maxLength(100)]),
      password: new FormControl('',[Validators.required, Validators.maxLength(50)]),
      confirmPassword: new FormControl('',[Validators.required, Validators.maxLength(50)]),
      terms: new FormControl(false, [Validators.requiredTrue])
    });
  }

  onSubmit(){
    let data = {
      username: this.registerFrm.get('username')?.value,
      userlastname: this.registerFrm.get('userlastname')?.value,
      email: this.registerFrm.get('email')?.value,
      password: this.registerFrm.get('password')?.value
    }
    this.RegisteredEventSubmit(data);
  }

  RegisteredEventSubmit(event: any){
    this.registeredEventSubmit.emit(event);
  }
}
