"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MESSAGE_TYPES = exports.MESSAGE_SIZES = exports.MESSAGE_ICON_PLACEMENT = exports.MESSAGE_ICONS = void 0;
exports.Message = Message;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faBan = require("@fortawesome/free-solid-svg-icons/faBan");
var _faCircleInfo = require("@fortawesome/free-solid-svg-icons/faCircleInfo");
var _faCircleExclamation = require("@fortawesome/free-solid-svg-icons/faCircleExclamation");
var _faCircleXmark = require("@fortawesome/free-solid-svg-icons/faCircleXmark");
var _faCircleCheck = require("@fortawesome/free-solid-svg-icons/faCircleCheck");
var _faCircleNotch = require("@fortawesome/free-solid-svg-icons/faCircleNotch");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _thinkingIcon = require("./thinking-icon");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const MESSAGE_TYPES = exports.MESSAGE_TYPES = {
  DISABLED: 'disabled',
  INFO: 'info',
  WARNING: 'warning',
  ERROR: 'error',
  SUCCESS: 'success',
  SUCCESS_INFO: 'success-info',
  IN_PROGRESS: 'in-progress',
  EXPIRED: 'expired',
  THINKING: 'thinking'
};
const MESSAGE_ICON_PLACEMENT = exports.MESSAGE_ICON_PLACEMENT = {
  LEFT: 'left',
  RIGHT: 'right'
};
const MESSAGE_SIZES = exports.MESSAGE_SIZES = {
  SM: 'sm',
  MD: 'md'
};
const MESSAGE_ICONS = exports.MESSAGE_ICONS = {
  [MESSAGE_TYPES.DISABLED]: _faBan.faBan,
  [MESSAGE_TYPES.INFO]: _faCircleInfo.faCircleInfo,
  [MESSAGE_TYPES.SUCCESS_INFO]: _faCircleCheck.faCircleCheck,
  [MESSAGE_TYPES.WARNING]: _faCircleExclamation.faCircleExclamation,
  [MESSAGE_TYPES.ERROR]: _faCircleXmark.faCircleXmark,
  [MESSAGE_TYPES.SUCCESS]: _faCircleCheck.faCircleCheck,
  [MESSAGE_TYPES.IN_PROGRESS]: _faCircleNotch.faCircleNotch,
  [MESSAGE_TYPES.EXPIRED]: _faCircleExclamation.faCircleExclamation
};
function getMessageConfig(icons, type) {
  const icon = type ? icons[type] : icons[MESSAGE_TYPES.INFO];
  switch (type) {
    case MESSAGE_TYPES.DISABLED:
      return {
        icon,
        className: 'disabled'
      };
    case MESSAGE_TYPES.INFO:
      return {
        icon,
        className: 'info'
      };
    case MESSAGE_TYPES.SUCCESS_INFO:
      return {
        icon,
        className: 'info'
      };
    case MESSAGE_TYPES.WARNING:
      return {
        icon,
        className: 'warning'
      };
    case MESSAGE_TYPES.ERROR:
      return {
        icon,
        className: 'error',
        role: 'alert'
      };
    case MESSAGE_TYPES.SUCCESS:
      return {
        icon,
        className: 'success'
      };
    case MESSAGE_TYPES.IN_PROGRESS:
      return {
        icon,
        className: 'in-progress'
      };
    case MESSAGE_TYPES.EXPIRED:
      return {
        icon,
        className: 'expired'
      };
    case MESSAGE_TYPES.THINKING:
      return {
        className: 'thinking'
      };
    default:
      return {
        icon,
        className: 'info'
      };
  }
}
/** Simple component to show a message with an appropriate icon
 * [CAPITALIZATION] Sentence case, full sentence, end in period
 * @midnight-gray-supported
 * @alpine-light-supported
 */
function Message({
  children,
  className,
  testId,
  type = MESSAGE_TYPES.INFO,
  isCentered = false,
  isStatus = false,
  size = 'md',
  id,
  iconPlacement = MESSAGE_ICON_PLACEMENT.LEFT,
  icons = MESSAGE_ICONS
}) {
  const messageConfig = getMessageConfig(icons, type);
  const renderIcon = () => {
    if (type === MESSAGE_TYPES.THINKING) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_thinkingIcon.ThinkingIcon, {
        size: size
      });
    }
    if (messageConfig.icon) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
        icon: messageConfig.icon,
        spin: type === MESSAGE_TYPES.IN_PROGRESS
      });
    }
    return null;
  };
  const icon = renderIcon();
  const resolvedChildren = type === MESSAGE_TYPES.THINKING ? children ?? 'Thinking' : children;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
    className: (0, _classnames.default)('message-component', isStatus && 'status', messageConfig.className, {
      'center-status': isCentered,
      sm: size === MESSAGE_SIZES.SM
    }, className, `with-${iconPlacement}-icon`),
    "test-id": testId,
    id: id,
    "aria-live": "polite",
    role: messageConfig?.role,
    children: [iconPlacement === MESSAGE_ICON_PLACEMENT.LEFT && icon, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: resolvedChildren
    }), iconPlacement === MESSAGE_ICON_PLACEMENT.RIGHT && icon]
  });
}