import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import DownloadIcon from '@atlaskit/icon/core/migration/download';
import { ArchiveDownloadButtonWrapper, DisabledArchiveDownloadButtonWrapper } from './styleWrappers';
import { AbuseModal } from '@atlaskit/media-ui/abuseModal';
import Tooltip from '@atlaskit/tooltip';
export var ArchiveDownloadButton = function ArchiveDownloadButton(_ref) {
  var downloadFn = _ref.downloadFn,
    shouldRenderAbuseModal = _ref.shouldRenderAbuseModal,
    isDisabled = _ref.isDisabled,
    tooltip = _ref.tooltip;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_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.createElement(DownloadIcon, {
    color: isDisabled ? "var(--ds-icon-disabled, #080F214A)" : 'currentColor',
    spacing: "spacious",
    label: "Download"
  });
  var downloadButton = isDisabled ? /*#__PURE__*/React.createElement(DisabledArchiveDownloadButtonWrapper, null, icon) : /*#__PURE__*/React.createElement(ArchiveDownloadButtonWrapper, {
    onClick: downloadOrWarn
  }, icon);
  return /*#__PURE__*/React.createElement(React.Fragment, null, shouldRenderAbuseModal && /*#__PURE__*/React.createElement(AbuseModal, {
    isOpen: isAbuseModalOpen,
    onConfirm: downloadFn,
    onClose: function onClose() {
      return setIsAbuseModalOpen(false);
    }
  }), tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
    content: tooltip,
    position: "bottom",
    tag: "span"
  }, downloadButton) : downloadButton);
};