"use client";
import { rem } from "../../core/utils/units-converters/rem.mjs";
import { getFontSize, getRadius, getSize, getSpacing } from "../../core/utils/get-size/get-size.mjs";
import { createVarsResolver } from "../../core/styles-api/create-vars-resolver/create-vars-resolver.mjs";
import { getThemeColor } from "../../core/MantineProvider/color-functions/get-theme-color/get-theme-color.mjs";
import { getContrastColor } from "../../core/MantineProvider/color-functions/get-contrast-color/get-contrast-color.mjs";
import { getAutoContrastValue } from "../../core/MantineProvider/color-functions/get-auto-contrast-value/get-auto-contrast-value.mjs";
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
import { useStyles } from "../../core/styles-api/use-styles/use-styles.mjs";
import { factory } from "../../core/factory/factory.mjs";
import { Box } from "../../core/Box/Box.mjs";
import { StepperProvider } from "./Stepper.context.mjs";
import { StepperCompleted } from "./StepperCompleted/StepperCompleted.mjs";
import Stepper_module_default from "./Stepper.module.mjs";
import { StepperStep } from "./StepperStep/StepperStep.mjs";
import { Activity, Children, cloneElement, createElement } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/Stepper/Stepper.tsx
const defaultProps = {
	orientation: "horizontal",
	iconPosition: "left",
	allowNextStepsSelect: true,
	wrap: true
};
const varsResolver = createVarsResolver((theme, { color, iconSize, size, contentPadding, radius, autoContrast }) => ({ root: {
	"--stepper-color": color ? getThemeColor(color, theme) : void 0,
	"--stepper-icon-color": getAutoContrastValue(autoContrast, theme) ? getContrastColor({
		color,
		theme,
		autoContrast
	}) : void 0,
	"--stepper-icon-size": iconSize === void 0 ? getSize(size, "stepper-icon-size") : rem(iconSize),
	"--stepper-content-padding": getSpacing(contentPadding),
	"--stepper-radius": radius === void 0 ? void 0 : getRadius(radius),
	"--stepper-fz": getFontSize(size),
	"--stepper-spacing": getSpacing(size)
} }));
const Stepper = factory((_props) => {
	const 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 = useStyles({
		name: "Stepper",
		classes: Stepper_module_default,
		props,
		className,
		style,
		classNames,
		styles,
		unstyled,
		attributes,
		vars,
		varsResolver
	});
	const convertedChildren = Children.toArray(children);
	const _children = convertedChildren.filter((child) => child.type !== StepperCompleted);
	const completedStep = convertedChildren.find((item) => item.type === 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(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__ */ 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__ */ jsxs(Fragment$1, { children: [_children.map((child, index) => /* @__PURE__ */ jsx(Activity, {
		mode: active === index ? "visible" : "hidden",
		children: /* @__PURE__ */ jsx("div", {
			...getStyles("content"),
			children: child.props.children
		})
	}, index)), completedStep && /* @__PURE__ */ jsx(Activity, {
		mode: active > _children.length - 1 ? "visible" : "hidden",
		children: /* @__PURE__ */ jsx("div", {
			...getStyles("content"),
			children: completedStep.props.children
		})
	})] }) : content && /* @__PURE__ */ jsx("div", {
		...getStyles("content"),
		children: content
	});
	return /* @__PURE__ */ jsx(StepperProvider, {
		value: {
			getStyles,
			orientation,
			iconPosition
		},
		children: /* @__PURE__ */ jsxs(Box, {
			...getStyles("root"),
			size,
			...others,
			children: [/* @__PURE__ */ jsx(Box, {
				...getStyles("steps"),
				mod: {
					orientation,
					"icon-position": iconPosition,
					wrap: wrap && orientation !== "vertical"
				},
				children: items
			}), contentSection]
		})
	});
});
Stepper.classes = Stepper_module_default;
Stepper.varsResolver = varsResolver;
Stepper.displayName = "@mantine/core/Stepper";
Stepper.Completed = StepperCompleted;
Stepper.Step = StepperStep;
//#endregion
export { Stepper };

//# sourceMappingURL=Stepper.mjs.map