//#region src/ui/index.ts
var e = {
	storageKey: "theme",
	defaultTheme: "system",
	themes: [
		"light",
		"dark",
		"monokai",
		"glass",
		"system"
	],
	attribute: "data-theme"
}, t = { ...e };
function n(n) {
	t = {
		...e,
		...n
	};
}
function r(e) {
	return e ? t.themes.includes(e) : !1;
}
function i(e) {
	switch (e) {
		case "monokai": return "Monokai";
		case "glass": return "Glass";
		case "dark": return "Dark";
		case "light": return "Light";
		case "system": return "System";
		default: return e;
	}
}
function a() {
	let e = localStorage.getItem(t.storageKey);
	return r(e) ? e : t.defaultTheme;
}
function o(e = a()) {
	return e === "system" ? window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : e;
}
function s() {
	let e = document.documentElement.getAttribute(t.attribute);
	return r(e) ? e : a();
}
function c(e = a()) {
	let n = o(e);
	document.documentElement.classList.remove("light", "dark", "monokai", "glass"), document.documentElement.classList.add(n), document.documentElement.setAttribute(t.attribute, n);
}
function l(e) {
	localStorage.setItem(t.storageKey, e);
}
function u(e) {
	l(e), c(e), g(e);
}
function d(e) {
	let n = t.themes.filter((e) => e !== "system"), r = n.indexOf(e);
	return r >= 0 && n.length > 0 ? n[(r + 1) % n.length] ?? "light" : "dark";
}
function f() {
	let e = d(s());
	return u(e), e;
}
function p(e) {
	t = {
		...t,
		themes: e
	};
}
function m(e, t) {
	let n = `Switch to ${i(d(t))} mode`;
	e.setAttribute("aria-label", n), e.setAttribute("title", n);
	let r = e.querySelector("[data-theme-label]");
	r && (r.textContent = `${i(t)} mode`);
}
function h(e) {
	document.querySelectorAll("[data-theme-option]").forEach((t) => {
		let n = t.dataset.themeOption;
		if (!r(n)) return;
		let i = n === e;
		t.setAttribute("aria-pressed", i ? "true" : "false"), t.dataset.active = i ? "true" : "false";
	});
}
function g(e) {
	let t = o(e);
	document.querySelectorAll("[data-theme-toggle]").forEach((e) => {
		m(e, t);
	}), h(t);
}
function _(e) {
	let t = e ?? "[data-theme-toggle]";
	document.querySelectorAll(t).forEach((e) => {
		e.addEventListener("click", () => f());
	});
}
function v() {
	document.querySelectorAll("[data-theme-option]").forEach((e) => {
		let t = e.dataset.themeOption;
		r(t) && e.addEventListener("click", () => {
			u(t);
		});
	});
}
function y(e) {
	let n = window.matchMedia("(prefers-color-scheme: dark)"), r = (n) => {
		let r = localStorage.getItem(t.storageKey);
		if (!(r === "system" || !(r !== null && r !== "") && t.defaultTheme === "system")) return;
		let i = n.matches ? "dark" : "light";
		c("system"), g(i), e?.(i);
	};
	return n.addEventListener("change", r), () => {
		n.removeEventListener("change", r);
	};
}
function b(e) {
	e && n(e);
	let t = a();
	c(t), g(t), _(), v(), y();
}
function x(e = 5e3) {
	document.querySelectorAll("[data-auto-dismiss]").forEach((t) => {
		let n = parseInt(t.dataset.autoDismiss ?? "", 10);
		setTimeout(() => {
			t.classList.add("opacity-0", "transition-opacity", "duration-300"), setTimeout(() => {
				t.remove();
			}, 300);
		}, Number.isNaN(n) || n === 0 ? e : n);
	});
}
function S(e, t) {
	let n = document.querySelector(e);
	n && (n.querySelectorAll(".field-error").forEach((e) => {
		e.remove();
	}), n.querySelectorAll(".input-error").forEach((e) => {
		e.classList.remove("input-error", "border-red-500");
	}), t.forEach(({ field: e, message: t }) => {
		let r = n.querySelector(`[name="${e}"]`);
		if (r) {
			r.classList.add("input-error", "border-red-500");
			let e = document.createElement("p");
			e.className = "field-error text-red-500 text-sm mt-1", e.textContent = t, r.parentNode?.appendChild(e);
		}
	}));
}
function C(e) {
	let t = document.querySelector(e);
	t && (t.querySelectorAll(".field-error").forEach((e) => {
		e.remove();
	}), t.querySelectorAll(".input-error").forEach((e) => {
		e.classList.remove("input-error", "border-red-500");
	}));
}
async function w(e, t = {}) {
	let n = document.querySelector(e);
	if (!n) return {
		ok: !1,
		errors: [{
			field: "",
			message: "Form not found"
		}]
	};
	let r = new FormData(n), i = n.action === "" ? window.location.href : n.action, a = t.method ?? (n.method === "" ? "POST" : n.method), o, s = { ...t.headers };
	t.transform ? (o = JSON.stringify(t.transform(r)), s["Content-Type"] = "application/json") : o = r;
	try {
		let e = await fetch(i, {
			method: a,
			headers: s,
			body: o
		}), t = await e.json();
		if (!e.ok) {
			let e = t;
			return {
				ok: !1,
				errors: e.errors ?? [{
					field: "",
					message: e.message ?? "Request failed"
				}]
			};
		}
		return {
			ok: !0,
			data: t
		};
	} catch (e) {
		return {
			ok: !1,
			errors: [{
				field: "",
				message: e instanceof Error ? e.message : "Network error"
			}]
		};
	}
}
function T(e, t) {
	t ? (e.disabled = !0, e.dataset.originalText = e.textContent || "", e.innerHTML = "\n      <svg class=\"animate-spin -ml-1 mr-2 h-4 w-4 inline\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\">\n        <circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"4\"></circle>\n        <path class=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"></path>\n      </svg>\n      Loading...\n    ") : (e.disabled = !1, e.textContent = e.dataset.originalText ?? "Submit");
}
//#endregion
export { c as applyTheme, C as clearFormErrors, n as configureTheme, S as displayFormErrors, s as getCurrentTheme, d as getNextTheme, a as getPreferredTheme, o as getResolvedTheme, i as getThemeLabel, b as initTheme, r as isValidTheme, l as saveTheme, T as setButtonLoading, u as setTheme, x as setupAutoDismiss, v as setupThemeOptions, _ as setupThemeToggle, w as submitForm, f as toggleTheme, p as updateToggleCycle, y as watchSystemTheme };

//# sourceMappingURL=index.js.map