"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Modal = Modal;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react2 = require("@headlessui/react");

var _solid = require("@heroicons/react/solid");

var _clsx = _interopRequireDefault(require("clsx"));

require("./index.css");

var _jsxRuntime = require("react/jsx-runtime");

var _excluded = ["title", "titleClass", "footerClassName", "actions", "body", "open", "onClose", "allowBackgroundClose", "hideCloseButton", "size"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function Modal(_ref) {
  var title = _ref.title,
      titleClass = _ref.titleClass,
      footerClassName = _ref.footerClassName,
      actions = _ref.actions,
      body = _ref.body,
      open = _ref.open,
      onClose = _ref.onClose,
      allowBackgroundClose = _ref.allowBackgroundClose,
      hideCloseButton = _ref.hideCloseButton,
      size = _ref.size,
      rest = _objectWithoutProperties(_ref, _excluded);

  var _rest = _objectSpread({}, rest),
      children = _rest.children;

  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Transition.Root, {
    show: open,
    as: _react.Fragment,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Dialog, _objectSpread(_objectSpread({
      as: "div",
      "auto-reopen": "true",
      className: "fixed z-50 inset-0",
      onClose: allowBackgroundClose ? onClose : function () {}
    }, rest), {}, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: (0, _clsx.default)("flex items-center justify-center h-full", {
          "py-8": size === "full"
        }),
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Transition.Child, {
          as: _react.Fragment,
          enter: "ease-out duration-300",
          enterFrom: "opacity-0",
          enterTo: "opacity-100",
          leave: "ease-in duration-200",
          leaveFrom: "opacity-100",
          leaveTo: "opacity-0",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Dialog.Overlay, {
            className: "fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Transition.Child, {
          as: _react.Fragment,
          enter: "ease-out duration-300",
          enterFrom: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
          enterTo: "opacity-100 translate-y-0 sm:scale-100",
          leave: "ease-in duration-200",
          leaveFrom: "opacity-100 translate-y-0 sm:scale-100",
          leaveTo: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
          children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
            className: (0, _clsx.default)("bg-white rounded-lg text-left shadow-xl transform transition-all w-full flex flex-col", "modal-card-".concat(size)),
            children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
              className: "mt-8 px-8 flex justify-between",
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h1", {
                className: (0, _clsx.default)("font-semibold text-lg", titleClass),
                children: title
              }), !hideCloseButton && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
                className: "pointer-events-none sm:pointer-events-auto",
                children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
                  type: "button",
                  className: "bg-white rounded-md text-gray-400 hover:text-gray-500 focus:outline-none",
                  onClick: onClose,
                  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
                    className: "sr-only",
                    children: "Close"
                  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_solid.XIcon, {
                    className: "w-6 h-6",
                    "aria-hidden": "true"
                  })]
                })
              })]
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
              className: "px-8 overflow-y-auto modal-card__container",
              children: children
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
              className: (0, _clsx.default)("flex my-2 px-8 justify-end", footerClassName),
              children: (actions === null || actions === void 0 ? void 0 : actions.length) && actions
            })]
          })
        })]
      })
    }))
  });
}

Modal.propTypes = {
  title: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.string]),
  titleClass: _propTypes.default.string,
  footerClassName: _propTypes.default.string,
  open: _propTypes.default.bool.isRequired,
  onClose: _propTypes.default.func.isRequired,
  allowBackgroundClose: _propTypes.default.bool,
  hideCloseButton: _propTypes.default.bool,
  size: _propTypes.default.oneOf(["small", "medium", "full"])
};
Modal.defaultProps = {
  title: "",
  titleClass: "",
  footerClassName: "",
  allowBackgroundClose: true,
  hideCloseButton: false,
  size: "medium"
};