import { getTheme as e, setThemePartial as t } from "../../services/theme-engine/index.js";
//#region src/components/theme/glass-slider.ts
function n(e, t, n) {
	return Math.max(t, Math.min(n, e));
}
var r = 0, i = .2, a = .01, o = class {
	el;
	input;
	value;
	_onThemeChange;
	constructor(o = {}) {
		let c = o.expanded === !0, l = n(e().transparency, r, i);
		if (this.el = document.createElement("div"), this.el.className = c ? "preview-glass-slider preview-glass-slider--expanded" : "preview-glass-slider", !c) {
			let e = document.createElement("span");
			e.className = "preview-glass-slider__label", e.textContent = "Glass", this.el.appendChild(e);
		}
		let u = document.createElement("div");
		if (u.className = "preview-glass-slider__row", c) {
			let e = document.createElement("span");
			e.className = "preview-glass-slider__edge", e.textContent = "Solid", u.appendChild(e);
		}
		this.input = document.createElement("input"), this.input.type = "range", this.input.min = String(r), this.input.max = String(i), this.input.step = String(a), this.input.value = String(l), this.input.className = "preview-glass-slider__input", this.input.setAttribute("aria-label", "Surface transparency");
		let d = `cm-glass-value-${Math.random().toString(36).slice(2, 8)}`;
		if (this.input.setAttribute("aria-describedby", d), this.input.setAttribute("aria-valuetext", `${Math.round(l * 100)}% transparency`), u.appendChild(this.input), c) {
			let e = document.createElement("span");
			e.className = "preview-glass-slider__edge", e.textContent = "Frosted", u.appendChild(e);
		}
		this.value = document.createElement("span"), this.value.className = "preview-glass-slider__value", this.value.id = d, this.value.setAttribute("aria-live", "polite"), this.value.textContent = s(l), u.appendChild(this.value), this.el.appendChild(u), this.applySliderFill(l), this.input.addEventListener("input", () => {
			t({ transparency: n(Number(this.input.value), r, i) });
		}), this._onThemeChange = () => {
			let t = n(e().transparency, r, i);
			this.input.value !== String(t) && (this.input.value = String(t)), this.input.setAttribute("aria-valuetext", `${Math.round(t * 100)}% transparency`), this.value.textContent = s(t), this.applySliderFill(t);
		}, document.addEventListener("cm:theme-change", this._onThemeChange);
	}
	destroy() {
		document.removeEventListener("cm:theme-change", this._onThemeChange);
	}
	applySliderFill(e) {
		let t = (e - r) / (i - r) * 100;
		this.input.style.setProperty("--slider-pct", `${t}%`);
	}
};
function s(e) {
	return `${Math.round(e * 100)}%`;
}
//#endregion
export { o as GlassSlider };

//# sourceMappingURL=glass-slider.js.map