const g = (t) => t.split(" ").map((n) => n.trim()).filter(Boolean), a = (t, n, e) => ({
  kind: t,
  axis: n,
  value: e
}), h = (t) => {
  const n = t.match(/^(margin|padding)(?:-(x|y|top|right|bottom|left))?-(.+)$/);
  if (!n)
    return null;
  const e = n[1], f = n[2] ?? "all", u = n[3];
  return { kind: e, axis: f, value: u };
}, $ = ({ kind: t, axis: n, value: e }) => n === "all" ? `${t}-${e}` : `${t}-${n}-${e}`, y = (t, n) => n === "all" || t === "all" || t === n || t === "x" && (n === "left" || n === "right") || t === "y" && (n === "top" || n === "bottom") || n === "x" && (t === "left" || t === "right") || n === "y" && (t === "top" || t === "bottom"), m = (t) => {
  if (t.startsWith("margin-")) {
    const [n, e] = t.split("-");
    return e === "x" || e === "y" || e === "top" || e === "right" || e === "bottom" || e === "left" ? `${n}-${e}` : n;
  }
  if (t.startsWith("padding-")) {
    const [n, e] = t.split("-");
    return e === "x" || e === "y" || e === "top" || e === "right" || e === "bottom" || e === "left" ? `${n}-${e}` : n;
  }
  return t.startsWith("text-size-") ? "text-size" : t.startsWith("text-color-") ? "text-color" : t.startsWith("bg-") ? "bg" : t === "rounded" || t.startsWith("rounded-") ? "rounded" : t === "border" || t.startsWith("border-") ? "border" : t;
}, k = (t, n) => {
  if (!n || n.trim() === "")
    return t;
  const e = g(n), f = new Set(e.map((r) => m(r))), u = e.map(h).filter(Boolean), c = {
    margin: u.filter((r) => r.kind === "margin").map((r) => r.axis),
    padding: u.filter((r) => r.kind === "padding").map((r) => r.axis)
  }, b = g(t), l = [], p = b.filter((r) => {
    const i = h(r);
    return i ? c[i.kind].some((S) => y(i.axis, S)) ? (l.push(i), !1) : !0 : !f.has(m(r));
  }), x = l.filter((r) => r.axis === "x" || r.axis === "y").flatMap((r) => {
    const i = c[r.kind];
    if (i.includes("all") || i.includes(r.axis))
      return [];
    if (r.axis === "x") {
      const o = i.includes("left"), s = i.includes("right");
      if (o && !s)
        return [a(r.kind, "right", r.value)];
      if (s && !o)
        return [a(r.kind, "left", r.value)];
    }
    if (r.axis === "y") {
      const o = i.includes("top"), s = i.includes("bottom");
      if (o && !s)
        return [a(r.kind, "bottom", r.value)];
      if (s && !o)
        return [a(r.kind, "top", r.value)];
    }
    return [];
  }).map($), d = /* @__PURE__ */ new Set([...p, ...e]), T = x.filter((r) => d.has(r) ? !1 : (d.add(r), !0));
  return [...p, ...T, ...e].join(" ");
};
export {
  k as mergeClassNameOverrides
};
//# sourceMappingURL=mergeClassNameOverrides.js.map
