import { contains } from 'ramda';

/**
 * Computes a file icon name for a particular media type
 * @param {string} type - Media type.
 * @returns {string|undefined} SUI file icon name
 */
export const getIconForMimeType = (type) => {
  const topLevelType = type.split('/')[0];
  if (contains(topLevelType, ['audio', 'image', 'video'])) {
    return topLevelType;
  }

  switch (type) {
    /* eslint-disable max-len */
    case 'application/gzip':
    case 'application/zip':
      return 'archive';

    case 'application/pdf':
      return 'pdf';

    case 'application/vnd.ms-excel':
    case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
    case 'application/vnd.openxmlformats-officedocument.spreadsheetml.template':
      return 'excel';

    case 'application/vnd.ms-powerpoint':
    case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
    case 'application/vnd.openxmlformats-officedocument.presentationml.template':
    case 'application/vnd.openxmlformats-officedocument.presentationml.slideshow':
      return 'powerpoint';

    case 'application/msword':
    case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
    case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
      return 'word';
    /* eslint-enable max-len */
  }
};
