'use client';
'use strict';

var React = require('react');
var rem = require('../../core/utils/units-converters/rem.cjs');
var createVarsResolver = require('../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs');
require('clsx');
require('@mantine/hooks');
require('../../core/MantineProvider/Mantine.context.cjs');
require('../../core/MantineProvider/default-theme.cjs');
require('../../core/MantineProvider/MantineProvider.cjs');
require('../../core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs');
var useProps = require('../../core/MantineProvider/use-props/use-props.cjs');
var useStyles = require('../../core/styles-api/use-styles/use-styles.cjs');
var Box = require('../../core/Box/Box.cjs');
var factory = require('../../core/factory/factory.cjs');
require('../../core/DirectionProvider/DirectionProvider.cjs');
var ScrollAreaCorner = require('./ScrollAreaCorner/ScrollAreaCorner.cjs');
var ScrollAreaRoot = require('./ScrollAreaRoot/ScrollAreaRoot.cjs');
var ScrollAreaScrollbar = require('./ScrollAreaScrollbar/ScrollAreaScrollbar.cjs');
var ScrollAreaThumb = require('./ScrollAreaThumb/ScrollAreaThumb.cjs');
var ScrollAreaViewport = require('./ScrollAreaViewport/ScrollAreaViewport.cjs');
var ScrollArea_module = require('./ScrollArea.module.css.cjs');

const defaultProps = {
  scrollHideDelay: 1e3,
  type: "hover",
  scrollbars: "xy"
};
const varsResolver = createVarsResolver.createVarsResolver((_, { scrollbarSize }) => ({
  root: {
    "--scrollarea-scrollbar-size": rem.rem(scrollbarSize)
  }
}));
const ScrollArea = factory.factory((_props, ref) => {
  const props = useProps.useProps("ScrollArea", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    scrollbarSize,
    vars,
    type,
    scrollHideDelay,
    viewportProps,
    viewportRef,
    onScrollPositionChange,
    children,
    offsetScrollbars,
    scrollbars,
    ...others
  } = props;
  const [scrollbarHovered, setScrollbarHovered] = React.useState(false);
  const getStyles = useStyles.useStyles({
    name: "ScrollArea",
    props,
    classes: ScrollArea_module,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  return /* @__PURE__ */ React.createElement(
    ScrollAreaRoot.ScrollAreaRoot,
    {
      type: type === "never" ? "always" : type,
      scrollHideDelay,
      ref,
      scrollbars,
      ...getStyles("root"),
      ...others
    },
    /* @__PURE__ */ React.createElement(
      ScrollAreaViewport.ScrollAreaViewport,
      {
        ...viewportProps,
        ...getStyles("viewport", { style: viewportProps?.style }),
        ref: viewportRef,
        "data-offset-scrollbars": offsetScrollbars === true ? "xy" : offsetScrollbars || void 0,
        "data-scrollbars": scrollbars || void 0,
        onScroll: typeof onScrollPositionChange === "function" ? ({ currentTarget }) => onScrollPositionChange({
          x: currentTarget.scrollLeft,
          y: currentTarget.scrollTop
        }) : void 0
      },
      children
    ),
    (scrollbars === "xy" || scrollbars === "x") && /* @__PURE__ */ React.createElement(
      ScrollAreaScrollbar.ScrollAreaScrollbar,
      {
        ...getStyles("scrollbar"),
        orientation: "horizontal",
        "data-hidden": type === "never" || void 0,
        forceMount: true,
        onMouseEnter: () => setScrollbarHovered(true),
        onMouseLeave: () => setScrollbarHovered(false)
      },
      /* @__PURE__ */ React.createElement(ScrollAreaThumb.ScrollAreaThumb, { ...getStyles("thumb") })
    ),
    (scrollbars === "xy" || scrollbars === "y") && /* @__PURE__ */ React.createElement(
      ScrollAreaScrollbar.ScrollAreaScrollbar,
      {
        ...getStyles("scrollbar"),
        orientation: "vertical",
        "data-hidden": type === "never" || void 0,
        forceMount: true,
        onMouseEnter: () => setScrollbarHovered(true),
        onMouseLeave: () => setScrollbarHovered(false)
      },
      /* @__PURE__ */ React.createElement(ScrollAreaThumb.ScrollAreaThumb, { ...getStyles("thumb") })
    ),
    /* @__PURE__ */ React.createElement(
      ScrollAreaCorner.ScrollAreaCorner,
      {
        ...getStyles("corner"),
        "data-hovered": scrollbarHovered || void 0,
        "data-hidden": type === "never" || void 0
      }
    )
  );
});
ScrollArea.displayName = "@mantine/core/ScrollArea";
const ScrollAreaAutosize = factory.factory((props, ref) => {
  const {
    children,
    classNames,
    styles,
    scrollbarSize,
    scrollHideDelay,
    type,
    dir,
    offsetScrollbars,
    viewportRef,
    onScrollPositionChange,
    unstyled,
    variant,
    viewportProps,
    scrollbars,
    style,
    vars,
    ...others
  } = useProps.useProps("ScrollAreaAutosize", defaultProps, props);
  return /* @__PURE__ */ React.createElement(Box.Box, { ...others, ref, style: [{ display: "flex", overflow: "auto" }, style] }, /* @__PURE__ */ React.createElement(Box.Box, { style: { display: "flex", flexDirection: "column", flex: 1 } }, /* @__PURE__ */ React.createElement(
    ScrollArea,
    {
      classNames,
      styles,
      scrollHideDelay,
      scrollbarSize,
      type,
      dir,
      offsetScrollbars,
      viewportRef,
      onScrollPositionChange,
      unstyled,
      variant,
      viewportProps,
      vars,
      scrollbars
    },
    children
  )));
});
ScrollArea.classes = ScrollArea_module;
ScrollAreaAutosize.displayName = "@mantine/core/ScrollAreaAutosize";
ScrollAreaAutosize.classes = ScrollArea_module;
ScrollArea.Autosize = ScrollAreaAutosize;

exports.ScrollArea = ScrollArea;
exports.ScrollAreaAutosize = ScrollAreaAutosize;
//# sourceMappingURL=ScrollArea.cjs.map
