import { useState, Children, isValidElement } from 'react';
import '../../common/theme.mjs';
import '../../common/direction.mjs';
import '@transferwise/neptune-tokens';
import '../../common/propsValues/control.mjs';
import '../../common/propsValues/size.mjs';
import { Typography } from '../../common/propsValues/typography.mjs';
import '../../common/propsValues/width.mjs';
import '../../common/propsValues/type.mjs';
import '../../common/propsValues/dateMode.mjs';
import '../../common/propsValues/monthFormat.mjs';
import '../../common/propsValues/position.mjs';
import '../../common/propsValues/layouts.mjs';
import '../../common/propsValues/status.mjs';
import { Sentiment } from '../../common/propsValues/sentiment.mjs';
import '../../common/propsValues/profileType.mjs';
import '../../common/propsValues/variant.mjs';
import '../../common/propsValues/scroll.mjs';
import '../../common/propsValues/markdownNodeType.mjs';
import '../../common/fileType.mjs';
import '@transferwise/formatting';
import { GiftBox } from '@transferwise/icons';
import { clsx } from 'clsx';
import 'react-intl';
import '../../common/closeButton/CloseButton.messages.mjs';
import { jsx, jsxs } from 'react/jsx-runtime';
import { LiveRegion } from '../../common/liveRegion/LiveRegion.mjs';
import StatusIcon from '../../statusIcon/StatusIcon.mjs';
import Body from '../../body/Body.mjs';
import Link from '../../link/Link.mjs';
import { PrimitivePrompt } from '../PrimitivePrompt/PrimitivePrompt.mjs';

const InfoPrompt = ({
  sentiment = 'neutral',
  onDismiss,
  media,
  action,
  title,
  description,
  className,
  'aria-live': ariaLive = 'polite',
  'data-testid': dataTestId,
  ...restProps
}) => {
  const [shouldFire, setShouldFire] = useState();
  const announceOnChange = [title, Children.toArray(description).map(child => /*#__PURE__*/isValidElement(child) ? child.props.children : child).join(''), action?.label].filter(Boolean).join('|');
  const statusIconSentiment = sentiment === 'success' ? Sentiment.POSITIVE : sentiment;
  const handleTouchStart = () => {
    setShouldFire(true);
  };
  const handleTouchEnd = () => {
    if (shouldFire && action?.href) {
      if (action.target === '_blank') {
        window.top?.open(action.href, '_blank', 'noopener, noreferrer');
      } else {
        window.top?.location.assign(action.href);
      }
    }
    setShouldFire(false);
  };
  const handleTouchMove = () => {
    setShouldFire(false);
  };
  const renderMedia = () => {
    if (media) {
      return /*#__PURE__*/jsx("span", {
        className: "wds-info-prompt__media",
        children: media.asset
      });
    }
    if (sentiment === 'proposition') {
      return /*#__PURE__*/jsx("span", {
        className: "wds-info-prompt__media",
        children: /*#__PURE__*/jsx(GiftBox, {})
      });
    }
    return /*#__PURE__*/jsx(StatusIcon, {
      size: 24,
      sentiment: statusIconSentiment
    });
  };
  // Render content directly in LiveRegion
  return /*#__PURE__*/jsx(LiveRegion, {
    "aria-live": ariaLive,
    announceOnChange: announceOnChange,
    children: /*#__PURE__*/jsx(PrimitivePrompt, {
      sentiment: sentiment,
      media: renderMedia(),
      "data-testid": dataTestId,
      className: clsx('wds-info-prompt', className),
      ...restProps,
      onTouchStart: handleTouchStart,
      onTouchEnd: handleTouchEnd,
      onTouchMove: handleTouchMove,
      onDismiss: onDismiss,
      children: /*#__PURE__*/jsxs("div", {
        className: "wds-info-prompt__content",
        children: [title && /*#__PURE__*/jsx(Body, {
          className: "wds-info-prompt__title",
          type: Typography.BODY_LARGE_BOLD,
          as: "span",
          children: title
        }), /*#__PURE__*/jsx(Body, {
          as: "span",
          className: "wds-info-prompt__description",
          children: description
        }), action && /*#__PURE__*/jsx(Link, {
          href: action.href,
          target: action.target,
          type: Typography.LINK_DEFAULT,
          className: "wds-info-prompt__action",
          onClick: action.onClick,
          children: action.label
        })]
      })
    })
  });
};

export { InfoPrompt };
//# sourceMappingURL=InfoPrompt.mjs.map
