import { Injectable } from '@angular/core';
import {
  faFileAlt,
  faFileExcel,
  faFileImage,
  faFilePdf,
  faFilePowerpoint,
  faFileWord,
} from '@fortawesome/free-solid-svg-icons';
import { MessageService } from 'primeng/api';

@Injectable({
  providedIn: 'root',
})
export class UtilsService {
  constructor(private messageService: MessageService) {}

  /**
   * @description get icon and color from filename
   *
   * @param {*} filename
   * @returns
   * @memberof UtilsService
   */
  getIconByFile(filename: string) {
    const ext = filename.split('.').pop() ?? '';
    let faDownload = faFileAlt;
    let iconClass = 'text-black';
    switch (ext.toLowerCase()) {
      case 'doc':
      case 'docx':
      case 'docm':
      case 'dotx':
      case 'dotm':
        faDownload = faFileWord;
        iconClass = 'iconWord';
        break;

      case 'xsl':
      case 'xlsx':
      case 'xlsm':
      case 'xltx':
      case 'xltm':
      case 'xlsb':
      case 'xlam':
        faDownload = faFileExcel;
        iconClass = 'iconExcel';
        break;

      case 'ppt':
      case 'pptx':
      case 'pptm':
      case 'potx':
      case 'potm':
      case 'ppam':
      case 'ppsx':
      case 'ppsm':
      case 'sldx':
      case 'sldm':
      case 'thmx':
        faDownload = faFilePowerpoint;
        iconClass = 'iconPowerPoint';
        break;

      case 'art':
      case 'bmp':
      case 'gif':
      case 'ico':
      case 'jpeg':
      case 'jpg':
      case 'psd':
      case 'raw':
      case 'tiff':
      case 'tif':
      case 'ai':
      case 'svg':
      case 'png':
        faDownload = faFileImage;
        iconClass = 'iconImg';
        break;

      case 'pdf':
        faDownload = faFilePdf;
        iconClass = 'iconPdf';
        break;

      default:
        faDownload = faFileAlt;
        break;
    }
    return {
      icon: faDownload,
      class: iconClass,
    };
  }

  showAlert(severity: string, summary: string, detail: string, life = 5000) {
    this.messageService.add({ severity, summary, detail, life });
  }
}
