"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
var _useDropElement = _interopRequireDefault(require("../../../hooks/useDropElement"));
var _useOutsideClick = _interopRequireDefault(require("../../../hooks/useOutsideClick"));
var _useKeyboardEsc = _interopRequireDefault(require("../../../hooks/useKeyboardEsc"));
var _container = _interopRequireDefault(require("./container"));
var _backdropContainer = _interopRequireDefault(require("./backdropContainer"));
var _excluded = ["position", "full", "backdrop", "margin", "onClickOutside", "onEsc", "borderShadow", "children", "backdropContainerProps", "backdropProps", "dataDrop"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var emptyArray = [];
var Layer = function Layer(_ref) {
  var _ref$position = _ref.position,
    position = _ref$position === void 0 ? "center" : _ref$position,
    _ref$full = _ref.full,
    full = _ref$full === void 0 ? false : _ref$full,
    _ref$backdrop = _ref.backdrop,
    backdrop = _ref$backdrop === void 0 ? true : _ref$backdrop,
    _ref$margin = _ref.margin,
    margin = _ref$margin === void 0 ? emptyArray : _ref$margin,
    onClickOutside = _ref.onClickOutside,
    onEsc = _ref.onEsc,
    borderShadow = _ref.borderShadow,
    children = _ref.children,
    backdropContainerProps = _ref.backdropContainerProps,
    backdropProps = _ref.backdropProps,
    _ref$dataDrop = _ref.dataDrop,
    dataDrop = _ref$dataDrop === void 0 ? "layer-content" : _ref$dataDrop,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var ref = (0, _react.useRef)();
  (0, _useOutsideClick["default"])(ref, onClickOutside, null, backdrop, dataDrop);
  (0, _useKeyboardEsc["default"])(onEsc);
  var el = (0, _useDropElement["default"])();
  var content = /*#__PURE__*/_react["default"].createElement(_container["default"], _extends({
    isAbsolute: backdrop,
    ref: ref,
    full: full,
    position: position,
    margin: margin,
    borderShadow: borderShadow,
    "data-testid": "layer-container",
    "data-drop": dataDrop
  }, rest), children);
  return /*#__PURE__*/_reactDom["default"].createPortal(backdrop ? /*#__PURE__*/_react["default"].createElement(_backdropContainer["default"], _extends({
    backdropContainerProps: backdropContainerProps,
    backdropProps: backdropProps
  }, rest, {
    onClick: onClickOutside
  }), content) : content, el);
};
var _default = exports["default"] = Layer;