"use client";
const require_rem = require("../../core/utils/units-converters/rem.cjs");
const require_get_size = require("../../core/utils/get-size/get-size.cjs");
const require_create_vars_resolver = require("../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs");
const require_get_theme_color = require("../../core/MantineProvider/color-functions/get-theme-color/get-theme-color.cjs");
const require_get_contrast_color = require("../../core/MantineProvider/color-functions/get-contrast-color/get-contrast-color.cjs");
const require_get_auto_contrast_value = require("../../core/MantineProvider/color-functions/get-auto-contrast-value/get-auto-contrast-value.cjs");
const require_use_props = require("../../core/MantineProvider/use-props/use-props.cjs");
const require_use_styles = require("../../core/styles-api/use-styles/use-styles.cjs");
const require_factory = require("../../core/factory/factory.cjs");
const require_Box = require("../../core/Box/Box.cjs");
const require_Stepper_context = require("./Stepper.context.cjs");
const require_StepperCompleted = require("./StepperCompleted/StepperCompleted.cjs");
const require_Stepper_module = require("./Stepper.module.cjs");
const require_StepperStep = require("./StepperStep/StepperStep.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/components/Stepper/Stepper.tsx
const defaultProps = {
	orientation: "horizontal",
	iconPosition: "left",
	allowNextStepsSelect: true,
	wrap: true
};
const varsResolver = require_create_vars_resolver.createVarsResolver((theme, { color, iconSize, size, contentPadding, radius, autoContrast }) => ({ root: {
	"--stepper-color": color ? require_get_theme_color.getThemeColor(color, theme) : void 0,
	"--stepper-icon-color": require_get_auto_contrast_value.getAutoContrastValue(autoContrast, theme) ? require_get_contrast_color.getContrastColor({
		color,
		theme,
		autoContrast
	}) : void 0,
	"--stepper-icon-size": iconSize === void 0 ? require_get_size.getSize(size, "stepper-icon-size") : require_rem.rem(iconSize),
	"--stepper-content-padding": require_get_size.getSpacing(contentPadding),
	"--stepper-radius": radius === void 0 ? void 0 : require_get_size.getRadius(radius),
	"--stepper-fz": require_get_size.getFontSize(size),
	"--stepper-spacing": require_get_size.getSpacing(size)
} }));
const Stepper = require_factory.factory((_props) => {
	const props = require_use_props.useProps("Stepper", defaultProps, _props);
	const { classNames, className, style, styles, unstyled, vars, children, onStepClick, active, icon, completedIcon, progressIcon, color, iconSize, contentPadding, orientation, iconPosition, size, radius, allowNextStepsSelect, wrap, autoContrast, keepMounted, attributes, ...others } = props;
	const getStyles = require_use_styles.useStyles({
		name: "Stepper",
		classes: require_Stepper_module.default,
		props,
		className,
		style,
		classNames,
		styles,
		unstyled,
		attributes,
		vars,
		varsResolver
	});
	const convertedChildren = react.Children.toArray(children);
	const _children = convertedChildren.filter((child) => child.type !== require_StepperCompleted.StepperCompleted);
	const completedStep = convertedChildren.find((item) => item.type === require_StepperCompleted.StepperCompleted);
	const items = _children.reduce((acc, item, index) => {
		const state = active === index ? "stepProgress" : active > index ? "stepCompleted" : "stepInactive";
		const shouldAllowSelect = () => {
			if (typeof onStepClick !== "function") return false;
			if (typeof item.props.allowStepSelect === "boolean") return item.props.allowStepSelect;
			return state === "stepCompleted" || allowNextStepsSelect;
		};
		const isStepSelectionEnabled = shouldAllowSelect();
		acc.push((0, react.cloneElement)(item, {
			icon: item.props.icon || icon || index + 1,
			key: index,
			step: index,
			state,
			onClick: () => isStepSelectionEnabled && onStepClick?.(index),
			allowStepClick: isStepSelectionEnabled,
			completedIcon: item.props.completedIcon || completedIcon,
			progressIcon: item.props.progressIcon || progressIcon,
			color: item.props.color || color,
			iconSize,
			iconPosition: item.props.iconPosition || iconPosition,
			orientation
		}));
		if (orientation === "horizontal" && index !== _children.length - 1) acc.push(/* @__PURE__ */ (0, react.createElement)("div", {
			...getStyles("separator"),
			"data-active": index < active || void 0,
			"data-orientation": orientation,
			key: `separator-${index}`
		}));
		return acc;
	}, []);
	const stepContent = _children[active]?.props?.children;
	const completedContent = completedStep?.props?.children;
	const content = active > _children.length - 1 ? completedContent : stepContent;
	const contentSection = keepMounted ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [_children.map((child, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Activity, {
		mode: active === index ? "visible" : "hidden",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			...getStyles("content"),
			children: child.props.children
		})
	}, index)), completedStep && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Activity, {
		mode: active > _children.length - 1 ? "visible" : "hidden",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			...getStyles("content"),
			children: completedStep.props.children
		})
	})] }) : content && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		...getStyles("content"),
		children: content
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Stepper_context.StepperProvider, {
		value: {
			getStyles,
			orientation,
			iconPosition
		},
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
			...getStyles("root"),
			size,
			...others,
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Box.Box, {
				...getStyles("steps"),
				mod: {
					orientation,
					"icon-position": iconPosition,
					wrap: wrap && orientation !== "vertical"
				},
				children: items
			}), contentSection]
		})
	});
});
Stepper.classes = require_Stepper_module.default;
Stepper.varsResolver = varsResolver;
Stepper.displayName = "@mantine/core/Stepper";
Stepper.Completed = require_StepperCompleted.StepperCompleted;
Stepper.Step = require_StepperStep.StepperStep;
//#endregion
exports.Stepper = Stepper;

//# sourceMappingURL=Stepper.cjs.map