import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/display/progress/index.ts
var n = 2 * Math.PI * 16;
function r(e) {
	return Math.min(100, Math.max(0, e));
}
var i = class {
	el;
	progressId;
	variant;
	size;
	showLabel;
	currentValue;
	currentLabel;
	fillEl = null;
	labelEl = null;
	circleFillEl = null;
	constructor(n) {
		this.progressId = e("cmm-progress"), this.variant = n.variant ?? "linear", this.size = n.size ?? "md", this.showLabel = n.showLabel === !0, this.currentLabel = n.label, this.currentValue = n.value === void 0 ? void 0 : r(n.value), this.el = document.createElement("div"), this.el.id = this.progressId, this.el.setAttribute("role", "progressbar"), this.el.setAttribute("aria-valuemin", "0"), this.el.setAttribute("aria-valuemax", "100"), this.currentValue !== void 0 && this.el.setAttribute("aria-valuenow", String(this.currentValue)), this.el.setAttribute("aria-label", n.ariaLabel ?? "Progress"), this.el.className = this.buildClassName(n.className), n.color && this.el.style.setProperty("--cmm-progress-color", n.color), this.variant === "linear" ? this.buildLinear() : this.buildCircular(), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	setValue(e) {
		if (this.currentValue = r(e), this.el.setAttribute("aria-valuenow", String(this.currentValue)), this.el.classList.remove("cmm-progress--indeterminate"), this.variant === "linear") this.fillEl && (this.fillEl.style.width = `${String(this.currentValue)}%`);
		else if (this.circleFillEl) {
			let e = n * (1 - this.currentValue / 100);
			this.circleFillEl.setAttribute("stroke-dashoffset", String(e));
		}
		this.updateLabelText();
	}
	setLabel(e) {
		e === null ? this.currentLabel = void 0 : this.currentLabel = e, this.updateLabelText();
	}
	destroy() {
		this.el.remove();
	}
	buildClassName(e) {
		let t = [
			"cmm-progress",
			`cmm-progress--${this.variant}`,
			`cmm-progress--${this.size}`
		];
		return this.currentValue === void 0 && t.push("cmm-progress--indeterminate"), e && t.push(e), t.join(" ");
	}
	buildLinear() {
		let e = document.createElement("div");
		e.className = "cmm-progress__track";
		let t = document.createElement("div");
		if (t.className = "cmm-progress__fill", this.currentValue !== void 0 && (t.style.width = `${String(this.currentValue)}%`), e.appendChild(t), this.el.appendChild(e), this.fillEl = t, this.showLabel) {
			let e = document.createElement("span");
			e.className = "cmm-progress__label", e.textContent = this.getLabelText(), this.el.appendChild(e), this.labelEl = e;
		}
	}
	buildCircular() {
		let e = "http://www.w3.org/2000/svg", t = document.createElementNS(e, "svg");
		t.setAttribute("viewBox", "0 0 36 36");
		let r = document.createElementNS(e, "circle");
		r.setAttribute("class", "cmm-progress__circle-bg"), r.setAttribute("cx", "18"), r.setAttribute("cy", "18"), r.setAttribute("r", "16"), r.setAttribute("stroke-width", "3"), t.appendChild(r);
		let i = document.createElementNS(e, "circle");
		if (i.setAttribute("class", "cmm-progress__circle-fill"), i.setAttribute("cx", "18"), i.setAttribute("cy", "18"), i.setAttribute("r", "16"), i.setAttribute("stroke-width", "3"), i.setAttribute("stroke-dasharray", String(n)), this.currentValue !== void 0) {
			let e = n * (1 - this.currentValue / 100);
			i.setAttribute("stroke-dashoffset", String(e));
		} else {
			let e = n * .75;
			i.setAttribute("stroke-dashoffset", String(e));
		}
		if (t.appendChild(i), this.circleFillEl = i, this.showLabel) {
			let n = document.createElementNS(e, "text");
			n.setAttribute("class", "cmm-progress__circle-label"), n.setAttribute("x", "18"), n.setAttribute("y", "18"), n.textContent = this.getLabelText(), t.appendChild(n), this.labelEl = n;
		}
		this.el.appendChild(t);
	}
	getLabelText() {
		return this.currentLabel === void 0 ? this.currentValue === void 0 ? "" : `${String(this.currentValue)}%` : this.currentLabel;
	}
	updateLabelText() {
		this.labelEl && (this.labelEl.textContent = this.getLabelText());
	}
};
//#endregion
export { i as Progress };

//# sourceMappingURL=index.js.map