"use client";
"use client";
import { cn as e } from "../../../lib/utils.js";
import { t } from "../../../button-BNOmhdpM.js";
import { SparkleBurst as n } from "../atoms/sparkle-burst.js";
import { StepIndicator as r, stepIndicatorIconVariants as i, stepIndicatorLabelVariants as a } from "../atoms/step-indicator.js";
import { useEffect as o, useRef as s, useState as c } from "react";
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
import { Check as f, X as p } from "lucide-react";
//#region lib/components/ui/molecules/steps-progress.tsx
function m({ step: t, stepNumber: n, isAttention: i }) {
	let a = /* @__PURE__ */ u(r, {
		className: "min-w-0",
		label: t.label,
		status: t.status,
		stepNumber: n
	}), o = e("flex min-w-0 flex-1 items-center justify-center", i && "step-attention-target");
	return t.onClick ? /* @__PURE__ */ u("button", {
		className: e(o, "cursor-pointer"),
		onClick: t.onClick,
		type: "button",
		children: a
	}) : /* @__PURE__ */ u("span", {
		className: o,
		children: a
	});
}
function h(e) {
	return e.length - 1;
}
function g(e) {
	return e.findIndex((e) => e.status === "active");
}
function _(e, t) {
	return e.length === 0 ? t ? 0 : -1 : t ? e.length : h(e);
}
function v(e, t) {
	let { currentIndex: n, isDismissible: r = !1 } = t ?? {}, i = g(e);
	if (i >= 0) return i;
	if (e.length === 0) return r ? 0 : -1;
	let a = _(e, r);
	return n !== void 0 && n >= 0 && n <= a ? n : h(e);
}
function y(e) {
	return `calc(${(e - 1) / e} * (100% - 4.25rem) + 0.75rem)`;
}
function b({ steps: r, onDismiss: h, animateStepTransitions: g = !1, orientation: _ = "horizontal", className: b, ...x }) {
	let S = !!h, [C, w] = c(void 0), T = s(null), E = s(null), D = s(0);
	o(() => {
		let e = T.current, t = new Map(r.map((e) => [e.id, e.status]));
		if (e === null) {
			T.current = t;
			return;
		}
		if (g) {
			let t = r.find((t) => t.status === "complete" && e.get(t.id) !== "complete");
			t && (E.current !== null && window.clearTimeout(E.current), D.current += 1, w({
				stepId: t.id,
				key: D.current
			}), E.current = window.setTimeout(() => {
				w(void 0), E.current = null;
			}, 800));
		}
		T.current = t;
	}, [g, r]), o(() => () => {
		E.current !== null && window.clearTimeout(E.current);
	}, []);
	let O = v(r), k = r[O], A = S && r.at(-1)?.status === "active";
	return _ === "vertical" ? /* @__PURE__ */ u("section", {
		"aria-label": "Steps progress",
		className: e(b),
		...x,
		children: /* @__PURE__ */ u("ol", {
			className: "flex flex-col",
			children: r.map((t, n) => {
				let o = n === r.length - 1;
				return /* @__PURE__ */ d("li", {
					className: e("flex items-start gap-3", !o && "pb-5"),
					children: [/* @__PURE__ */ d("div", {
						className: "flex shrink-0 flex-col items-center self-stretch",
						children: [/* @__PURE__ */ u("span", {
							className: e(i({ status: t.status })),
							children: t.status === "complete" ? /* @__PURE__ */ u(f, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ u("span", {
								className: "text-sm",
								children: n + 1
							})
						}), !o && /* @__PURE__ */ u("div", { className: "mt-2 w-px flex-1 bg-border" })]
					}), /* @__PURE__ */ d("span", {
						"aria-current": t.status === "active" ? "step" : void 0,
						className: e(a({ status: t.status }), "pt-0.5"),
						children: [t.label, /* @__PURE__ */ d("span", {
							className: "sr-only",
							children: [" — ", t.status]
						})]
					})]
				}, t.id);
			})
		})
	}) : /* @__PURE__ */ d("section", {
		"aria-label": "Steps progress",
		className: e("relative h-14 overflow-hidden border border-border bg-card text-foreground", b),
		...x,
		children: [
			A && /* @__PURE__ */ u("span", {
				"aria-hidden": "true",
				className: "pointer-events-none absolute top-0 right-0 z-10 hidden h-0.5 bg-foreground sm:block",
				style: { left: y(r.length) }
			}),
			k?.status === "active" && /* @__PURE__ */ u("span", {
				"aria-hidden": "true",
				className: "pointer-events-none absolute inset-x-0 top-0 z-20 h-0.5 bg-foreground sm:hidden"
			}),
			/* @__PURE__ */ d("div", {
				className: "relative z-10 flex h-full items-center sm:gap-3 sm:px-3",
				children: [
					/* @__PURE__ */ u("ol", {
						className: "flex h-full min-w-0 flex-1 items-center gap-0",
						children: r.map((t, r) => {
							let i = C?.stepId === t.id;
							return /* @__PURE__ */ d("li", {
								"aria-current": t.status === "active" ? "step" : void 0,
								className: e("relative isolate flex h-full min-w-0 flex-1 items-center justify-center px-2 py-4 sm:px-3", r !== O && "hidden sm:flex"),
								"data-attention": i ? "true" : void 0,
								"data-status": t.status,
								children: [
									r > 0 && /* @__PURE__ */ u("span", {
										"aria-hidden": "true",
										className: "absolute left-0 hidden h-full w-px bg-border sm:block"
									}),
									/* @__PURE__ */ u(m, {
										isAttention: i,
										step: t,
										stepNumber: r + 1
									}),
									i ? /* @__PURE__ */ u("span", {
										"aria-hidden": !0,
										className: "pointer-events-none absolute inset-0 z-30 flex items-center justify-center",
										children: /* @__PURE__ */ u(n, {}, C.key)
									}) : null
								]
							}, t.id);
						})
					}),
					r.length > 0 && k && /* @__PURE__ */ d("span", {
						"aria-hidden": "true",
						className: "shrink-0 px-3 font-mono text-muted-foreground text-xs tabular-nums sm:hidden",
						children: [
							O + 1,
							" / ",
							r.length
						]
					}),
					h && /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ d(t, {
						"aria-label": "Dismiss",
						className: "h-8 shrink-0 gap-1.5 border border-border px-3 text-muted-foreground hover:bg-muted hover:text-foreground sm:hidden",
						onClick: h,
						type: "button",
						variant: "ghost",
						children: [/* @__PURE__ */ u(p, { className: "h-4 w-4" }), /* @__PURE__ */ u("span", {
							className: "text-sm",
							children: "Dismiss"
						})]
					}), /* @__PURE__ */ u(t, {
						"aria-label": "Dismiss steps progress",
						className: "hidden h-8 w-8 shrink-0 border border-border text-muted-foreground hover:bg-muted hover:text-foreground sm:flex",
						onClick: h,
						size: "icon",
						type: "button",
						variant: "ghost",
						children: /* @__PURE__ */ u(p, { className: "h-4 w-4" })
					})] })
				]
			})
		]
	});
}
//#endregion
export { b as StepsProgress, v as getMobileIndexForSteps };
