import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import CopyIcon from '@atlaskit/icon/core/copy';
import { useAnalyticsEvents } from '../../../../../common/analytics/generated/use-analytics-events';
import { messages } from '../../../../../messages';
import Action from '../action';
export function CopySummaryAction({
  url,
  onClick: onClickCallback,
  testId,
  content,
  ...props
}) {
  const {
    fireEvent
  } = useAnalyticsEvents();
  const [tooltipMessage, setTooltipMessage] = useState(messages.copy_summary_action_description);
  const handleCopySummaryClick = useCallback(async () => {
    fireEvent('ui.button.clicked.copySummary', {});
    await navigator.clipboard.writeText(content !== null && content !== void 0 ? content : '');
    setTooltipMessage(messages.copied_summary_action_description);
    onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
  }, [fireEvent, onClickCallback, content]);
  return /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, messages.copy_summary_action),
    icon: /*#__PURE__*/React.createElement(CopyIcon, {
      color: "currentColor",
      spacing: "spacious",
      label: "Copy Summary"
    }),
    onClick: handleCopySummaryClick,
    testId: `${testId}-copy-summary-action`,
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, tooltipMessage),
    tooltipOnHide: () => setTooltipMessage(messages.copy_summary_action_description)
  }, props));
}
export function CopySummaryActionNew({
  url,
  onClick: onClickCallback,
  summary = '',
  testId,
  ...props
}) {
  const {
    fireEvent
  } = useAnalyticsEvents();
  const [tooltipMessage, setTooltipMessage] = useState(messages.copy_summary_action_description);
  const handleCopySummaryClick = useCallback(async () => {
    fireEvent('ui.button.clicked.copySummary', {});
    await navigator.clipboard.writeText(summary);
    setTooltipMessage(messages.copied_summary_action_description);
    onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
  }, [fireEvent, onClickCallback, summary]);
  return /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, messages.copy_summary_action),
    icon: /*#__PURE__*/React.createElement(CopyIcon, {
      color: "currentColor",
      spacing: "spacious",
      label: "Copy Summary",
      size: props.iconSize
    }),
    onClick: handleCopySummaryClick,
    testId: `${testId}-copy-summary-action`,
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, tooltipMessage),
    tooltipOnHide: () => setTooltipMessage(messages.copy_summary_action_description)
  }, props));
}