"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactFocusLock = _interopRequireDefault(require("react-focus-lock"));
var _framerMotion = require("framer-motion");
var _reactRemoveScroll = require("react-remove-scroll");
var _ = require("../..");
var _BottomSheet = require("./BottomSheet.styles");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var BottomSheet = function BottomSheet(_ref) {
  var children = _ref.children,
    className = _ref.className,
    closeOnClickOutside = _ref.closeOnClickOutside,
    fullScreenMobile = _ref.fullScreenMobile,
    _ref$height = _ref.height,
    height = _ref$height === void 0 ? '40%' : _ref$height,
    onClose = _ref.onClose,
    open = _ref.open,
    _ref$showBackdrop = _ref.showBackdrop,
    showBackdrop = _ref$showBackdrop === void 0 ? true : _ref$showBackdrop,
    title = _ref.title;
  var internalRef = (0, _react.useRef)(null);
  (0, _.useOnClickOutside)(internalRef, function () {
    if (closeOnClickOutside && typeof onClose === 'function') {
      onClose();
    }
  });
  return _react.default.createElement(_.Portal, null, _react.default.createElement(_framerMotion.AnimatePresence, null, open ? _react.default.createElement(_reactFocusLock.default, {
    disabled: fullScreenMobile
  }, _react.default.createElement(_reactRemoveScroll.RemoveScroll, {
    enabled: !fullScreenMobile
  }, showBackdrop && _react.default.createElement(_framerMotion.motion.div, {
    key: "backdrop",
    initial: {
      opacity: 0,
      zIndex: _.theme.zIndex.overlay,
      position: 'fixed'
    },
    exit: {
      opacity: 0
    },
    animate: {
      opacity: 1
    },
    transition: {
      type: 'ease',
      duration: 0.2
    }
  }, _react.default.createElement(_BottomSheet.Backdrop, {
    container: true,
    alignItems: "center",
    justifyContent: "center"
  })), _react.default.createElement(_framerMotion.motion.div, {
    key: "bottomsheet",
    initial: {
      bottom: '-100%',
      position: 'fixed',
      zIndex: _.theme.zIndex.modal
    },
    exit: {
      bottom: '-100%'
    },
    animate: {
      bottom: 0
    },
    transition: {
      type: 'ease',
      duration: 0.2
    },
    style: {
      width: '100%',
      height: '100%'
    }
  }, _react.default.createElement(_BottomSheet.StyledBottomSheet, {
    className: className,
    fullScreenMobile: fullScreenMobile,
    height: height,
    ref: internalRef
  }, _react.default.createElement(_.Flexbox, {
    container: true,
    direction: "column",
    gap: 2
  }, _react.default.createElement(_.Flexbox, {
    container: true,
    item: true,
    justifyContent: "space-between",
    alignItems: "center"
  }, _react.default.createElement(_.Flexbox, {
    item: true
  }, title), typeof onClose === 'function' && _react.default.createElement(_.Flexbox, {
    item: true
  }, _react.default.createElement(_.Button.Icon, {
    variant: "primary",
    onClick: onClose,
    size: "s"
  }, _react.default.createElement(_.Icon.Cross16, {
    color: "currentColor"
  })))), _react.default.createElement(_.Flexbox, {
    item: true
  }, children)))))) : null));
};
var _default = exports.default = BottomSheet;