'use strict';

var React = require('react');
require('../../common/theme.js');
require('../../common/direction.js');
require('@transferwise/neptune-tokens');
require('../../common/propsValues/control.js');
require('../../common/propsValues/size.js');
var typography = require('../../common/propsValues/typography.js');
require('../../common/propsValues/width.js');
require('../../common/propsValues/type.js');
require('../../common/propsValues/dateMode.js');
require('../../common/propsValues/monthFormat.js');
require('../../common/propsValues/position.js');
require('../../common/propsValues/layouts.js');
require('../../common/propsValues/status.js');
var sentiment = require('../../common/propsValues/sentiment.js');
require('../../common/propsValues/profileType.js');
require('../../common/propsValues/variant.js');
require('../../common/propsValues/scroll.js');
require('../../common/propsValues/markdownNodeType.js');
require('../../common/fileType.js');
require('@transferwise/formatting');
var icons = require('@transferwise/icons');
var clsx = require('clsx');
require('react-intl');
require('../../common/closeButton/CloseButton.messages.js');
var jsxRuntime = require('react/jsx-runtime');
var LiveRegion = require('../../common/liveRegion/LiveRegion.js');
var StatusIcon = require('../../statusIcon/StatusIcon.js');
var Body = require('../../body/Body.js');
var Link = require('../../link/Link.js');
var PrimitivePrompt = require('../PrimitivePrompt/PrimitivePrompt.js');

const InfoPrompt = ({
  sentiment: sentiment$1 = 'neutral',
  onDismiss,
  media,
  action,
  title,
  description,
  className,
  'aria-live': ariaLive = 'polite',
  'data-testid': dataTestId,
  ...restProps
}) => {
  const [shouldFire, setShouldFire] = React.useState();
  const announceOnChange = [title, description, action?.label].filter(Boolean).join('|');
  const statusIconSentiment = sentiment$1 === 'success' ? sentiment.Sentiment.POSITIVE : sentiment$1;
  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__*/jsxRuntime.jsx("span", {
        className: "wds-info-prompt__media",
        children: media.asset
      });
    }
    if (sentiment$1 === 'proposition') {
      return /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "wds-info-prompt__media",
        children: /*#__PURE__*/jsxRuntime.jsx(icons.GiftBox, {})
      });
    }
    return /*#__PURE__*/jsxRuntime.jsx(StatusIcon.default, {
      size: 24,
      sentiment: statusIconSentiment
    });
  };
  // Render content directly in LiveRegion
  return /*#__PURE__*/jsxRuntime.jsx(LiveRegion.LiveRegion, {
    "aria-live": ariaLive,
    announceOnChange: announceOnChange,
    children: /*#__PURE__*/jsxRuntime.jsx(PrimitivePrompt.PrimitivePrompt, {
      sentiment: sentiment$1,
      media: renderMedia(),
      "data-testid": dataTestId,
      className: clsx.clsx('wds-info-prompt', className),
      ...restProps,
      onTouchStart: handleTouchStart,
      onTouchEnd: handleTouchEnd,
      onTouchMove: handleTouchMove,
      onDismiss: onDismiss,
      children: /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "wds-info-prompt__content",
        children: [title && /*#__PURE__*/jsxRuntime.jsx(Body.default, {
          className: "wds-info-prompt__title",
          type: typography.Typography.BODY_LARGE_BOLD,
          as: "span",
          children: title
        }), /*#__PURE__*/jsxRuntime.jsx(Body.default, {
          as: "span",
          className: "wds-info-prompt__description",
          children: description
        }), action && /*#__PURE__*/jsxRuntime.jsx(Link.default, {
          href: action.href,
          target: action.target,
          type: typography.Typography.LINK_DEFAULT,
          className: "wds-info-prompt__action",
          onClick: action.onClick,
          children: action.label
        })]
      })
    })
  });
};

exports.InfoPrompt = InfoPrompt;
//# sourceMappingURL=InfoPrompt.js.map
