"use client";
import { rem } from "../../core/utils/units-converters/rem.mjs";
import { getSafeId } from "../../core/utils/get-safe-id/get-safe-id.mjs";
import { getRadius } from "../../core/utils/get-size/get-size.mjs";
import { createVarsResolver } from "../../core/styles-api/create-vars-resolver/create-vars-resolver.mjs";
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
import { useStyles } from "../../core/styles-api/use-styles/use-styles.mjs";
import { genericFactory } from "../../core/factory/factory.mjs";
import { Box } from "../../core/Box/Box.mjs";
import { AccordionProvider } from "./Accordion.context.mjs";
import { AccordionChevron } from "./AccordionChevron.mjs";
import Accordion_module_default from "./Accordion.module.mjs";
import { AccordionControl } from "./AccordionControl/AccordionControl.mjs";
import { AccordionItem } from "./AccordionItem/AccordionItem.mjs";
import { AccordionPanel } from "./AccordionPanel/AccordionPanel.mjs";
import { useId, useUncontrolled } from "@mantine/hooks";
import { jsx } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/Accordion/Accordion.tsx
const defaultProps = {
	multiple: false,
	disableChevronRotation: false,
	chevronPosition: "right",
	variant: "default",
	chevronSize: "auto",
	chevronIconSize: 16
};
const varsResolver = createVarsResolver((_, { transitionDuration, chevronSize, radius }) => ({ root: {
	"--accordion-transition-duration": transitionDuration === void 0 ? void 0 : `${transitionDuration}ms`,
	"--accordion-chevron-size": chevronSize === void 0 ? void 0 : rem(chevronSize),
	"--accordion-radius": radius === void 0 ? void 0 : getRadius(radius)
} }));
const Accordion = genericFactory((_props) => {
	const props = useProps("Accordion", defaultProps, _props);
	const { classNames, className, style, styles, unstyled, vars, children, multiple, value, defaultValue, onChange, id, loop, transitionDuration, disableChevronRotation, chevronPosition, chevronSize, order, chevron, variant, radius, chevronIconSize, attributes, keepMounted, ...others } = props;
	const uid = useId(id);
	const [_value, handleChange] = useUncontrolled({
		value,
		defaultValue,
		finalValue: multiple ? [] : null,
		onChange
	});
	const isItemActive = (itemValue) => Array.isArray(_value) ? _value.includes(itemValue) : itemValue === _value;
	const handleItemChange = (itemValue) => {
		handleChange(Array.isArray(_value) ? _value.includes(itemValue) ? _value.filter((selectedValue) => selectedValue !== itemValue) : [..._value, itemValue] : itemValue === _value ? null : itemValue);
	};
	const getStyles = useStyles({
		name: "Accordion",
		classes: Accordion_module_default,
		props,
		className,
		style,
		classNames,
		styles,
		unstyled,
		attributes,
		vars,
		varsResolver
	});
	return /* @__PURE__ */ jsx(AccordionProvider, {
		value: {
			isItemActive,
			onChange: handleItemChange,
			getControlId: getSafeId(`${uid}-control`, "Accordion.Item component was rendered with invalid value or without value"),
			getRegionId: getSafeId(`${uid}-panel`, "Accordion.Item component was rendered with invalid value or without value"),
			chevron: chevron === null ? null : chevron || /* @__PURE__ */ jsx(AccordionChevron, { size: chevronIconSize }),
			transitionDuration,
			disableChevronRotation,
			chevronPosition,
			order,
			loop,
			getStyles,
			variant,
			unstyled,
			keepMounted
		},
		children: /* @__PURE__ */ jsx(Box, {
			...getStyles("root"),
			id: uid,
			...others,
			variant,
			"data-accordion": true,
			children
		})
	});
});
Accordion.classes = Accordion_module_default;
Accordion.varsResolver = varsResolver;
Accordion.displayName = "@mantine/core/Accordion";
Accordion.Item = AccordionItem;
Accordion.Panel = AccordionPanel;
Accordion.Control = AccordionControl;
Accordion.Chevron = AccordionChevron;
//#endregion
export { Accordion };

//# sourceMappingURL=Accordion.mjs.map