import { Component, inject, Input, output } from '@angular/core';
import { User } from '@app/domain/users/user.model';
import { FormBuilder, FormControl, Validators } from '@angular/forms';
import { AuthService } from '@app/core/services/authentication/auth.service';

@Component({
  selector: 'app-user-password-form',
  standalone: true,
  imports: [],
  templateUrl: './user-password-form.component.html',
  styleUrl: './user-password-form.component.scss',
})
export class UserPasswordFormComponent {
  @Input({ required: true }) user: User | undefined = undefined;
  onFormSubmitted = output<any>();

  private authService = inject(AuthService);

  private fb = inject(FormBuilder);

  protected userPasswordForm = this.fb.group({
    password: new FormControl('', [Validators.required]),
    passwordConfirm: new FormControl('', [Validators.required]),
    oldPassword: new FormControl('', [Validators.required]),
  });

  onUserPasswordFormSubmit() {
    if (this.userPasswordForm.invalid) {
      return;
    }

    const data = this.userPasswordForm.getRawValue();

    this.onFormSubmitted.emit(data);
  }
}
