import { Component, ChangeDetectionStrategy, Input, EventEmitter, Output } from '@angular/core';
import { Article, File } from '../../defs';

@Component({
  selector: 'app-file-list',
  templateUrl: 'file-list.component.html',
  styleUrls: ['./file-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FileListComponent {
  filesWithoutImgs: File[] = [];
  images: File[] = [];

  @Input() articles: Article[];
  @Input() set files(files: File[]) {
    if (!files) {
      return;
    }
    this.filesWithoutImgs = files.filter((file) => file.type !== 'img');
    this.images = files.filter((file) => file.type === 'img');
  }

  @Output() openFile = new EventEmitter<number>();

  constructor() {}

  previewFile(fileId: number) {
    this.openFile.emit(fileId);
  }
}
