"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const createOptionalContext = require("../../core/utils/create-optional-context/create-optional-context.cjs");
const getDefaultZIndex = require("../../core/utils/get-default-z-index/get-default-z-index.cjs");
require("clsx");
const [ModalStackProvider, useModalStackContext] = createOptionalContext.createOptionalContext();
function ModalStack({ children }) {
  const [stack, setStack] = React.useState([]);
  const [maxZIndex, setMaxZIndex] = React.useState(getDefaultZIndex.getDefaultZIndex("modal"));
  return /* @__PURE__ */ jsxRuntime.jsx(
    ModalStackProvider,
    {
      value: {
        stack,
        addModal: (id, zIndex) => {
          setStack((current) => [.../* @__PURE__ */ new Set([...current, id])]);
          setMaxZIndex(
            (current) => typeof zIndex === "number" && typeof current === "number" ? Math.max(current, zIndex) : current
          );
        },
        removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),
        getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,
        currentId: stack[stack.length - 1],
        maxZIndex
      },
      children
    }
  );
}
ModalStack.displayName = "@mantine/core/ModalStack";
exports.ModalStack = ModalStack;
exports.useModalStackContext = useModalStackContext;
