"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const ScrollArea_context = require("../ScrollArea.context.cjs");
const useResizeObserver = require("../use-resize-observer.cjs");
const ScrollAreaScrollbarVisible = require("./ScrollAreaScrollbarVisible.cjs");
const useDebouncedCallback = require("../../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-debounced-callback/use-debounced-callback.cjs");
const ScrollAreaScrollbarAuto = React.forwardRef(
  (props, ref) => {
    const context = ScrollArea_context.useScrollAreaContext();
    const { forceMount, ...scrollbarProps } = props;
    const [visible, setVisible] = React.useState(false);
    const isHorizontal = props.orientation === "horizontal";
    const handleResize = useDebouncedCallback.useDebouncedCallback(() => {
      if (context.viewport) {
        const isOverflowX = context.viewport.offsetWidth < context.viewport.scrollWidth;
        const isOverflowY = context.viewport.offsetHeight < context.viewport.scrollHeight;
        setVisible(isHorizontal ? isOverflowX : isOverflowY);
      }
    }, 10);
    useResizeObserver.useResizeObserver(context.viewport, handleResize);
    useResizeObserver.useResizeObserver(context.content, handleResize);
    if (forceMount || visible) {
      return /* @__PURE__ */ jsxRuntime.jsx(
        ScrollAreaScrollbarVisible.ScrollAreaScrollbarVisible,
        {
          "data-state": visible ? "visible" : "hidden",
          ...scrollbarProps,
          ref
        }
      );
    }
    return null;
  }
);
ScrollAreaScrollbarAuto.displayName = "@mantine/core/ScrollAreaScrollbarAuto";
exports.ScrollAreaScrollbarAuto = ScrollAreaScrollbarAuto;
