import React from 'react';
import classNames from 'classnames';
import { faBan } from '@fortawesome/free-solid-svg-icons/faBan';
import { faCircleInfo } from '@fortawesome/free-solid-svg-icons/faCircleInfo';
import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons/faCircleExclamation';
import { faCircleXmark } from '@fortawesome/free-solid-svg-icons/faCircleXmark';
import { faCircleCheck } from '@fortawesome/free-solid-svg-icons/faCircleCheck';
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons/faCircleNotch';
import { FontAwesomeIcon } from '../font-awesome-icon';
import { ThinkingIcon } from './thinking-icon';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const MESSAGE_TYPES = {
  DISABLED: 'disabled',
  INFO: 'info',
  WARNING: 'warning',
  ERROR: 'error',
  SUCCESS: 'success',
  SUCCESS_INFO: 'success-info',
  IN_PROGRESS: 'in-progress',
  EXPIRED: 'expired',
  THINKING: 'thinking'
};
export const MESSAGE_ICON_PLACEMENT = {
  LEFT: 'left',
  RIGHT: 'right'
};
export const MESSAGE_SIZES = {
  SM: 'sm',
  MD: 'md'
};
export const MESSAGE_ICONS = {
  [MESSAGE_TYPES.DISABLED]: faBan,
  [MESSAGE_TYPES.INFO]: faCircleInfo,
  [MESSAGE_TYPES.SUCCESS_INFO]: faCircleCheck,
  [MESSAGE_TYPES.WARNING]: faCircleExclamation,
  [MESSAGE_TYPES.ERROR]: faCircleXmark,
  [MESSAGE_TYPES.SUCCESS]: faCircleCheck,
  [MESSAGE_TYPES.IN_PROGRESS]: faCircleNotch,
  [MESSAGE_TYPES.EXPIRED]: 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
 */
export 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__*/_jsx(ThinkingIcon, {
        size: size
      });
    }
    if (messageConfig.icon) {
      return /*#__PURE__*/_jsx(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__*/_jsxs("p", {
    className: classNames('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__*/_jsx("span", {
      children: resolvedChildren
    }), iconPlacement === MESSAGE_ICON_PLACEMENT.RIGHT && icon]
  });
}