import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default, { useState, useRef } from 'react';
import classnames from 'classnames';
import Close from '@bigbinary/neeto-icons/Close';
import { u as useOverlayManager, a as useOverlay, P as Portal, C as CSSTransition, B as Backdrop } from './Portal-qx5uRFGk.js';
import Button from './Button.js';
import 'react-router-dom';
import 'qs';
import { jsx, jsxs } from 'react/jsx-runtime';
import Typography from './Typography.js';
import '@bigbinary/neeto-hotkeys';
import './overlayManager.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import './index-QWVp_Xt6.js';
import '@bigbinary/neeto-cist';
import 'ramda';
import './en-Dmu3B4Vs.js';
import './index-DyUNP5G9.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'dayjs';
import 'dayjs/plugin/localeData';
import 'dayjs/plugin/utc';
import 'dayjs/plugin/weekday';
import 'dayjs/plugin/weekOfYear';
import 'i18next';
import '@babel/runtime/helpers/esm/extends';
import '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
import '@babel/runtime/helpers/esm/inheritsLoose';
import 'react-dom';
import './Spinner.js';
import './Tooltip.js';
import '@tippyjs/react';
import 'tippy.js';
import './usePrefersReducedMotion-n4ZJtExQ.js';

var Body = function Body(_ref) {
  var children = _ref.children,
    className = _ref.className,
    dataTestid = _ref.dataTestid;
  return /*#__PURE__*/jsx("div", {
    className: classnames("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__*/jsx("div", {
    className: classnames("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__*/jsxs("div", {
    className: classnames("neeto-ui-modal__header", className),
    "data-testid": dataTestid !== null && dataTestid !== void 0 ? dataTestid : "modal-header",
    children: [children, description && /*#__PURE__*/jsx("div", {
      className: "neeto-ui-modal__header-desc",
      "data-testid": "modal-header-desc",
      children: /*#__PURE__*/jsx(Typography, {
        lineHeight: "normal",
        style: "body2",
        children: description
      })
    })]
  });
};

var MemoizedChildren = /*#__PURE__*/React__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(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(_ref, _excluded);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    hasTransitionCompleted = _useState2[0],
    setHasTransitionCompleted = _useState2[1];
  var modalWrapper = useRef(null);
  var backdropRef = useRef(null);
  useOverlayManager(modalWrapper, isOpen);
  var _useOverlay = 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__*/jsx(Portal, {
    bringToFront: isOpen,
    rootId: "neeto-ui-portal",
    children: /*#__PURE__*/jsx(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__*/jsx(Backdrop, {
        ref: backdropRef,
        className: classnames("neeto-ui-modal__backdrop", {
          "neeto-ui-modal__backdrop--fullscreen": isFullScreenModal
        }, backdropClassName),
        children: /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
          "aria-modal": true,
          ref: modalWrapper,
          role: "dialog",
          className: classnames("neeto-ui-modal__wrapper", _defineProperty({
            "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__*/jsx(Button, {
            "aria-label": "Close",
            className: "neeto-ui-modal__close",
            "data-testid": "modal-close-button",
            icon: Close,
            size: isFullScreenModal ? "large" : "small",
            style: isFullScreenModal ? "secondary" : "text",
            onClick: handleOverlayClose
          }), /*#__PURE__*/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;

export { Modal as default };
//# sourceMappingURL=Modal.js.map
