import { normalize as e } from "../../property-information/lib/normalize.js";
import { find as t } from "../../property-information/lib/find.js";
import { parse as n } from "../../comma-separated-tokens/index.js";
import { parseSelector as r } from "../../hast-util-parse-selector/lib/index.js";
import { parse as i } from "../../space-separated-tokens/index.js";
//#region ../../node_modules/hastscript/lib/create-h.js
function a(e, t, n) {
	let i = n ? d(n) : void 0;
	function a(n, a, ...l) {
		let u;
		if (n == null) {
			u = {
				type: "root",
				children: []
			};
			let e = a;
			l.unshift(e);
		} else {
			u = r(n, t);
			let c = u.tagName.toLowerCase(), d = i ? i.get(c) : void 0;
			if (u.tagName = d || c, o(a)) l.unshift(a);
			else for (let [t, n] of Object.entries(a)) s(e, u.properties, t, n);
		}
		for (let e of l) c(u.children, e);
		return u.type === "element" && u.tagName === "template" && (u.content = {
			type: "root",
			children: u.children
		}, u.children = []), u;
	}
	return a;
}
function o(e) {
	if (typeof e != "object" || !e || Array.isArray(e)) return !0;
	if (typeof e.type != "string") return !1;
	let t = e, n = Object.keys(e);
	for (let e of n) {
		let n = t[e];
		if (n && typeof n == "object") {
			if (!Array.isArray(n)) return !0;
			let e = n;
			for (let t of e) if (typeof t != "number" && typeof t != "string") return !0;
		}
	}
	return !!("children" in e && Array.isArray(e.children));
}
function s(e, r, a, o) {
	let s = t(e, a), c;
	if (o != null) {
		if (typeof o == "number") {
			if (Number.isNaN(o)) return;
			c = o;
		} else c = typeof o == "boolean" ? o : typeof o == "string" ? s.spaceSeparated ? i(o) : s.commaSeparated ? n(o) : s.commaOrSpaceSeparated ? i(n(o).join(" ")) : l(s, s.property, o) : Array.isArray(o) ? [...o] : s.property === "style" ? u(o) : String(o);
		if (Array.isArray(c)) {
			let e = [];
			for (let t of c) e.push(l(s, s.property, t));
			c = e;
		}
		s.property === "className" && Array.isArray(r.className) && (c = r.className.concat(c)), r[s.property] = c;
	}
}
function c(e, t) {
	if (t != null) if (typeof t == "number" || typeof t == "string") e.push({
		type: "text",
		value: String(t)
	});
	else if (Array.isArray(t)) for (let n of t) c(e, n);
	else if (typeof t == "object" && "type" in t) t.type === "root" ? c(e, t.children) : e.push(t);
	else throw Error("Expected node, nodes, or string, got `" + t + "`");
}
function l(t, n, r) {
	if (typeof r == "string") {
		if (t.number && r && !Number.isNaN(Number(r))) return Number(r);
		if ((t.boolean || t.overloadedBoolean) && (r === "" || e(r) === e(n))) return !0;
	}
	return r;
}
function u(e) {
	let t = [];
	for (let [n, r] of Object.entries(e)) t.push([n, r].join(": "));
	return t.join("; ");
}
function d(e) {
	let t = /* @__PURE__ */ new Map();
	for (let n of e) t.set(n.toLowerCase(), n);
	return t;
}
//#endregion
export { a as createH };
