import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import LinkIcon from '@atlaskit/icon/core/link';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
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 CopyLinkAction = ({
  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.CopyLinkAction];
  const [tooltipMessage, setTooltipMessage] = useState(messages.copy_url_to_clipboard);
  const onClick = useCallback(() => {
    if (data !== null && data !== void 0 && data.invokeAction) {
      invoke({
        ...data.invokeAction,
        actionFn: async () => {
          var _data$invokeAction;
          await ((_data$invokeAction = data.invokeAction) === null || _data$invokeAction === void 0 ? void 0 : _data$invokeAction.actionFn());
          setTooltipMessage(messages.copied_url_to_clipboard);
        }
      });
      onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
    }
  }, [data, invoke, onClickCallback]);
  return data ? /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, messages.copy_url_to_clipboard),
    icon: /*#__PURE__*/React.createElement(LinkIcon, _extends({
      color: "currentColor",
      label: fg('navx-3698-flexible-card-a11y-fix') ? '' : 'copy url',
      spacing: "spacious"
    }, fg('platform_sl_3p_auth_rovo_action_kill_switch') || fg('platform_sl_3p_auth_rovo_block_card_kill_switch') || expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true) ? {
      size: props.iconSize
    } : {})),
    onClick: onClick,
    testId: "smart-action-copy-link-action",
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, tooltipMessage),
    tooltipOnHide: () => setTooltipMessage(messages.copy_url_to_clipboard)
  }, data, props)) : null;
};
export default CopyLinkAction;