import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DataDescriptionArticle } from '../../../../../interfaces/acquisition-management/artitle.interface';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';

@Component({
    selector: 'app-priority-article',
    templateUrl: './priority-article.component.html',
    styleUrl: './priority-article.component.css',
    standalone: false
})
export class PriorityArticleComponent implements OnInit {
  
  constructor (
    @Inject(MAT_DIALOG_DATA) public arrItems: DataDescriptionArticle[],
  ) {
    console.log(arrItems);
  }
  
  ngOnInit() {
    console.log(this.arrItems)
  }

  drop(event: CdkDragDrop<string[]>) {
    moveItemInArray(this.arrItems, event.previousIndex, event.currentIndex);
  }
  
  public setImage (dataDescription: DataDescriptionArticle) {
    if (dataDescription.ARCHIVOS.length === 0) {
      return 'assets/img/empty_img_2.svg';
    } else {
      return dataDescription.ARCHIVOS[0].SHOW;
    }
  }
  
  public setAlt (dataDescription: DataDescriptionArticle) {
    if (dataDescription.ARCHIVOS.length === 0) {
      return 'no_data';
    } else {
      return dataDescription.ARCHIVOS[0].NAME;
    }
  }
}
