"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const getDefaultZIndex = require("../../core/utils/get-default-z-index/get-default-z-index.cjs");
require("clsx");
const useProps = require("../../core/MantineProvider/use-props/use-props.cjs");
const factory = require("../../core/factory/factory.cjs");
const DrawerBody = require("./DrawerBody.cjs");
const DrawerCloseButton = require("./DrawerCloseButton.cjs");
const DrawerContent = require("./DrawerContent.cjs");
const DrawerHeader = require("./DrawerHeader.cjs");
const DrawerOverlay = require("./DrawerOverlay.cjs");
const DrawerRoot = require("./DrawerRoot.cjs");
const DrawerStack = require("./DrawerStack.cjs");
const DrawerTitle = require("./DrawerTitle.cjs");
const Drawer_module_css = require("./Drawer.module.css.cjs");
const defaultProps = {
  closeOnClickOutside: true,
  withinPortal: true,
  lockScroll: true,
  trapFocus: true,
  returnFocus: true,
  closeOnEscape: true,
  keepMounted: false,
  zIndex: getDefaultZIndex.getDefaultZIndex("modal"),
  withOverlay: true,
  withCloseButton: true
};
const Drawer = factory.factory((_props, ref) => {
  const {
    title,
    withOverlay,
    overlayProps,
    withCloseButton,
    closeButtonProps,
    children,
    opened,
    stackId,
    zIndex,
    ...others
  } = useProps.useProps("Drawer", defaultProps, _props);
  const ctx = DrawerStack.useDrawerStackContext();
  const hasHeader = !!title || withCloseButton;
  const stackProps = ctx && stackId ? {
    closeOnEscape: ctx.currentId === stackId,
    trapFocus: ctx.currentId === stackId,
    zIndex: ctx.getZIndex(stackId)
  } : {};
  const overlayVisible = withOverlay === false ? false : stackId && ctx ? ctx.currentId === stackId : opened;
  React.useEffect(() => {
    if (ctx && stackId) {
      opened ? ctx.addModal(stackId, zIndex || getDefaultZIndex.getDefaultZIndex("modal")) : ctx.removeModal(stackId);
    }
  }, [opened, stackId, zIndex]);
  return /* @__PURE__ */ jsxRuntime.jsxs(
    DrawerRoot.DrawerRoot,
    {
      ref,
      opened,
      zIndex: ctx && stackId ? ctx.getZIndex(stackId) : zIndex,
      ...others,
      ...stackProps,
      children: [
        withOverlay && /* @__PURE__ */ jsxRuntime.jsx(
          DrawerOverlay.DrawerOverlay,
          {
            visible: overlayVisible,
            transitionProps: ctx && stackId ? { duration: 0 } : void 0,
            ...overlayProps
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsxs(DrawerContent.DrawerContent, { __hidden: ctx && stackId && opened ? stackId !== ctx.currentId : false, children: [
          hasHeader && /* @__PURE__ */ jsxRuntime.jsxs(DrawerHeader.DrawerHeader, { children: [
            title && /* @__PURE__ */ jsxRuntime.jsx(DrawerTitle.DrawerTitle, { children: title }),
            withCloseButton && /* @__PURE__ */ jsxRuntime.jsx(DrawerCloseButton.DrawerCloseButton, { ...closeButtonProps })
          ] }),
          /* @__PURE__ */ jsxRuntime.jsx(DrawerBody.DrawerBody, { children })
        ] })
      ]
    }
  );
});
Drawer.classes = Drawer_module_css.default;
Drawer.displayName = "@mantine/core/Drawer";
Drawer.Root = DrawerRoot.DrawerRoot;
Drawer.Overlay = DrawerOverlay.DrawerOverlay;
Drawer.Content = DrawerContent.DrawerContent;
Drawer.Body = DrawerBody.DrawerBody;
Drawer.Header = DrawerHeader.DrawerHeader;
Drawer.Title = DrawerTitle.DrawerTitle;
Drawer.CloseButton = DrawerCloseButton.DrawerCloseButton;
Drawer.Stack = DrawerStack.DrawerStack;
exports.Drawer = Drawer;
