import { getIconSvgInner as e } from "./icons/index.js";
import { t } from "./utils-C_mWfcFX.js";
//#region src/sidebar/component.ts
function n(t, n) {
	let r = "http://www.w3.org/2000/svg", i = document.createElementNS(r, "svg");
	i.setAttribute("xmlns", r), i.setAttribute("width", "18"), i.setAttribute("height", "18"), i.setAttribute("viewBox", "0 0 24 24"), i.setAttribute("fill", "none"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), i.classList.add("sidebar__item-icon"), i.setAttribute("data-icon", n), i.setAttribute("aria-hidden", "true");
	let a = e(t, n);
	return a && (i.innerHTML = a), i;
}
var r = class {
	container;
	aside;
	config;
	iconSet;
	constructor(e) {
		this.config = e, this.container = t(e.container), this.iconSet = e.iconSet ?? "lucide", this.aside = document.createElement("aside"), this.aside.classList.add("sidebar"), this.aside.setAttribute("data-sidebar", e.variant ?? "app"), this.render(), this.container.appendChild(this.aside);
	}
	render() {
		for (let e of this.config.sections) {
			let t = document.createElement("div");
			if (t.classList.add("sidebar__section"), e.label) {
				let n = document.createElement("div");
				n.classList.add("sidebar__section-label"), n.textContent = e.label, t.appendChild(n);
			}
			for (let r of e.items) {
				let e = document.createElement("a");
				if (e.classList.add("sidebar__item"), e.setAttribute("data-item-id", r.id), r.icon) {
					let t = n(this.iconSet, r.icon);
					e.appendChild(t);
				}
				let i = document.createElement("span");
				if (i.classList.add("sidebar__item-label"), i.textContent = r.label, e.appendChild(i), r.badge !== void 0 && r.badge > 0) {
					let t = document.createElement("span");
					t.classList.add("sidebar__badge"), t.setAttribute("data-badge", r.id), t.textContent = String(r.badge), e.appendChild(t);
				}
				e.addEventListener("click", () => {
					this.config.onNavigate && this.config.onNavigate(r), r.onClick && r.onClick();
				}), t.appendChild(e);
			}
			this.aside.appendChild(t);
		}
		this.renderFooter();
	}
	renderFooter() {
		let e = this.config.user !== void 0, t = this.config.footerActions !== void 0 && this.config.footerActions.length > 0;
		if (!e && !t) return;
		let r = document.createElement("div");
		r.classList.add("sidebar__footer");
		let i = document.createElement("div");
		if (i.classList.add("sidebar__footer-bar"), e && this.config.user) {
			let e = document.createElement("span");
			e.classList.add("sidebar__footer-user");
			let t = document.createElement("span");
			t.classList.add("sidebar__footer-name"), t.textContent = this.config.user.name, e.appendChild(t), i.appendChild(e);
		}
		if (t && this.config.footerActions) {
			let e = document.createElement("span");
			e.classList.add("sidebar__footer-icons");
			for (let t of this.config.footerActions) {
				let r = document.createElement("button");
				r.classList.add("sidebar__footer-icon"), t.danger === !0 && r.classList.add("sidebar__footer-icon--danger"), r.setAttribute("aria-label", t.label);
				let i = n(this.iconSet, t.icon);
				if (r.appendChild(i), t.onClick) {
					let e = t.onClick;
					r.addEventListener("click", () => {
						e();
					});
				}
				e.appendChild(r);
			}
			i.appendChild(e);
		}
		r.appendChild(i), this.aside.appendChild(r);
	}
	setActive(e) {
		this.aside.querySelectorAll(".sidebar__item").forEach((e) => {
			e.classList.remove("sidebar__item--active");
		});
		let t = this.aside.querySelector(`[data-item-id="${e}"]`);
		t && t.classList.add("sidebar__item--active");
	}
	updateBadge(e, t) {
		let n = this.aside.querySelector(`[data-badge="${e}"]`);
		n && (n.textContent = t > 0 ? String(t) : "");
	}
	toggleCollapse() {
		let e = this.aside.classList.toggle("sidebar--collapsed");
		this.config.onCollapse && this.config.onCollapse(e);
	}
	collapse() {
		this.aside.classList.add("sidebar--collapsed");
	}
	expand() {
		this.aside.classList.remove("sidebar--collapsed");
	}
	destroy() {
		this.aside.remove();
	}
};
//#endregion
export { r as t };

//# sourceMappingURL=component-x2UxdKEC.js.map