import { QuestionMarkCircle } from '@transferwise/icons';
import { clsx } from 'clsx';
import { useState } from 'react';
import { useIntl } from 'react-intl';
import Modal from '../modal/Modal.mjs';
import Popover from '../popover/Popover.mjs';
import messages from './Info.messages.mjs';
import { InfoPresentation } from './infoPresentations.mjs';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { Size } from '../common/propsValues/size.mjs';
import { Position } from '../common/propsValues/position.mjs';

const Info = ({
  className = undefined,
  content = undefined,
  onClick = undefined,
  presentation = InfoPresentation.POPOVER,
  size = Size.SMALL,
  title = undefined,
  'aria-label': ariaLabel,
  preferredPlacement = Position.BOTTOM
}) => {
  const intl = useIntl();
  const [open, setOpen] = useState(false);
  ariaLabel ??= intl.formatMessage(messages.ariaLabel);
  const isModal = presentation === InfoPresentation.MODAL;
  const isSmall = size === Size.SMALL;
  const buttonProps = {
    'aria-label': ariaLabel,
    className: 'btn-unstyled',
    children: /*#__PURE__*/jsx(QuestionMarkCircle, {
      size: isSmall ? 16 : 24
    })
  };
  return /*#__PURE__*/jsx("span", {
    className: clsx(className, 'np-info', {
      'np-info__small': isSmall,
      'np-info__large': !isSmall
    }),
    children: isModal ? /*#__PURE__*/jsxs(Fragment, {
      children: [/*#__PURE__*/jsx("button", {
        type: "button",
        onClick: () => {
          setOpen(!open);
          if (onClick) {
            onClick();
          }
        },
        ...buttonProps
      }), /*#__PURE__*/jsx(Modal, {
        body: content,
        open: open,
        title: title,
        onClose: () => setOpen(false)
      })]
    }) : /*#__PURE__*/jsx(Popover, {
      content: content,
      preferredPlacement: preferredPlacement,
      title: title,
      children: /*#__PURE__*/jsx("button", {
        type: "button",
        ...buttonProps,
        onClick: () => {
          if (onClick) {
            onClick();
          }
        }
      })
    })
  });
};

export { Info as default };
//# sourceMappingURL=Info.mjs.map
