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 const ArchiveDownloadButton = ({
  downloadFn,
  shouldRenderAbuseModal,
  isDisabled,
  tooltip
}) => {
  const [isAbuseModalOpen, setIsAbuseModalOpen] = useState(false);
  const downloadOrWarn = () => {
    if (isDisabled) {
      return;
    }
    if (shouldRenderAbuseModal) {
      setIsAbuseModalOpen(true);
    } else {
      downloadFn();
    }
  };
  const icon = /*#__PURE__*/React.createElement(DownloadIcon, {
    color: isDisabled ? "var(--ds-icon-disabled, #080F214A)" : 'currentColor',
    spacing: "spacious",
    label: "Download"
  });
  const 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: () => setIsAbuseModalOpen(false)
  }), tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
    content: tooltip,
    position: "bottom",
    tag: "span"
  }, downloadButton) : downloadButton);
};