import PropTypes from 'prop-types';
import { keys, omit } from 'ramda';
import React from 'react';
import { Icon } from 'semantic-ui-react';

import { getIconForMimeType } from '../../lib';

/* Interface */
const propTypes = {
  /** Whether to use the outline icon variant for the type. */
  outline: PropTypes.bool,

  /** MIME type */
  type: PropTypes.string,
};

/* Defaults */
const defaultProps = {
  type: '',
};

/**
 * File icon
 * Renders an SUI icon to match a file type.
 * @param {Object} props - React component props.
 * @returns {Object} React element.
 */
export const FileIcon = (props) => {
  const { outline, type } = props;

  const nameParts = ['file'];

  const icon = getIconForMimeType(type);
  if (icon) {
    nameParts.push(icon);
  }

  if (outline) {
    nameParts.push('outline');
  }

  return (
    <Icon
      name={ nameParts.join(' ') }
      { ...omit(keys(propTypes), props) }
    />
  );
};

FileIcon.propTypes = propTypes;
FileIcon.defaultProps = defaultProps;

export default FileIcon;
