import _extends from "@babel/runtime/helpers/extends";
import "core-js/modules/es.array.concat.js";
import "core-js/modules/es.string.link.js";
import * as React from 'react';
import { TextLink } from '@megafon/ui-core';
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import "./DownloadLink.css";
var DownloadIcon = function DownloadIcon(props) {
  return /*#__PURE__*/React.createElement("svg", _extends({
    viewBox: "0 0 40 40"
  }, props), /*#__PURE__*/React.createElement("path", {
    d: "M21 6v14l2.68-4 1.65 1-4.44 6.74h-1.77L14.68 17l1.65-1L19 20V6zM8 20H6a14 14 0 0028 0h-2a12 12 0 01-24 0z"
  }));
};
var cn = cnCreate('mfui-download-link');
var DownloadLink = function DownloadLink(_ref) {
  var href = _ref.href,
    text = _ref.text,
    extension = _ref.extension,
    fileSize = _ref.fileSize,
    onClick = _ref.onClick,
    className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    rootRef = _ref.rootRef,
    dataAttrs = _ref.dataAttrs,
    disableDownload = _ref.disableDownload,
    target = _ref.target,
    rel = _ref.rel;
  var setRelAttribute = function setRelAttribute() {
    if (rel) {
      return rel;
    }
    if (target && target !== '_self') {
      return 'noreferrer noopener';
    }
    return undefined;
  };
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn([className, classes.root]),
    ref: rootRef
  }), /*#__PURE__*/React.createElement("div", {
    className: cn('icon')
  }, /*#__PURE__*/React.createElement(DownloadIcon, {
    className: cn('icon-svg')
  })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(TextLink, _extends({}, !disableDownload && {
    download: true
  }, {
    href: href,
    onClick: onClick,
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.link
    },
    className: cn('link', [classes.link]),
    target: target,
    rel: setRelAttribute()
  }), text), /*#__PURE__*/React.createElement("p", {
    className: cn('info')
  }, "".concat(extension).concat(extension && fileSize ? ', ' : '').concat(fileSize))));
};
export default DownloadLink;