var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import Icon from '../../../base/Icon';
import './style.css';

var DecorativeLink = function DecorativeLink(props) {
  var _classNames;

  var showFileIcon = props.showFileIcon,
      className = props.className,
      href = props.href,
      info = props.info,
      text = props.text,
      details = props.details,
      icon = props.icon,
      rest = _objectWithoutProperties(props, ['showFileIcon', 'className', 'href', 'info', 'text', 'details', 'icon']);

  var classes = classNames((_classNames = {
    'ma__decorative-link': true,
    'ma__download-link': showFileIcon
  }, _classNames[props.className] = className, _classNames));
  var decIcon = null;
  var title = void 0;
  if (showFileIcon) {
    // eslint-disable-next-line no-bitwise
    var getFileExtension = function getFileExtension(filename) {
      return filename.slice((filename.lastIndexOf('.') - 1 >>> 0) + 2);
    };
    var ext = getFileExtension(href);
    title = ext + ' file';
    var genericFile = ['csv', 'doc', 'docm', 'dot', 'dotx', 'dwg', 'geojson', 'gif', 'json', 'jpg', 'kml', 'kmz', 'mp3', 'mpp', 'msg', 'odf', 'ods', 'odt', 'png', 'pps', 'ppsx', 'potx', 'ppt', 'pptm', 'pptx', 'ppsm', 'prx', 'pub', 'rdf', 'rtf', 'tiff', 'tsv', 'txt', 'xls', 'xlsb', 'xlsm', 'xml', 'zip'];
    ext = genericFile.indexOf(ext) !== -1 ? 'generic' : ext;
    switch (ext) {
      case 'pdf':
        decIcon = React.createElement(Icon, { name: 'pdf', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'docx':
        decIcon = React.createElement(Icon, { name: 'docx', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'xlxs':
        decIcon = React.createElement(Icon, { name: 'xlxs', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'generic':
        decIcon = React.createElement(Icon, { name: 'generic', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      default:
        decIcon = null;
    }
  }
  return React.createElement(
    'span',
    { className: classes },
    React.createElement(
      'a',
      _extends({}, rest, {
        href: href,
        title: info || null
      }),
      decIcon && React.createElement(
        'span',
        { className: 'ma__download-link--icon' },
        decIcon,
        '\xA0'
      ),
      text,
      details && React.createElement(
        'span',
        { className: 'ma__decorative-link__details' },
        '\xA0',
        details
      ),
      '\xA0',
      icon || React.createElement(Icon, { name: 'arrow', 'aria-hidden': 'true' })
    )
  );
};

DecorativeLink.propTypes = process.env.NODE_ENV !== "production" ? {
  href: PropTypes.string,
  info: PropTypes.string,
  text: PropTypes.string,
  showFileIcon: PropTypes.bool,
  className: PropTypes.string,
  details: PropTypes.string,
  icon: PropTypes.elementType
} : {};

DecorativeLink.defaultProps = {
  href: '#',
  text: 'Lorem ipsum dolor sit amet',
  showFileIcon: false
};

export default DecorativeLink;