"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Overlay = void 0;

var _base = _interopRequireDefault(require("@emotion/styled/base"));

var _react = require("@emotion/react");

var _react2 = _interopRequireDefault(require("react"));

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

var _excluded = ["isOpen", "offsetTop", "children"];

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

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; }

/**
 * The amount of time in milliseconds for the
 * overlay in/out transition to complete.
 * This const is used to determine when to apply
 * the hidden state.
 */
var TRANSITION_DURATION = 300;
var OverlayWrapper = (0, _base["default"])("div", process.env.NODE_ENV === "production" ? {
  target: "e1lrjmpf0"
} : {
  target: "e1lrjmpf0",
  label: "OverlayWrapper"
})(function (_ref) {
  var _ref$transitionState = _ref.transitionState,
      transitionState = _ref$transitionState === void 0 ? 'exited' : _ref$transitionState,
      _ref$offsetTop = _ref.offsetTop,
      offsetTop = _ref$offsetTop === void 0 ? 0 : _ref$offsetTop;
  return [{
    "position": "fixed",
    "left": "0px",
    "right": "0px",
    "zIndex": "50",
    "bottom": "0px"
  }, /*#__PURE__*/(0, _react.css)("top:", offsetTop, "px;" + (process.env.NODE_ENV === "production" ? "" : ";label:OverlayWrapper;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sYXlvdXQvT3ZlcmxheS50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBMEJPIiwiZmlsZSI6Ii4uLy4uL3NyYy9sYXlvdXQvT3ZlcmxheS50c3giLCJzb3VyY2VzQ29udGVudCI6WyIvKiogQGpzeEltcG9ydFNvdXJjZSBAZW1vdGlvbi9yZWFjdCAqL1xuaW1wb3J0IFJlYWN0LCB7IEZ1bmN0aW9uQ29tcG9uZW50IH0gZnJvbSAncmVhY3QnO1xuaW1wb3J0IHR3LCB7IGNzcywgc3R5bGVkIH0gZnJvbSAndHdpbi5tYWNybyc7XG5cbi8qKlxuICogVGhlIGFtb3VudCBvZiB0aW1lIGluIG1pbGxpc2Vjb25kcyBmb3IgdGhlXG4gKiBvdmVybGF5IGluL291dCB0cmFuc2l0aW9uIHRvIGNvbXBsZXRlLlxuICogVGhpcyBjb25zdCBpcyB1c2VkIHRvIGRldGVybWluZSB3aGVuIHRvIGFwcGx5XG4gKiB0aGUgaGlkZGVuIHN0YXRlLlxuICovXG5jb25zdCBUUkFOU0lUSU9OX0RVUkFUSU9OID0gMzAwO1xuXG50eXBlIFRyYW5zaXRpb25TdGF0ZSA9ICdlbnRlcmluZycgfCAnZW50ZXJlZCcgfCAnZXhpdGluZycgfCAnZXhpdGVkJztcblxudHlwZSBPdmVybGF5UHJvcHMgPSB7XG4gIGlzT3BlbjogYm9vbGVhbjtcbiAgb2Zmc2V0VG9wPzogbnVtYmVyO1xufTtcblxudHlwZSBPdmVybGF5V3JhcHBlclByb3BzID0gT3ZlcmxheVByb3BzICYge1xuICB0cmFuc2l0aW9uU3Rh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zaXRpb25TdGF0ZSgnZXhpdGluZycpO1xuICAgIH1cbiAgfSwgW2lzT3Blbiwgc2V0VHJhbnNpdGlvblN0YXRlXSk7XG4gIHJldHVybiAoXG4gICAgPD5cbiAgICAgIHtpc09wZW4gJiYgKFxuICAgICAgICA8T3ZlcmxheVdyYXBwZXJcbiAgICAgICAgICBvZmZzZXRUb3A9e29mZnNldFRvcH1cbiAgICAgICAgICBpc09wZW49e2lzT3Blbn1cbiAgICAgICAgICB0cmFuc2l0aW9uU3RhdGU9e3RyYW5zaXRpb25TdGF0ZX1cbiAgICAgICAgICB7Li4ucHJvcHN9XG4gICAgICAgID5cbiAgICAgICAgICB7Y2hpbGRyZW59XG4gICAgICAgIDwvT3ZlcmxheVdyYXBwZXI+XG4gICAgICApfVxuICAgIDwvPlxuICApO1xufTtcblxuZXhwb3J0IGRlZmF1bHQgT3ZlcmxheTtcbiJdfQ== */"), {
    "transitionProperty": "opacity",
    "transitionTimingFunction": "cubic-bezier(0.4, 0, 0.2, 1)",
    "transitionDuration": "300ms"
  }, transitionState === 'entered' && {
    "opacity": "1"
  }, transitionState === 'entering' && {
    "opacity": "1",
    "pointerEvents": "none"
  }, transitionState === 'exiting' && {
    "opacity": "0",
    "pointerEvents": "none"
  }, transitionState === 'exited' && {
    "opacity": "0"
  }];
}, process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sYXlvdXQvT3ZlcmxheS50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBdUJ1QiIsImZpbGUiOiIuLi8uLi9zcmMvbGF5b3V0L092ZXJsYXkudHN4Iiwic291cmNlc0NvbnRlbnQiOlsiLyoqIEBqc3hJbXBvcnRTb3VyY2UgQGVtb3Rpb24vcmVhY3QgKi9cbmltcG9ydCBSZWFjdCwgeyBGdW5jdGlvbkNvbXBvbmVudCB9IGZyb20gJ3JlYWN0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Wx0IE92ZXJsYXk7XG4iXX0= */");

var Overlay = function Overlay(_ref2) {
  var _ref2$isOpen = _ref2.isOpen,
      isOpen = _ref2$isOpen === void 0 ? false : _ref2$isOpen,
      _ref2$offsetTop = _ref2.offsetTop,
      offsetTop = _ref2$offsetTop === void 0 ? 0 : _ref2$offsetTop,
      children = _ref2.children,
      props = _objectWithoutProperties(_ref2, _excluded);

  var _React$useState = _react2["default"].useState(isOpen ? 'entered' : 'exited'),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      transitionState = _React$useState2[0],
      setTransitionState = _React$useState2[1];

  _react2["default"].useEffect(function () {
    var timeout = setTimeout(function () {
      setTransitionState(function (transitionState) {
        if (transitionState === 'entering') {
          return 'entered';
        }

        if (transitionState === 'exiting') {
          return 'exited';
        }

        return transitionState;
      });
      timeout = null;
    }, TRANSITION_DURATION);
    return function () {
      if (!timeout) return;
      clearTimeout(timeout);
    };
  }, [isOpen, setTransitionState]);

  _react2["default"].useEffect(function () {
    if (isOpen) {
      if (transitionState !== 'entered') setTransitionState('entering');
    } else {
      if (transitionState !== 'exited') setTransitionState('exiting');
    }
  }, [isOpen, setTransitionState]);

  return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: isOpen && (0, _jsxRuntime.jsx)(OverlayWrapper, _objectSpread(_objectSpread({
      offsetTop: offsetTop,
      isOpen: isOpen,
      transitionState: transitionState
    }, props), {}, {
      children: children
    }))
  });
};

exports.Overlay = Overlay;
var _default = Overlay;
exports["default"] = _default;