import { Component, OnInit, ChangeDetectionStrategy, Inject } from '@angular/core';
import { ModalDialogData } from 'apps/sales/src/app/core/overlay/modal-dialog-data';
import { Article, File } from '../../defs';
import { Observable, of } from 'rxjs';

import { Store, select } from '@ngrx/store';
import { DisplayInfoDTO } from '@swagger/eis';
import { selectTaskById } from 'apps/sales/src/app/store/branch/task-calendar/task-calendar.selectors';

@Component({
  selector: 'app-modal-edit-task',
  templateUrl: './edit-task.component.html',
  styleUrls: ['./edit-task.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EditTaskComponent implements OnInit {
  task$: Observable<DisplayInfoDTO>;
  files$: Observable<File[]>;
  articles$: Observable<Article[]>;

  constructor(@Inject(ModalDialogData) public data: ModalDialogData<number>, private store: Store<any>) {}

  ngOnInit() {
    this.task$ = this.getTask(this.data.data);
    this.files$ = this.getFiles(this.data.data);
    this.articles$ = this.getArticles(this.data.data);
  }

  closeModal() {
    if (this.data.ref) {
      this.data.ref.close();
    }
  }

  private getTask(taskId: number): Observable<DisplayInfoDTO> {
    return this.store.pipe(select(selectTaskById, taskId));
  }

  private getArticles(taskId: number): Observable<Article[]> {
    return of([]);
  }

  private getFiles(taskId: number): Observable<File[]> {
    return of([]);
  }

  openFilePreview(fileId: number) {}
}
