import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback } from 'react';
import { FormattedMessage } from 'react-intl';
import DownloadIcon from '@atlaskit/icon/core/download';
import { ActionName } from '../../../../../constants';
import { messages } from '../../../../../messages';
import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
import useInvokeClientAction from '../../../../../state/hooks/use-invoke-client-action';
import Action from '../action';
const DownloadAction = ({
  onClick: onClickCallback,
  ...props
}) => {
  var _context$actions;
  const context = useFlexibleUiContext();
  const invoke = useInvokeClientAction({});
  const data = context === null || context === void 0 ? void 0 : (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions[ActionName.DownloadAction];
  const onClick = useCallback(() => {
    if (data !== null && data !== void 0 && data.invokeAction) {
      invoke(data.invokeAction);
      onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
    }
  }, [data, invoke, onClickCallback]);
  const isStackItem = props.as === 'stack-item';
  const label = isStackItem ? messages.download_file : messages.download;
  const tooltipMessage = isStackItem ? messages.download_description : messages.download;
  return data ? /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, label),
    icon: /*#__PURE__*/React.createElement(DownloadIcon, {
      spacing: "spacious",
      color: "currentColor",
      label: "Download"
    }),
    onClick: onClick,
    testId: "smart-action-download-action",
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, tooltipMessage)
  }, data, props)) : null;
};
export default DownloadAction;