"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 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 Anchor = require("../Anchor/Anchor.cjs");
const Spoiler_module_css = require("./Spoiler.module.css.cjs");
const useId = require("../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-id/use-id.cjs");
const useUncontrolled = require("../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-uncontrolled/use-uncontrolled.cjs");
const useResizeObserver = require("../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-resize-observer/use-resize-observer.cjs");
const defaultProps = {
  maxHeight: 100,
  initialState: false
};
const varsResolver = createVarsResolver.createVarsResolver((_, { transitionDuration }) => ({
  root: {
    "--spoiler-transition-duration": transitionDuration !== void 0 ? `${transitionDuration}ms` : void 0
  }
}));
const Spoiler = factory.factory((_props, ref) => {
  const props = useProps.useProps("Spoiler", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    initialState,
    maxHeight,
    hideLabel,
    showLabel,
    children,
    controlRef,
    transitionDuration,
    id,
    expanded,
    onExpandedChange,
    ...others
  } = props;
  const getStyles = useStyles.useStyles({
    name: "Spoiler",
    classes: Spoiler_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  const _id = useId.useId(id);
  const regionId = `${_id}-region`;
  const [show, setShowState] = useUncontrolled.useUncontrolled({
    value: expanded,
    defaultValue: initialState,
    finalValue: false,
    onChange: onExpandedChange
  });
  const { ref: contentRef, height } = useResizeObserver.useElementSize();
  const spoilerMoreContent = show ? hideLabel : showLabel;
  const spoiler = spoilerMoreContent !== null && maxHeight < height;
  return /* @__PURE__ */ jsxRuntime.jsxs(
    Box.Box,
    {
      ...getStyles("root"),
      id: _id,
      ref,
      "data-has-spoiler": spoiler || void 0,
      ...others,
      children: [
        spoiler && /* @__PURE__ */ jsxRuntime.jsx(
          Anchor.Anchor,
          {
            component: "button",
            type: "button",
            ref: controlRef,
            onClick: () => setShowState(!show),
            "aria-expanded": show,
            "aria-controls": regionId,
            ...getStyles("control"),
            children: spoilerMoreContent
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(
          "div",
          {
            ...getStyles("content", {
              style: { maxHeight: !show ? rem.rem(maxHeight) : height ? rem.rem(height) : void 0 }
            }),
            "data-reduce-motion": true,
            role: "region",
            id: regionId,
            children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, children })
          }
        )
      ]
    }
  );
});
Spoiler.classes = Spoiler_module_css.default;
Spoiler.displayName = "@mantine/core/Spoiler";
exports.Spoiler = Spoiler;
