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

//# sourceMappingURL=index.js.map