"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const rem = require("../../core/utils/units-converters/rem.cjs");
require("react");
const getDefaultZIndex = require("../../core/utils/get-default-z-index/get-default-z-index.cjs");
const getSize = require("../../core/utils/get-size/get-size.cjs");
const createVarsResolver = require("../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs");
require("clsx");
const useProps = require("../../core/MantineProvider/use-props/use-props.cjs");
const useStyles = require("../../core/styles-api/use-styles/use-styles.cjs");
const factory = require("../../core/factory/factory.cjs");
const DirectionProvider = require("../../core/DirectionProvider/DirectionProvider.cjs");
const ModalBase = require("../ModalBase/ModalBase.cjs");
const Drawer_context = require("./Drawer.context.cjs");
const Drawer_module_css = require("./Drawer.module.css.cjs");
function getDrawerAlign(position) {
  switch (position) {
    case "top":
      return "flex-start";
    case "bottom":
      return "flex-end";
    default:
      return void 0;
  }
}
function getDrawerFlex(position) {
  if (position === "top" || position === "bottom") {
    return "0 0 calc(100% - var(--drawer-offset, 0rem) * 2)";
  }
  return void 0;
}
const transitions = {
  top: "slide-down",
  bottom: "slide-up",
  left: "slide-right",
  right: "slide-left"
};
const rtlTransitions = {
  top: "slide-down",
  bottom: "slide-up",
  right: "slide-right",
  left: "slide-left"
};
const defaultProps = {
  closeOnClickOutside: true,
  withinPortal: true,
  lockScroll: true,
  trapFocus: true,
  returnFocus: true,
  closeOnEscape: true,
  keepMounted: false,
  zIndex: getDefaultZIndex.getDefaultZIndex("modal"),
  position: "left"
};
const varsResolver = createVarsResolver.createVarsResolver((_, { position, size, offset }) => ({
  root: {
    "--drawer-size": getSize.getSize(size, "drawer-size"),
    "--drawer-flex": getDrawerFlex(position),
    "--drawer-height": position === "left" || position === "right" ? void 0 : "var(--drawer-size)",
    "--drawer-align": getDrawerAlign(position),
    "--drawer-justify": position === "right" ? "flex-end" : void 0,
    "--drawer-offset": rem.rem(offset)
  }
}));
const DrawerRoot = factory.factory((_props, ref) => {
  const props = useProps.useProps("DrawerRoot", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    scrollAreaComponent,
    position,
    transitionProps,
    radius,
    ...others
  } = props;
  const { dir } = DirectionProvider.useDirection();
  const getStyles = useStyles.useStyles({
    name: "Drawer",
    classes: Drawer_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  const drawerTransition = (dir === "rtl" ? rtlTransitions : transitions)[position];
  return /* @__PURE__ */ jsxRuntime.jsx(Drawer_context.DrawerProvider, { value: { scrollAreaComponent, getStyles, radius }, children: /* @__PURE__ */ jsxRuntime.jsx(
    ModalBase.ModalBase,
    {
      ref,
      ...getStyles("root"),
      transitionProps: { transition: drawerTransition, ...transitionProps },
      unstyled,
      ...others
    }
  ) });
});
DrawerRoot.classes = Drawer_module_css.default;
DrawerRoot.displayName = "@mantine/core/DrawerRoot";
exports.DrawerRoot = DrawerRoot;
