"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faCircleNotch = require("@fortawesome/free-solid-svg-icons/faCircleNotch");
var _faPen = require("@fortawesome/free-solid-svg-icons/faPen");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _textWithHyperlinks = require("../text-with-hyperlinks");
var _button = require("../button");
var _useTranslation = require("../hooks/use-translation");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const TextMode = ({
  className = 'text',
  startEditing,
  value,
  isMultiline,
  isDisabled,
  isLoading,
  buttonLabel,
  buttonTooltip,
  placeholder,
  areHyperLinksClickable,
  buttonTestId = 'edit-text-button',
  buttonAriaLabel
}) => {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const editButton = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_button.Button, {
    accentType: buttonLabel ? _button.ACCENT_TYPES.COMMAND : _button.ACCENT_TYPES.ROUND_ICON,
    className: 'edit-button',
    isDisabled: isDisabled || isLoading,
    "aria-label": buttonAriaLabel ?? t('Edit'),
    onClick: startEditing,
    tooltipText: buttonTooltip,
    testId: buttonTestId,
    tourId: "edit-text",
    size: buttonLabel ? _button.BUTTON_SIZES.SM : undefined,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
      icon: isLoading ? _faCircleNotch.faCircleNotch : _faPen.faPen,
      spin: isLoading,
      "test-id": "is-loading-icon"
    }), buttonLabel ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: buttonLabel
    }) : null]
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: (0, _classnames.default)('edit-text-label', className, {
        'edit-text-label-truncated-wrapper': !isMultiline
      }),
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        "test-id": "edit-text-label",
        className: (0, _classnames.default)({
          'edit-text-label-truncated': !isMultiline
        }),
        children: (areHyperLinksClickable && value ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_textWithHyperlinks.TextWithHyperlinks, {
          value: value.toString()
        }) : value) || placeholder
      }), editButton]
    })
  });
};
var _default = exports.default = TextMode;