"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CopyToClipboard = CopyToClipboard;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useTranslation = require("../hooks/use-translation");
var _input = require("../input");
var _constants = require("./constants");
var _copyToClipboardButton = require("./copy-to-clipboard-button");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** Allows users to quickly copy content to clipboard.
 * @uxr-only-supported
 * @midnight-gray-supported
 */
function CopyToClipboard({
  value,
  id,
  label,
  className,
  copyLabel,
  buttonAccentType,
  onClick,
  isDisabled = false,
  mode = _constants.COPY_TO_CLIPBOARD_MODES.INPUT,
  buttonAriaLabel,
  copyTooltipText,
  copiedTooltipText,
  testId = 'copy-to-clipboard'
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const copyTooltipTextValue = copyTooltipText ?? t('Copy to clipboard');
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)('copy-to-clipboard', className),
    "test-id": testId,
    children: [mode === _constants.COPY_TO_CLIPBOARD_MODES.TEXT && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      id: id,
      className: (0, _classnames.default)('copy-to-clipboard-text', {
        disabled: isDisabled
      }),
      "test-id": `${testId}-text`,
      children: value
    }), mode === _constants.COPY_TO_CLIPBOARD_MODES.INPUT && /*#__PURE__*/(0, _jsxRuntime.jsx)(_input.Input, {
      readOnly: true,
      value: value,
      id: id,
      label: label,
      fieldClass: "copy-to-clipboard-input",
      isDisabled: isDisabled,
      labelIconTooltipText: copyTooltipTextValue
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_copyToClipboardButton.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
    })]
  });
}