'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var formatting = require('@transferwise/formatting');
var reactIntl = require('react-intl');
var Chevron = require('../../chevron/Chevron.js');
require('../../common/theme.js');
require('../../common/direction.js');
require('../../common/propsValues/control.js');
require('../../common/propsValues/breakpoint.js');
var size = 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');
var position = require('../../common/propsValues/position.js');
require('../../common/propsValues/layouts.js');
require('../../common/propsValues/status.js');
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');
var icons = require('@transferwise/icons');
require('clsx');
var React = require('react');
require('../../common/closeButton/CloseButton.messages.js');
var jsxRuntime = require('react/jsx-runtime');
var DateTrigger_messages = require('./DateTrigger.messages.js');
var OverlayIdProvider = require('../../provider/overlay/OverlayIdProvider.js');
var Body = require('../../body/Body.js');
var IconButton = require('../../iconButton/IconButton.js');

const DateTrigger = ({
  selectedDate,
  size: size$1 = size.Size.MEDIUM,
  placeholder,
  label,
  id,
  monthFormat,
  disabled,
  ariaLabelledBy,
  onClick,
  onClear
}) => {
  const {
    locale,
    formatMessage
  } = reactIntl.useIntl();
  const valueIdPrefix = React.useId();
  const overlayId = React.useContext(OverlayIdProvider.OverlayIdContext);
  const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
    children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
      id: id,
      "aria-haspopup": "dialog",
      "aria-expanded": overlayId != null,
      "aria-controls": overlayId,
      "aria-labelledby": ariaLabelIds.filter(Boolean).join(' '),
      className: `btn btn-${size$1} btn-input np-date-trigger`,
      disabled: disabled,
      type: "button",
      onClick: onClick,
      children: [label && /*#__PURE__*/jsxRuntime.jsx(Body.default, {
        as: "span",
        className: "np-date-trigger-label m-r-1",
        id: ariaLabelIds[1],
        children: label
      }), selectedDate ? /*#__PURE__*/jsxRuntime.jsx(Body.default, {
        as: "span",
        type: typography.Typography.BODY_LARGE,
        id: ariaLabelIds[2],
        children: formatting.formatDate(selectedDate, locale, {
          day: 'numeric',
          month: monthFormat,
          year: 'numeric'
        })
      }) : /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "form-control-placeholder visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xl-inline",
        id: ariaLabelIds[2],
        children: placeholder
      }), !onClear ? /*#__PURE__*/jsxRuntime.jsx(Chevron.default, {
        orientation: position.Position.BOTTOM,
        disabled: disabled
      }) : null]
    }), onClear ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [/*#__PURE__*/jsxRuntime.jsx("div", {
        className: "clearfix"
      }), /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "input-group-addon",
        children: /*#__PURE__*/jsxRuntime.jsx(IconButton.default, {
          size: 32,
          priority: "minimal",
          className: `clear-btn clear-btn--${size$1}`,
          "aria-label": `${formatMessage(DateTrigger_messages.default.ariaLabel)} ${label}`,
          onClick: event => {
            event.stopPropagation();
            event.preventDefault();
            onClear();
          },
          children: /*#__PURE__*/jsxRuntime.jsx(icons.Cross, {})
        })
      })]
    }) : null]
  });
};

exports.default = DateTrigger;
//# sourceMappingURL=DateTrigger.js.map
