'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var Close = require('@bigbinary/neeto-icons/Close');
var Portal = require('./Portal-nCvANFeL.js');
var Button = require('./Button.js');
require('react-router-dom');
require('qs');
var jsxRuntime = require('react/jsx-runtime');
var Typography = require('./Typography.js');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('./index-CNZKW5X0.js');
require('@bigbinary/neeto-cist');
require('ramda');
require('./en-B1i-pQJm.js');
require('./index-BgzkP01c.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('i18next');
require('@babel/runtime/helpers/esm/extends');
require('@babel/runtime/helpers/esm/objectWithoutPropertiesLoose');
require('@babel/runtime/helpers/esm/inheritsLoose');
require('react-dom');
require('./Spinner.js');
require('./Tooltip.js');
require('@tippyjs/react');
require('tippy.js');
require('./usePrefersReducedMotion-D2Ck84HM.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Close__default = /*#__PURE__*/_interopDefault(Close);

var Body = function Body(_ref) {
  var children = _ref.children,
    className = _ref.className,
    dataTestid = _ref.dataTestid;
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: classnames__default.default("neeto-ui-modal__body", className),
    "data-testid": dataTestid !== null && dataTestid !== void 0 ? dataTestid : "modal-body",
    children: children
  });
};

var Footer = function Footer(_ref) {
  var children = _ref.children,
    className = _ref.className,
    dataTestid = _ref.dataTestid;
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: classnames__default.default("neeto-ui-modal__footer", className),
    "data-testid": dataTestid !== null && dataTestid !== void 0 ? dataTestid : "modal-footer",
    children: children
  });
};

var Header = function Header(_ref) {
  var _ref$description = _ref.description,
    description = _ref$description === void 0 ? "" : _ref$description,
    children = _ref.children,
    className = _ref.className,
    dataTestid = _ref.dataTestid;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: classnames__default.default("neeto-ui-modal__header", className),
    "data-testid": dataTestid !== null && dataTestid !== void 0 ? dataTestid : "modal-header",
    children: [children, description && /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-ui-modal__header-desc",
      "data-testid": "modal-header-desc",
      children: /*#__PURE__*/jsxRuntime.jsx(Typography, {
        lineHeight: "normal",
        style: "body2",
        children: description
      })
    })]
  });
};

var MemoizedChildren = /*#__PURE__*/React__default.default.memo(function (_ref) {
  var children = _ref.children;
  return children;
}, function (_, _ref2) {
  var shouldUpdate = _ref2.shouldUpdate;
  return !shouldUpdate;
});
MemoizedChildren.displayName = "MemoizedChildren";

var _excluded = ["size", "isOpen", "onClose", "children", "finalFocusRef", "initialFocusRef", "className", "closeOnEsc", "closeButton", "backdropClassName", "blockScrollOnMount", "closeOnOutsideClick", "forceRender"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var SIZES = {
  small: "small",
  medium: "medium",
  large: "large",
  fullScreen: "fullScreen"
};
var Modal = function Modal(_ref) {
  var _ref$size = _ref.size,
    size = _ref$size === void 0 ? SIZES.medium : _ref$size,
    _ref$isOpen = _ref.isOpen,
    isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
    _ref$onClose = _ref.onClose,
    onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
    children = _ref.children,
    finalFocusRef = _ref.finalFocusRef,
    initialFocusRef = _ref.initialFocusRef,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$closeOnEsc = _ref.closeOnEsc,
    closeOnEsc = _ref$closeOnEsc === void 0 ? true : _ref$closeOnEsc,
    _ref$closeButton = _ref.closeButton,
    closeButton = _ref$closeButton === void 0 ? true : _ref$closeButton,
    _ref$backdropClassNam = _ref.backdropClassName,
    backdropClassName = _ref$backdropClassNam === void 0 ? "" : _ref$backdropClassNam,
    _ref$blockScrollOnMou = _ref.blockScrollOnMount,
    blockScrollOnMount = _ref$blockScrollOnMou === void 0 ? true : _ref$blockScrollOnMou,
    _ref$closeOnOutsideCl = _ref.closeOnOutsideClick,
    closeOnOutsideClick = _ref$closeOnOutsideCl === void 0 ? true : _ref$closeOnOutsideCl,
    _ref$forceRender = _ref.forceRender,
    forceRender = _ref$forceRender === void 0 ? false : _ref$forceRender,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded);
  var _useState = React.useState(false),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    hasTransitionCompleted = _useState2[0],
    setHasTransitionCompleted = _useState2[1];
  var modalWrapper = React.useRef(null);
  var backdropRef = React.useRef(null);
  Portal.useOverlayManager(modalWrapper, isOpen);
  var _useOverlay = Portal.useOverlay({
      isOpen: isOpen,
      initialFocusRef: initialFocusRef,
      finalFocusRef: finalFocusRef,
      overlayWrapper: modalWrapper,
      onClose: onClose,
      backdropRef: backdropRef,
      closeOnOutsideClick: closeOnOutsideClick,
      closeOnEsc: closeOnEsc,
      blockScrollOnMount: blockScrollOnMount,
      hasTransitionCompleted: hasTransitionCompleted
    }),
    handleOverlayClose = _useOverlay.handleOverlayClose,
    setFocusField = _useOverlay.setFocusField;
  var isFullScreenModal = size === SIZES.fullScreen;
  return /*#__PURE__*/jsxRuntime.jsx(Portal.Portal, {
    bringToFront: isOpen,
    rootId: "neeto-ui-portal",
    children: /*#__PURE__*/jsxRuntime.jsx(Portal.CSSTransition, {
      unmountOnExit: true,
      appear: isOpen,
      classNames: "neeto-ui-modal",
      "in": isOpen,
      timeout: 300,
      onEntered: function onEntered() {
        return setHasTransitionCompleted(true);
      },
      onExited: function onExited() {
        return setHasTransitionCompleted(false);
      },
      children: /*#__PURE__*/jsxRuntime.jsx(Portal.Backdrop, {
        ref: backdropRef,
        className: classnames__default.default("neeto-ui-modal__backdrop", {
          "neeto-ui-modal__backdrop--fullscreen": isFullScreenModal
        }, backdropClassName),
        children: /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
          "aria-modal": true,
          ref: modalWrapper,
          role: "dialog",
          className: classnames__default.default("neeto-ui-modal__wrapper", _defineProperty__default.default({
            "neeto-ui-modal__wrapper--small": size === SIZES.small,
            "neeto-ui-modal__wrapper--medium": size === SIZES.medium,
            "neeto-ui-modal__wrapper--large": size === SIZES.large,
            "neeto-ui-modal__wrapper--fullscreen": isFullScreenModal
          }, className, className))
        }, otherProps), {}, {
          children: [closeButton && /*#__PURE__*/jsxRuntime.jsx(Button, {
            "aria-label": "Close",
            className: "neeto-ui-modal__close",
            "data-testid": "modal-close-button",
            icon: Close__default.default,
            size: isFullScreenModal ? "large" : "small",
            style: isFullScreenModal ? "secondary" : "text",
            onClick: handleOverlayClose
          }), /*#__PURE__*/jsxRuntime.jsx(MemoizedChildren, {
            shouldUpdate: isOpen || forceRender,
            children: typeof children === "function" ? children({
              setFocusField: setFocusField
            }) : children
          })]
        }), "modal-wrapper")
      }, "modal-backdrop")
    })
  });
};
Modal.Header = Header;
Modal.Body = Body;
Modal.Footer = Footer;

module.exports = Modal;
//# sourceMappingURL=Modal.js.map
