import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { DmpInvitationService } from '@app/core/services/dmp/dmp-invitation.service';
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';

@Component({
	selector: 'app-dmp-invitation-accepted-component',
	templateUrl: 'dmp-invitation-accepted.component.html',

})
export class InvitationAcceptedComponent extends BaseComponent implements OnInit {
	constructor(
		private dmpInvitationService: DmpInvitationService,
		private route: ActivatedRoute,
		private router: Router
	) { super(); }

	ngOnInit(): void {
		this.route.params
			.pipe(takeUntil(this._destroyed))
			.subscribe(params => {
				const id = params['id'];
				this.dmpInvitationService.exchange(id)
					.pipe(takeUntil(this._destroyed))
					.subscribe(result => {
						this.router.navigate(['plans/edit/' + result]);
					});
			});
	}
}
