"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _useCopyClipboard = require("../../providers/useCopyClipboard");
var _Tooltip = _interopRequireDefault(require("../../Tooltip/Tooltip"));
var _InlineVariantSt = require("./InlineVariant.st.css.js");
var _CodeSnippet = require("../CodeSnippet.constants");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/CodeSnippet/components/InlineVariant.tsx";
var InlineVariant = _ref => {
  var {
    code,
    size,
    copyText,
    disableCopy = false,
    copyTooltipText = _CodeSnippet.DEFAULT_TOOLTIP_IDLE,
    copiedTooltipText = _CodeSnippet.DEFAULT_TOOLTIP_COPIED,
    tooltipProps,
    onCopy: _onCopy,
    ariaLabel,
    dataHook,
    className
  } = _ref;
  var valueToCopy = copyText !== null && copyText !== void 0 ? copyText : code;
  var {
    isCopied,
    copyToClipboard
  } = (0, _useCopyClipboard.useCopyClipboard)({
    value: valueToCopy,
    onCopy: () => _onCopy == null ? void 0 : _onCopy(valueToCopy),
    resetTimeout: _CodeSnippet.COPY_RESET_TIMEOUT_MS
  });
  if (disableCopy) {
    return /*#__PURE__*/_react.default.createElement("span", {
      "data-hook": dataHook,
      "aria-label": ariaLabel,
      className: (0, _InlineVariantSt.st)(_InlineVariantSt.classes.root, {
        size,
        static: true
      }, className),
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 51,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement("code", {
      "data-hook": _CodeSnippet.DATA_HOOKS.code,
      className: _InlineVariantSt.classes.code,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 56,
        columnNumber: 9
      }
    }, code));
  }
  var tooltipLabel = isCopied ? copiedTooltipText : copyTooltipText;
  var handleKeyDown = event => {
    if (event.key === 'Enter' || event.key === ' ') {
      event.preventDefault();
      copyToClipboard();
    }
  };
  return /*#__PURE__*/_react.default.createElement(_Tooltip.default, (0, _extends2.default)({
    appendTo: "window",
    inline: true
  }, tooltipProps, {
    content: tooltipLabel,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 73,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement("span", {
    role: "button",
    tabIndex: 0,
    "data-hook": dataHook,
    "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : "".concat(code, ", ").concat(tooltipLabel),
    className: (0, _InlineVariantSt.st)(_InlineVariantSt.classes.root, {
      size
    }, className),
    onClick: copyToClipboard,
    onKeyDown: handleKeyDown,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 74,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement("code", {
    "data-hook": _CodeSnippet.DATA_HOOKS.code,
    className: _InlineVariantSt.classes.code,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 83,
      columnNumber: 9
    }
  }, code)));
};
InlineVariant.displayName = 'CodeSnippet.InlineVariant';
var _default = exports.default = InlineVariant;
//# sourceMappingURL=InlineVariant.js.map