'use strict';

exports.__esModule = true;

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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Icon = require('../../../base/Icon');

var _Icon2 = _interopRequireDefault(_Icon);

require('./style.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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; }

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 = (0, _classnames2.default)((_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 = _react2.default.createElement(_Icon2.default, { name: 'pdf', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'docx':
        decIcon = _react2.default.createElement(_Icon2.default, { name: 'docx', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'xlxs':
        decIcon = _react2.default.createElement(_Icon2.default, { name: 'xlxs', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      case 'generic':
        decIcon = _react2.default.createElement(_Icon2.default, { name: 'generic', title: title, svgWidth: 35, svgHeight: 36 });
        break;
      default:
        decIcon = null;
    }
  }
  return _react2.default.createElement(
    'span',
    { className: classes },
    _react2.default.createElement(
      'a',
      _extends({}, rest, {
        href: href,
        title: info || null
      }),
      decIcon && _react2.default.createElement(
        'span',
        { className: 'ma__download-link--icon' },
        decIcon,
        '\xA0'
      ),
      text,
      details && _react2.default.createElement(
        'span',
        { className: 'ma__decorative-link__details' },
        '\xA0',
        details
      ),
      '\xA0',
      icon || _react2.default.createElement(_Icon2.default, { name: 'arrow', 'aria-hidden': 'true' })
    )
  );
};

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

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

exports.default = DecorativeLink;
module.exports = exports['default'];