import { Component, OnInit } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { IClientModel } from '@fleio-api/client-user/model/client.model';
import { ClipboardService } from '@shared/ui-api/clipboard.service';
import { ClientsApiService } from '@fleio-api/client-user/client/clients-api.service';
import { ConfigService } from '@shared/config/config.service';
import { NotificationService } from '@shared/ui-api/notification.service';

@Component({
  selector: 'app-client-details-referral',
  templateUrl: './client-details-referral.component.html',
  styleUrl: './client-details-referral.component.scss'
})
export class ClientDetailsReferralComponent extends DetailsComponentBase<IClientModel> implements OnInit {
  referralData = null;
  loading = false;

  constructor(
    public clipboard: ClipboardService,
    private clientsApi: ClientsApiService,
    public config: ConfigService,
    private notificationService: NotificationService,
  ) {
    super();

  }

  ngOnInit(refreshTimerInterval?: number) {
    super.ngOnInit(refreshTimerInterval);
  }

  protected tabActivated() {
    super.tabActivated();
    this.loading = true;
    this.clientsApi.referralData(this.object.id).subscribe({
      next: value => {
        this.referralData = value;
      }, error: error => {
        this.notificationService.showMessage(error.error.detail);
      }
    }).add(() => {
      this.loading = false;
    });
  }


}
