import { o as e } from "../../sanitize-uWpY18N9.js";
import { n as t, t as n } from "../../utils-CSEWuKHo.js";
//#region src/navigation/breadcrumb/index.ts
var r = class {
	container;
	separator;
	maxVisible;
	className;
	onNavigate;
	navId;
	items;
	destroyed = !1;
	constructor(e) {
		this.container = n(e.container), this.items = [...e.items], this.separator = e.separator ?? "/", this.maxVisible = e.maxVisible, this.className = e.className, this.onNavigate = e.onNavigate, this.navId = t("cmm-breadcrumb"), this.render();
	}
	update(e) {
		this.destroyed || (this.items = [...e], this.render());
	}
	destroy() {
		this.destroyed || (this.destroyed = !0, this.container.replaceChildren());
	}
	getVisibleItems() {
		if (this.maxVisible === void 0 || this.items.length <= this.maxVisible) return [...this.items];
		let e = this.maxVisible - 1, t = this.items[0], n = this.items.slice(this.items.length - e);
		return t === void 0 ? [] : [
			t,
			"ellipsis",
			...n
		];
	}
	render() {
		this.container.replaceChildren();
		let t = document.createElement("nav");
		t.id = this.navId, t.className = "cmm-breadcrumb", t.setAttribute("aria-label", "Breadcrumb"), this.className && t.classList.add(this.className);
		let n = document.createElement("ol");
		n.className = "cmm-breadcrumb__list";
		let r = this.getVisibleItems();
		for (let t = 0; t < r.length; t++) {
			let i = r[t];
			if (t > 0) {
				let e = document.createElement("li");
				e.className = "cmm-breadcrumb__separator", e.setAttribute("aria-hidden", "true"), e.textContent = this.separator, n.appendChild(e);
			}
			if (i === "ellipsis") {
				let e = document.createElement("li");
				e.className = "cmm-breadcrumb__item cmm-breadcrumb__item--ellipsis", e.setAttribute("aria-hidden", "true");
				let t = document.createElement("span");
				t.className = "cmm-breadcrumb__ellipsis", t.textContent = "…", e.appendChild(t), n.appendChild(e);
				continue;
			}
			if (i === void 0) continue;
			let a = this.items.indexOf(i), o = document.createElement("li");
			o.className = "cmm-breadcrumb__item", i.current === !0 && o.classList.add("cmm-breadcrumb__item--current");
			let s = i.href && i.current !== !0 ? document.createElement("a") : document.createElement("span");
			if (s.className = "cmm-breadcrumb__link", s instanceof HTMLAnchorElement && i.href && (s.href = i.href), i.current === !0 && s.setAttribute("aria-current", "page"), i.icon) {
				let t = document.createElement("span");
				t.className = "cmm-breadcrumb__icon", t.setAttribute("aria-hidden", "true"), e(t, i.icon), s.appendChild(t);
			}
			let c = document.createElement("span");
			if (c.textContent = i.label, s.appendChild(c), i.href && i.current !== !0) {
				let e = i;
				s.addEventListener("click", (t) => {
					this.onNavigate && (t.preventDefault(), this.onNavigate(e, a));
				});
			}
			o.appendChild(s), n.appendChild(o);
		}
		t.appendChild(n), this.container.appendChild(t);
	}
};
//#endregion
export { r as Breadcrumb };

//# sourceMappingURL=index.js.map