import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { IClientModel } from '@fleio-api/client-user/model/client.model';
import { ClientsApiService } from '@fleio-api/client-user/client/clients-api.service';
import { ConfigService } from '@shared/config/config.service';
import { EmailMessageLogApiService } from '@fleio-api/logger/emai-message-log-api.service';
import { IEmailMessageLogModel } from '@fleio-api/logger/model/email-message-log.model';

@Component({
  selector: 'app-client-details-email-message-log',
  templateUrl: './client-details-email-message-log.component.html',
  styleUrls: ['./client-details-email-message-log.component.scss']
})
export class ClientDetailsEmailMessageLogComponent extends DetailsComponentBase<IClientModel> implements OnInit {
  emailMessageLogEntries: IEmailMessageLogModel[];
  displayedColumns: string[] = ['subject', 'to', 'created_at'];

  constructor(
    private clientsApi: ClientsApiService,
    private emailMessageLogApiService: EmailMessageLogApiService,
    public config: ConfigService,
    ngZone: NgZone,
    changeDetectorRef: ChangeDetectorRef,
  ) {
    super(ngZone, changeDetectorRef, config);
  }

  ngOnInit() {
    super.ngOnInit();
  }

  protected refreshData() {
    this.emailMessageLogApiService.list({
      client: this.object.id,
      page_size: 20,
    }).subscribe(journalEntries => {
      this.emailMessageLogEntries = journalEntries.objects;
    });
  }
}
