import { Component, OnInit } from '@angular/core';
import { Application } from 'src/app/core/entities/Application';
import { ApplicationStatus } from 'src/app/core/entities/ApplicationStatus';
import { ApplicationService } from 'src/app/core/services/application.service';
import { ModalService } from 'src/app/core/services/modal.service';

@Component({
  selector: 'app-status',
  templateUrl: './status.component.html',
  styleUrls: ['./status.component.scss']
})
export class StatusComponent implements OnInit {
  applicationsStatus: ApplicationStatus[] = [];

  constructor(
    private _applicationService: ApplicationService,
    private _modalService: ModalService
  ) {}

  ngOnInit(): void {
    this.loadApplications();
    this._modalService.onClose.subscribe(() => this.loadApplications());
  }

  private loadApplications(): void {
    this._applicationService.getAllStatus()
        .then(applicationsStatus => this.applicationsStatus = applicationsStatus);
  }
}
