"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ArchiveDownloadButton = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _download = _interopRequireDefault(require("@atlaskit/icon/core/migration/download"));
var _styleWrappers = require("./styleWrappers");
var _abuseModal = require("@atlaskit/media-ui/abuseModal");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var ArchiveDownloadButton = exports.ArchiveDownloadButton = function ArchiveDownloadButton(_ref) {
  var downloadFn = _ref.downloadFn,
    shouldRenderAbuseModal = _ref.shouldRenderAbuseModal,
    isDisabled = _ref.isDisabled,
    tooltip = _ref.tooltip;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    isAbuseModalOpen = _useState2[0],
    setIsAbuseModalOpen = _useState2[1];
  var downloadOrWarn = function downloadOrWarn() {
    if (isDisabled) {
      return;
    }
    if (shouldRenderAbuseModal) {
      setIsAbuseModalOpen(true);
    } else {
      downloadFn();
    }
  };
  var icon = /*#__PURE__*/_react.default.createElement(_download.default, {
    color: isDisabled ? "var(--ds-icon-disabled, #080F214A)" : 'currentColor',
    spacing: "spacious",
    label: "Download"
  });
  var downloadButton = isDisabled ? /*#__PURE__*/_react.default.createElement(_styleWrappers.DisabledArchiveDownloadButtonWrapper, null, icon) : /*#__PURE__*/_react.default.createElement(_styleWrappers.ArchiveDownloadButtonWrapper, {
    onClick: downloadOrWarn
  }, icon);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, shouldRenderAbuseModal && /*#__PURE__*/_react.default.createElement(_abuseModal.AbuseModal, {
    isOpen: isAbuseModalOpen,
    onConfirm: downloadFn,
    onClose: function onClose() {
      return setIsAbuseModalOpen(false);
    }
  }), tooltip ? /*#__PURE__*/_react.default.createElement(_tooltip.default, {
    content: tooltip,
    position: "bottom",
    tag: "span"
  }, downloadButton) : downloadButton);
};