import { Component, OnDestroy, OnInit } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { LicenseApiService } from '@fleio-api/core/license-api.service';

@Component({
  selector: 'app-license',
  templateUrl: './license.component.html',
  styleUrls: ['./license.component.scss']
})
export class LicenseComponent
  extends DetailsComponentBase<IBaseFleioObjectModel> implements OnInit, OnDestroy {

  public licenseInfo: { [key: string]: any } = null;
  public loadingLicenseInfo: boolean;

  constructor(private licenseApiService: LicenseApiService) {
    super();
  }

  protected initTabData() {
    this.loadingLicenseInfo = true;
    this.licenseApiService.getLicenseInfo().subscribe(licenseInfo => {
      this.licenseInfo = licenseInfo;
      this.loadingLicenseInfo = false;
    });
  }

  ngOnInit(): void {
    super.ngOnInit();
    this.initTabData();
  }

  ngOnDestroy(): void {
  }

  licenseInfoKeys(): string[] {
    return Object.keys(this.licenseInfo);
  }
}
