var _excluded = ["position", "full", "backdrop", "margin", "onClickOutside", "onEsc", "borderShadow", "children", "backdropContainerProps", "backdropProps", "dataDrop"];
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; }
import React, { useRef } from "react";
import ReactDOM from "react-dom";
import useDropElement from "../../../hooks/useDropElement";
import useOutsideClick from "../../../hooks/useOutsideClick";
import useKeyboardEsc from "../../../hooks/useKeyboardEsc";
import Container from "./container";
import BackdropContainer from "./backdropContainer";
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 = useRef();
  useOutsideClick(ref, onClickOutside, null, backdrop, dataDrop);
  useKeyboardEsc(onEsc);
  var el = useDropElement();
  var content = /*#__PURE__*/React.createElement(Container, _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.createPortal(backdrop ? /*#__PURE__*/React.createElement(BackdropContainer, _extends({
    backdropContainerProps: backdropContainerProps,
    backdropProps: backdropProps
  }, rest, {
    onClick: onClickOutside
  }), content) : content, el);
};
export default Layer;