"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.ALERT_TYPES = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faCircleCheck = require("@fortawesome/free-solid-svg-icons/faCircleCheck");
var _faCircleInfo = require("@fortawesome/free-solid-svg-icons/faCircleInfo");
var _faCircleXmark = require("@fortawesome/free-solid-svg-icons/faCircleXmark");
var _faCircleExclamation = require("@fortawesome/free-solid-svg-icons/faCircleExclamation");
var _faBolt = require("@fortawesome/free-solid-svg-icons/faBolt");
var _faEye = require("@fortawesome/free-solid-svg-icons/faEye");
var _faEyeSlash = require("@fortawesome/free-solid-svg-icons/faEyeSlash");
var _faXmark = require("@fortawesome/free-solid-svg-icons/faXmark");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _button = require("../button");
var _useTranslation = require("../hooks/use-translation");
var _truncateWithTooltip = require("../truncate-with-tooltip");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const ALERT_TYPES = exports.ALERT_TYPES = {
  SUCCESS: 'success',
  INFO: 'info',
  WARNING: 'warning',
  FAILURE: 'failure'
};
/** Alert is used to notify users about significant events in the application
 * [CAPITALIZATION] Use sentence case for title, text, buttons
 * @midnight-gray-supported
 * @alpine-light-supported
 */

function Alert({
  className,
  type = ALERT_TYPES.INFO,
  header,
  children = '',
  testId,
  actionButtonText,
  dismissButtonText,
  docsLink,
  onTakeAction,
  onDismiss,
  footer,
  collapsedTextContent = false,
  collapsedContentShowMessageButtonText,
  collapsedContentHideMessageButtonText,
  takeActionIcon = _faBolt.faBolt,
  wordBreakHeader = false
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const alertIcon = {
    [ALERT_TYPES.SUCCESS]: _faCircleCheck.faCircleCheck,
    [ALERT_TYPES.INFO]: _faCircleInfo.faCircleInfo,
    [ALERT_TYPES.WARNING]: _faCircleExclamation.faCircleExclamation,
    [ALERT_TYPES.FAILURE]: _faCircleXmark.faCircleXmark
  };
  const [showMessage, setShowMessage] = (0, _react.useState)(!collapsedTextContent);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    "test-id": testId,
    className: (0, _classnames.default)('alert', type, className, collapsedTextContent && 'collapsed'),
    role: "alert",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
      icon: alertIcon[type],
      className: "alert-icon"
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("section", {
      className: "alert-section",
      "test-id": "alert-section",
      children: !showMessage ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "show-more-header",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "alert-header",
          children: wordBreakHeader ? /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
            className: "break-word",
            children: header
          }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncateWithTooltip.TruncateWithTooltip, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
              children: header
            })
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
          testId: "show-message",
          accentType: _button.ACCENT_TYPES.COMMAND,
          onClick: () => setShowMessage(true),
          leftIcon: _faEye.faEye,
          children: collapsedContentShowMessageButtonText ?? t('Show message')
        })]
      }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "alert-header",
          children: wordBreakHeader ? /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
            className: "break-word",
            children: header
          }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncateWithTooltip.TruncateWithTooltip, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
              children: header
            })
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "alert-body",
          children: children
        }), footer || /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          className: "alert-footer",
          children: [onTakeAction && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
            testId: "take-action",
            accentType: _button.ACCENT_TYPES.COMMAND,
            onClick: onTakeAction,
            leftIcon: takeActionIcon,
            children: actionButtonText
          }), docsLink && /*#__PURE__*/(0, _react.cloneElement)(docsLink, {
            className: 'alert-docs-link'
          }), onDismiss && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
            testId: "dismiss",
            accentType: _button.ACCENT_TYPES.COMMAND,
            onClick: onDismiss,
            leftIcon: _faXmark.faXmark,
            children: dismissButtonText ?? t('Dismiss')
          }), collapsedTextContent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
            testId: "hide-message",
            accentType: _button.ACCENT_TYPES.COMMAND,
            onClick: () => setShowMessage(false),
            leftIcon: _faEyeSlash.faEyeSlash,
            children: collapsedContentHideMessageButtonText || t('Hide message')
          })]
        })]
      })
    })]
  });
}
var _default = exports.default = Alert;