"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useReturnFocusOnClose = useReturnFocusOnClose;
var _react = require("react");
/**
 * Returns focus to the previously focused element when the full-screen drawer is dismissed.
 */
function useReturnFocusOnClose({
  isShown
}) {
  const lastActiveElement = (0, _react.useRef)(null);
  (0, _react.useLayoutEffect)(() => {
    if (isShown) {
      lastActiveElement.current = document.activeElement;
    } else {
      lastActiveElement.current?.focus();
    }
    return () => lastActiveElement?.current?.focus();
  }, [isShown]);
}