import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { Confirmation } from '../models';
@Injectable({
providedIn: 'root',
})
export class ConfirmationService {
private readonly requireConfirmation$ = new Subject<Confirmation | null>();
public requireConfirmationObs$: Observable<Confirmation | null>;
private readonly acceptConfirmation$ = new Subject<Confirmation | null>();
public acceptObs$: Observable<Confirmation | null>;
constructor() {
this.requireConfirmationObs$ = this.requireConfirmation$.asObservable();
this.acceptObs$ = this.acceptConfirmation$.asObservable();
}
confirm(confirmation: Confirmation): this {
this.requireConfirmation$.next(confirmation);
return this;
}
close(): this {
this.requireConfirmation$.next(null);
return this;
}
onAccept(): void {
this.acceptConfirmation$.next(null);
}
}
onDeleteProfileClick(event: Event): void {
event.preventDefault();
this.confirmationService.confirm({
header: this.translocoService.translate('PROFILE.DELETE_PROFILE'),
message: this.translocoService.translate('PROFILE.DELETE_PROFILE_CONFIRMATION'),
acceptLabel: this.translocoService.translate('PROFILE.DELETE_PROFILE'),
rejectLabel: this.translocoService.translate('SHARED.CANCEL'),
icon: 'icon-alert-triangle',
accept: () => {
console.log('ITT HÍVJUK AZ APIT A TÖRLÉSHEZ');
},
});
}