import { f as g } from "../../../property-information/find.mjs";
import { n as b } from "../../../property-information/normalize.mjs";
import { h as N } from "../../../hast-util-parse-selector/index.mjs";
import "../space-separated-tokens/index.mjs";
import "../comma-separated-tokens/index.mjs";
import { __exports as w } from "../../../../_virtual/index2.mjs";
import { __exports as j } from "../../../../_virtual/index3.mjs";
var x = g, d = b, S = N, l = w.parse, h = j.parse, q = _, v = {}.hasOwnProperty;
function _(e, t, r) {
  var n = r ? z(r) : null;
  return p;
  function p(m, a) {
    var i = S(m, t), f = Array.prototype.slice.call(arguments, 2), s = i.tagName.toLowerCase(), o;
    if (i.tagName = n && v.call(n, s) ? n[s] : s, a && C(a, i) && (f.unshift(a), a = null), a)
      for (o in a)
        c(i.properties, o, a[o]);
    return y(i.children, f), i.tagName === "template" && (i.content = {
      type: "root",
      children: i.children
    }, i.children = []), i;
  }
  function c(m, a, i) {
    var f, s, o;
    i == null || i !== i || (f = x(e, a), s = f.property, o = i, typeof o == "string" && (f.spaceSeparated ? o = l(o) : f.commaSeparated ? o = h(o) : f.commaOrSpaceSeparated && (o = l(h(o).join(" ")))), s === "style" && typeof i != "string" && (o = L(o)), s === "className" && m.className && (o = m.className.concat(o)), m[s] = k(f, s, o));
  }
}
function C(e, t) {
  return typeof e == "string" || "length" in e || P(t.tagName, e);
}
function P(e, t) {
  var r = t.type;
  return e === "input" || !r || typeof r != "string" ? !1 : typeof t.children == "object" && "length" in t.children ? !0 : (r = r.toLowerCase(), e === "button" ? r !== "menu" && r !== "submit" && r !== "reset" && r !== "button" : "value" in t);
}
function y(e, t) {
  var r, n;
  if (typeof t == "string" || typeof t == "number") {
    e.push({
      type: "text",
      value: String(t)
    });
    return;
  }
  if (typeof t == "object" && "length" in t) {
    for (r = -1, n = t.length; ++r < n; )
      y(e, t[r]);
    return;
  }
  if (typeof t != "object" || !("type" in t))
    throw new Error("Expected node, nodes, or string, got `" + t + "`");
  e.push(t);
}
function k(e, t, r) {
  var n, p, c;
  if (typeof r != "object" || !("length" in r))
    return u(e, t, r);
  for (p = r.length, n = -1, c = []; ++n < p; )
    c[n] = u(e, t, r[n]);
  return c;
}
function u(e, t, r) {
  var n = r;
  return e.number || e.positiveNumber ? !isNaN(n) && n !== "" && (n = Number(n)) : (e.boolean || e.overloadedBoolean) && typeof n == "string" && (n === "" || d(r) === d(t)) && (n = !0), n;
}
function L(e) {
  var t = [], r;
  for (r in e)
    t.push([r, e[r]].join(": "));
  return t.join("; ");
}
function z(e) {
  for (var t = e.length, r = -1, n = {}, p; ++r < t; )
    p = e[r], n[p.toLowerCase()] = p;
  return n;
}
export {
  q as f
};
