const N = (e = "") => {
  if (!e)
    return "";
  const r = e.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);
  return r ? r.map((s) => s.toLowerCase()).join("-") : "";
}, R = (e) => typeof e == "object" && Array.isArray(e), O = (e) => {
  if (R(e)) {
    let r = !0;
    return e.forEach((s) => {
      typeof s != "string" && (r = !1);
    }), r;
  } else
    return !1;
}, m = (e) => typeof e == "string", j = (e) => [
  ...new Set(e.map((r) => r && typeof r == "string" && r.includes(" ") ? j(r.split(" ")) : (r && typeof r == "string" ? r.trim() : null) || "").flat().filter((r) => r !== ""))
], E = (e) => e == null ? !0 : e !== void 0 ? !!e : !1, b = {
  ARRAY: "array",
  STRING: "string",
  AUTO: "auto"
}, l = {
  STRING: "string",
  ARRAY: "array",
  OBJECT: "object",
  NONE: "none"
}, S = (e) => m(e) ? e : "", $ = (e) => m(e) || O(e) ? e : "", C = (e) => {
  if (typeof e != "object" && !Array.isArray(e) && e !== null)
    return !1;
  const r = [
    "b",
    "block",
    "e",
    "element",
    "m",
    "modifier",
    "s",
    "show"
  ];
  return ![
    ...new Set(Object.keys(e).find((t) => !r.includes(t)))
  ].length;
}, I = (e) => !!(R(e) && m(e[0]) && (O(e[1]) || m(e[1]))), B = (e) => !m(e) && e[2] !== void 0 && !e[2], Y = (e, r, s = {}) => {
  const t = [];
  return d(e, S(r[0]), $(r[1]), Object.assign(Object.assign({}, s), { return: b.ARRAY })).forEach((o) => {
    t.push(o);
  }), t;
}, G = (e, r, s = {}) => {
  const t = {
    block: e,
    element: "",
    modifier: ""
  };
  return r.includes(":") ? (t.element = r.split(":")[0], t.modifier = r.split(":")[1]) : t.element = r, d(t.block, t.element, t.modifier, Object.assign(Object.assign({}, s), { return: b.ARRAY }));
}, v = (e, r, s = {}) => {
  if (r.show !== void 0 && !r.show || r.s !== void 0 && !r.s)
    return [];
  const t = (r == null ? void 0 : r.block) || r.b || e, i = {
    element: r.element || r.e || "",
    modifier: r.modifier || r.m || ""
  };
  return d(t, i, "", Object.assign(Object.assign({}, s), { return: b.ARRAY }));
}, x = (e) => e == null ? l.NONE : m(e) && e !== "" ? l.STRING : O(e) && e.length < 4 || I(e) ? B(e) ? l.NONE : l.ARRAY : C(e) ? l.OBJECT : l.NONE, U = (e, r = {}) => (...t) => {
  const i = typeof e == "string" ? [e] : e;
  let o = [];
  return i.forEach((c) => {
    (t.length == 0 || t[0] == null || t[0] == "") && o.push(d(c, "", "", { return: b.STRING })), t.forEach((n) => {
      switch (x(n)) {
        case l.STRING:
          o.push(...G(c, n, r));
          break;
        case l.ARRAY:
          o.push(...Y(c, n, r));
          break;
        case l.OBJECT:
          o.push(...v(c, n, r));
          break;
      }
    });
  }), T(j(o), r);
}, u = {
  ARRAY: "array",
  STRING: "string",
  AUTO: "auto"
}, _ = (e, r, s) => typeof e == "string" && r == "string" ? {
  element: e,
  modifier: r,
  show: s.show
} : typeof e == "object" && (e != null && e.element) && (e != null && e.modifier) ? {
  element: e.element,
  modifier: e.modifier,
  show: e.show
} : {
  element: s.element,
  modifier: s.modifier,
  show: s.show
}, w = (e) => {
  let r = Object.assign({ modifier: "--", element: "__" }, e.prefix);
  return Object.assign(Object.assign({ toKebabCase: !0, return: u.AUTO }, e), { prefix: r });
}, T = (e, r) => {
  switch (r.return) {
    case u.STRING:
      return e.join(" ");
    case u.ARRAY:
      return e;
    default:
    case u.AUTO:
      return e.length == 1 ? e[0] : e;
  }
}, d = (e, r = "", s = "", t) => {
  var i, o;
  if (e == "")
    return "";
  const { element: c, modifier: n } = _(r, s, {
    element: typeof r == "string" || r == null ? r : r.element,
    modifier: typeof r == "string" || r == null ? s : r.modifier
  }), f = w(t), A = (a) => (f.toKebabCase && (a = N(a)), a), h = `${A(e)}${c ? `${(i = f.prefix) === null || i === void 0 ? void 0 : i.element}${A(c)}` : ""}`, g = [];
  if (typeof n == "object")
    n.forEach((a) => {
      var y;
      g.push(A(a).length ? `${h}${(y = f.prefix) === null || y === void 0 ? void 0 : y.modifier}${A(a)}` : `${h}`);
    });
  else {
    let a = `${h}${n ? `${(o = f.prefix) === null || o === void 0 ? void 0 : o.modifier}${A(n)}` : ""}`;
    g.push(a);
  }
  return T(g, f);
}, F = (e, r = {}) => {
  const s = (t = "", i = "", o = {}) => {
    const c = w(Object.assign(Object.assign({}, r), o));
    if (typeof t != "string" && t !== null && !E(t.show))
      return "";
    let n = [];
    switch (typeof e == "string" ? n = d(e, t, i, Object.assign(Object.assign({}, c), { return: "array" })) : e.forEach((f) => {
      n = [
        ...n,
        ...d(f, t, i, Object.assign(Object.assign({}, c), { return: "array" }))
      ];
    }), c.return) {
      case u.STRING:
        return n.join(" ");
      case u.ARRAY:
        return n;
      default:
      case u.AUTO:
        return n.length == 1 ? n[0] : n;
    }
  };
  return s.bemm = s, s.classes = U(e, r), s;
};
export {
  F as u
};
