import { FormGroup } from '@angular/forms';

export function PasswordMatch(password: string, pw_match: string) {
	return (formGroup: FormGroup) => {
		const PASS = formGroup.controls[password];
		const MATCH = formGroup.controls[pw_match];

		if (MATCH.errors && !MATCH.errors.mustMatch) {
			return;
		}

		if (PASS.value !== MATCH.value) {
			MATCH.setErrors({ mustMatch: true });
		} else {
			MATCH.setErrors(null);
		}
	}
}
