import { Component, OnInit } from '@angular/core';
import {Observable} from "rxjs";
import {EventService, Registration} from "../../services/event.service";
import {NavigationService} from "../../services/navigation.service";
import {flatMap, map, mergeMap} from "rxjs/operators";
import {RegistrationService} from "../../services/reservation.service";
import { faCalendarCheck, faCalendarMinus, faCalendarTimes } from '@fortawesome/free-solid-svg-icons';


@Component({
  selector: 'app-registrations',
  templateUrl: './registrations.component.html',
  styleUrls: ['./registrations.component.scss']
})
export class RegistrationsComponent implements OnInit {
  faCalendarCheck = faCalendarCheck;
  faCalendarMinus = faCalendarMinus;
  faCalendarTimes = faCalendarTimes;

  registrations: Observable<Registration[]>;
  constructor(private eventService: EventService,
              private navigationService: NavigationService,
              public registrationService: RegistrationService) { }

  ngOnInit() {
    this.registrations = this.eventService.findRegistrations()
      .pipe( map(
        (registration: Registration[]) => {
          registration = registration.sort( (a, b) => a.created_at - b.created_at);
          return registration;
        }
      ) );
  }

  showRegistration(registration: Registration) {
    this.navigationService.navigateRegistration(registration.id);
  }

}
