import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/display/uptime-bar/index.ts
function n(e) {
	if (e.length === 0) return "0.0";
	let t = 0;
	for (let n of e) n.status === "up" && (t += 1);
	return (t / e.length * 100).toFixed(1);
}
var r = class {
	el;
	barId;
	segmentsEl;
	labelEl = null;
	showLabels;
	height;
	constructor(n) {
		this.barId = e("cmm-uptime-bar"), this.showLabels = n.showLabels !== !1, this.height = n.height ?? 32, this.el = document.createElement("div"), this.el.id = this.barId, this.el.className = this.buildClassName(n.className), this.el.setAttribute("role", "img"), this.el.setAttribute("aria-label", "Uptime status bar"), this.segmentsEl = document.createElement("div"), this.segmentsEl.className = "cmm-uptime-bar__segments", this.segmentsEl.style.height = `${String(this.height)}px`, this.el.appendChild(this.segmentsEl), this.showLabels && (this.labelEl = document.createElement("div"), this.labelEl.className = "cmm-uptime-bar__label", this.el.appendChild(this.labelEl)), this.renderSegments(n.segments), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	setSegments(e) {
		this.renderSegments(e);
	}
	destroy() {
		this.el.remove();
	}
	renderSegments(e) {
		this.segmentsEl.textContent = "";
		for (let t of e) {
			let e = document.createElement("div");
			e.className = `cmm-uptime-bar__segment cmm-uptime-bar__segment--${t.status}`, t.tooltip !== void 0 && (e.title = t.tooltip), this.segmentsEl.appendChild(e);
		}
		if (this.labelEl !== null) {
			let t = n(e);
			this.labelEl.textContent = `${t}% uptime`, this.el.setAttribute("aria-label", `Uptime status bar: ${t}% uptime`);
		}
	}
	buildClassName(e) {
		let t = ["cmm-uptime-bar"];
		return e && t.push(e), t.join(" ");
	}
};
//#endregion
export { r as UptimeBar };

//# sourceMappingURL=index.js.map