import { i as e } from "../../sanitize-CDxuPfMB.js";
import { n as t, t as n } from "../../utils-C_mWfcFX.js";
//#region src/navigation/stepper/index.ts
var r = {
	complete: "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"m9 12 2 2 4-4\"/></svg>",
	error: "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"m15 9-6 6\"/><path d=\"m9 9 6 6\"/></svg>"
}, i = class {
	container;
	orientation;
	allowClick;
	linear;
	className;
	onChangeCallback;
	stepperId;
	steps;
	currentIndex;
	destroyed = !1;
	constructor(e) {
		this.container = n(e.container), this.steps = [...e.steps], this.orientation = e.orientation ?? "horizontal", this.allowClick = e.allowClick !== !1, this.linear = e.linear === !0, this.className = e.className, this.onChangeCallback = e.onChange, this.stepperId = t("cmm-stepper"), this.currentIndex = this.steps.findIndex((e) => e.status === "active"), this.currentIndex < 0 && (this.currentIndex = 0), this.applyStatuses(), this.render();
	}
	goTo(e) {
		this.destroyed || e < 0 || e >= this.steps.length || this.steps[e]?.status !== "disabled" && (this.linear && e > this.currentIndex + 1 || this.setCurrentIndex(e));
	}
	next() {
		this.currentIndex < this.steps.length - 1 && this.goTo(this.currentIndex + 1);
	}
	prev() {
		this.currentIndex > 0 && this.goTo(this.currentIndex - 1);
	}
	getCurrentIndex() {
		return this.currentIndex;
	}
	update(e) {
		this.destroyed || (this.steps = [...e], this.applyStatuses(), this.render());
	}
	destroy() {
		this.destroyed || (this.destroyed = !0, this.container.innerHTML = "");
	}
	setCurrentIndex(e) {
		for (let t = 0; t < this.steps.length; t++) {
			let n = this.steps[t];
			n && n.status !== "disabled" && (t < e ? n.status !== "error" && (n.status = "complete") : t === e ? n.status = "active" : n.status !== "error" && (n.status = "pending"));
		}
		this.currentIndex = e, this.render(), this.onChangeCallback?.(e);
	}
	applyStatuses() {
		for (let e = 0; e < this.steps.length; e++) {
			let t = this.steps[e];
			t && t.status === void 0 && (e < this.currentIndex ? t.status = "complete" : e === this.currentIndex ? t.status = "active" : t.status = "pending");
		}
	}
	render() {
		this.container.innerHTML = "";
		let t = document.createElement("div");
		t.className = "cmm-stepper", t.id = this.stepperId, t.setAttribute("role", "navigation"), t.setAttribute("aria-label", "Progress"), this.orientation === "vertical" && t.classList.add("cmm-stepper--vertical"), this.className && t.classList.add(this.className);
		let n = document.createElement("ol");
		n.className = "cmm-stepper__list";
		for (let t = 0; t < this.steps.length; t++) {
			let i = this.steps[t];
			if (!i) continue;
			let a = i.status ?? "pending", o = document.createElement("li");
			if (o.className = `cmm-stepper__step cmm-stepper__step--${a}`, t > 0) {
				let e = document.createElement("div");
				e.className = "cmm-stepper__connector", e.setAttribute("aria-hidden", "true"), this.steps[t - 1]?.status === "complete" && e.classList.add("cmm-stepper__connector--complete"), o.appendChild(e);
			}
			let s = document.createElement("div");
			if (s.className = "cmm-stepper__indicator", i.icon ? e(s, i.icon) : a === "complete" || a === "error" ? e(s, r[a] ?? "") : s.textContent = String(t + 1), this.allowClick && a !== "disabled" && (!this.linear || t <= this.currentIndex + 1)) {
				s.classList.add("cmm-stepper__indicator--clickable"), s.setAttribute("tabindex", "0"), s.setAttribute("role", "button"), s.setAttribute("aria-label", `Go to step ${String(t + 1)}: ${i.label}`);
				let e = t;
				s.addEventListener("click", () => {
					this.goTo(e);
				}), s.addEventListener("keydown", (t) => {
					(t.key === "Enter" || t.key === " ") && (t.preventDefault(), this.goTo(e));
				});
			}
			o.appendChild(s);
			let c = document.createElement("div");
			c.className = "cmm-stepper__content";
			let l = document.createElement("div");
			if (l.className = "cmm-stepper__label", l.textContent = i.label, a === "active" && l.setAttribute("aria-current", "step"), c.appendChild(l), i.description) {
				let e = document.createElement("div");
				e.className = "cmm-stepper__description", e.textContent = i.description, c.appendChild(e);
			}
			o.appendChild(c), n.appendChild(o);
		}
		t.appendChild(n), this.container.appendChild(t);
	}
};
//#endregion
export { i as Stepper };

//# sourceMappingURL=index.js.map