"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 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 Box = require("../../core/Box/Box.cjs");
const factory = require("../../core/factory/factory.cjs");
const UnstyledButton = require("../UnstyledButton/UnstyledButton.cjs");
const TableOfContents_module_css = require("./TableOfContents.module.css.cjs");
const useId = require("../../../../../../../@mantine_hooks@7.17.8_react@18.3.1/node_modules/@mantine/hooks/esm/use-id/use-id.cjs");
const useScrollSpy = require("../../../../../../../@mantine_hooks@7.17.8_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-spy/use-scroll-spy.cjs");
const useMergedRef = require("../../../../../../../@mantine_hooks@7.17.8_react@18.3.1/node_modules/@mantine/hooks/esm/use-merged-ref/use-merged-ref.cjs");
const defaultProps = {
  getControlProps: ({ data }) => ({
    children: data.value
  })
};
const varsResolver = createVarsResolver.createVarsResolver(
  (theme, { color, size, variant, autoContrast, depthOffset, radius }) => {
    const colors = theme.variantColorResolver({
      color: color || theme.primaryColor,
      theme,
      variant: variant || "filled",
      autoContrast
    });
    return {
      root: {
        "--toc-bg": variant !== "none" ? colors.background : void 0,
        "--toc-color": variant !== "none" ? colors.color : void 0,
        "--toc-size": getSize.getFontSize(size),
        "--toc-depth-offset": rem.rem(depthOffset),
        "--toc-radius": getSize.getRadius(radius)
      }
    };
  }
);
const TableOfContents = factory.factory((_props, ref) => {
  const props = useProps.useProps("TableOfContents", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    color,
    autoContrast,
    scrollSpyOptions,
    initialData,
    getControlProps,
    minDepthToOffset,
    depthOffset,
    variant,
    radius,
    reinitializeRef,
    ...others
  } = props;
  const getStyles = useStyles.useStyles({
    name: "TableOfContents",
    classes: TableOfContents_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  const idBase = useId.useId();
  const spy = useScrollSpy.useScrollSpy(scrollSpyOptions);
  useMergedRef.assignRef(reinitializeRef, spy.reinitialize);
  const headingsData = spy.initialized ? spy.data : initialData || [];
  const controls = headingsData.map((data, index) => {
    const controlProps = getControlProps == null ? void 0 : getControlProps({
      active: index === spy.active,
      data: {
        ...data,
        getNode: data.getNode || (() => {
        })
      }
    });
    return /* @__PURE__ */ jsxRuntime.jsx(
      UnstyledButton.UnstyledButton,
      {
        __vars: { "--depth-offset": `${data.depth - (minDepthToOffset || 1)}` },
        "data-active": index === spy.active || void 0,
        variant,
        ...controlProps,
        ...getStyles("control", {
          className: controlProps == null ? void 0 : controlProps.className,
          style: controlProps == null ? void 0 : controlProps.style
        })
      },
      data.id || `${idBase}-${index}`
    );
  });
  return /* @__PURE__ */ jsxRuntime.jsx(Box.Box, { ref, variant, ...getStyles("root"), ...others, children: controls });
});
TableOfContents.displayName = "@mantine/core/TableOfContents";
TableOfContents.classes = TableOfContents_module_css.default;
exports.TableOfContents = TableOfContents;
