import { Component, OnInit, ChangeDetectionStrategy, Input } from '@angular/core';
import { Article } from '../../../defs';
import { ClipboardService } from 'apps/sales/src/app/core/services/clipboard.service';

@Component({
  selector: 'app-file-list-articles',
  templateUrl: 'file-list-articles.component.html',
  styleUrls: ['../file-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FileListArticlesComponent implements OnInit {
  @Input() articles: Article[];

  constructor(private clipboardService: ClipboardService) {}

  ngOnInit() {}

  previewArticles() {}

  private generateEanString(articles: Article[]): string {
    return articles.map((article) => article.ean).join(';');
  }

  copyArticles() {
    this.clipboardService.copy(this.generateEanString(this.articles)).then(
      (result) => console.log('Copied to Clipboard: ', result)
      // TODO Add Snackbar Service
      /*         this.snackbar.open(
          `Die EAN-Liste wurde kopiert (${result})`,
          'Schließen',
          {
            duration: 5000,
            horizontalPosition: 'center',
            verticalPosition: 'top',
          }
        ) */
    );
  }
}
