"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = PasswordToggleButton;
var _react = _interopRequireDefault(require("react"));
var _faEyeSlash = require("@fortawesome/free-solid-svg-icons/faEyeSlash");
var _faEye = require("@fortawesome/free-solid-svg-icons/faEye");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _tooltip = require("../tooltip");
var _constants = require("./constants");
var _utilities = require("./utilities");
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 }; }
function PasswordToggleButton({
  onClick,
  fieldType,
  passwordToggleButtonTexts,
  isDisabled = false
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const isPasswordType = (0, _utilities.isPassword)(fieldType);
  const tooltipText = isPasswordType ? passwordToggleButtonTexts.show : passwordToggleButtonTexts.hide;
  function handleClick() {
    onClick(isPasswordType ? _constants.INPUT_TYPES.TEXT : _constants.INPUT_TYPES.PASSWORD);
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
    content: tooltipText,
    placement: _tooltip.TOOLTIP_PLACEMENT_TYPES.TOP,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
      className: "button command round-icon-button xs toggle-password-button",
      "test-id": "toggle-password-button",
      onClick: handleClick,
      disabled: isDisabled,
      "aria-label": passwordToggleButtonTexts.toggle || t('Toggle'),
      type: _button.BUTTON_TYPES.BUTTON,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
        icon: isPasswordType ? _faEyeSlash.faEyeSlash : _faEye.faEye,
        "test-id": "show-password-toggle"
      })
    })
  });
}