"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.DrawerToggle = void 0;
var _Button = _interopRequireDefault(require("../Button/Button"));
var _compat = require("preact/compat");
var _classnames = _interopRequireDefault(require("classnames"));
var _usePrevious = _interopRequireDefault(require("../utilities/usePrevious"));
var _jsxRuntime = require("preact/compat/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * A link that triggers the visibility of a drawer
 */
const DrawerToggle = _ref => {
  let {
    className,
    children,
    inline,
    showDrawer,
    drawerOpen,
    ...others
  } = _ref;
  const buttonRef = (0, _compat.useRef)(null);
  const prevDrawerOpenProp = (0, _usePrevious.default)(drawerOpen);
  (0, _compat.useEffect)(() => {
    // if drawer was open but now closed, focus the toggle
    if (prevDrawerOpenProp && !drawerOpen && buttonRef.current) {
      buttonRef.current.focus();
    }
  }, [drawerOpen]);
  const classes = (0, _classnames.default)('ds-c-drawer__toggle', inline && 'ds-c-drawer__toggle--inline', className);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
    className: classes,
    inputRef: el => buttonRef.current = el,
    onClick: showDrawer,
    variation: "ghost",
    ...others,
    children: children
  });
};
exports.DrawerToggle = DrawerToggle;
var _default = exports.default = DrawerToggle;