import { Component } from '@angular/core';
import { PasswordWrapper } from '../../core/entities';
import { ChangePasswordService } from './change-password.service';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';

@Component({
	selector: 'app-change-password',
	templateUrl: './change-password.component.html',
	styles: [`
		#form.card-body {
			padding-bottom: 10px;
		}

		.submitFormArea {
			line-height: 50px;
		}
	`]
})
export class ChangePasswordComponent {
	model: PasswordWrapper = new PasswordWrapper('', '', '');

	error: string;

	constructor(
		private changePasswordService: ChangePasswordService
	) {}

	onSubmit(): void {
		if (this.model.newPassword !== this.model.confirmPassword) {
			this.error = 'Les mots de passe saisis ne correspondent pas.';
		} else {
			this.changePasswordService.changePassword(this.model).subscribe(null, error => {
				this.error = 'Le mot de passe saisi ne correspond pas au votre.';
			});
		}
	}
}
