import React from 'react';
import classNames from 'classnames';
import { useTranslation } from '../hooks/use-translation';
import { Input } from '../input';
import { COPY_TO_CLIPBOARD_MODES } from './constants';
import { CopyToClipboardButton } from './copy-to-clipboard-button';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/** Allows users to quickly copy content to clipboard.
 * @uxr-only-supported
 * @midnight-gray-supported
 */
export function CopyToClipboard({
  value,
  id,
  label,
  className,
  copyLabel,
  buttonAccentType,
  onClick,
  isDisabled = false,
  mode = COPY_TO_CLIPBOARD_MODES.INPUT,
  buttonAriaLabel,
  copyTooltipText,
  copiedTooltipText,
  testId = 'copy-to-clipboard'
}) {
  const {
    t
  } = useTranslation();
  const copyTooltipTextValue = copyTooltipText ?? t('Copy to clipboard');
  return /*#__PURE__*/_jsxs("div", {
    className: classNames('copy-to-clipboard', className),
    "test-id": testId,
    children: [mode === COPY_TO_CLIPBOARD_MODES.TEXT && /*#__PURE__*/_jsx("span", {
      id: id,
      className: classNames('copy-to-clipboard-text', {
        disabled: isDisabled
      }),
      "test-id": `${testId}-text`,
      children: value
    }), mode === COPY_TO_CLIPBOARD_MODES.INPUT && /*#__PURE__*/_jsx(Input, {
      readOnly: true,
      value: value,
      id: id,
      label: label,
      fieldClass: "copy-to-clipboard-input",
      isDisabled: isDisabled,
      labelIconTooltipText: copyTooltipTextValue
    }), /*#__PURE__*/_jsx(CopyToClipboardButton, {
      copyLabel: copyLabel,
      ariaLabel: buttonAriaLabel ?? t('Copy text'),
      ariaLabelledBy: id,
      value: value,
      copyTooltipText: copyTooltipTextValue,
      copiedTooltipText: copiedTooltipText ?? t('Copied to clipboard'),
      testId: `${testId}-btn`,
      className: `with-${mode}`,
      isDisabled: isDisabled,
      accentType: buttonAccentType,
      onClick: onClick
    })]
  });
}