import k from "./index-merge.js";
import { getPath as j, getStyleValue as h } from "./index-style.js";
import { createEmptyBreakpointObject as S, handleBreakpoints as p, removeUnusedBreakpoints as x } from "./index-breakpoints2.js";
import O from "./index-defaultSxConfig.js";
import P from "./index-capitalize.js";
function B(...s) {
  const a = s.reduce((t, i) => t.concat(Object.keys(i)), []), r = new Set(a);
  return s.every((t) => r.size === Object.keys(t).length);
}
function _(s, a) {
  return typeof s == "function" ? s(a) : s;
}
function C() {
  function s(r, t, i, o) {
    const m = {
      [r]: t,
      theme: i
    }, y = o[r];
    if (!y)
      return {
        [r]: t
      };
    const {
      cssProperty: c = r,
      themeKey: f,
      transform: b,
      style: g
    } = y;
    if (t == null)
      return null;
    if (f === "typography" && t === "inherit")
      return {
        [r]: t
      };
    const n = j(i, f) || {};
    return g ? g(m) : p(m, t, (e) => {
      let l = h(n, b, e);
      return e === l && typeof e == "string" && (l = h(n, b, `${r}${e === "default" ? "" : P(e)}`, e)), c === !1 ? l : {
        [c]: l
      };
    });
  }
  function a(r) {
    var t;
    const {
      sx: i,
      theme: o = {}
    } = r || {};
    if (!i)
      return null;
    const m = (t = o.unstable_sxConfig) != null ? t : O;
    function y(c) {
      let f = c;
      if (typeof c == "function")
        f = c(o);
      else if (typeof c != "object")
        return c;
      if (!f)
        return null;
      const b = S(o.breakpoints), g = Object.keys(b);
      let n = b;
      return Object.keys(f).forEach((u) => {
        const e = _(f[u], o);
        if (e != null)
          if (typeof e == "object")
            if (m[u])
              n = k(n, s(u, e, o, m));
            else {
              const l = p({
                theme: o
              }, e, (d) => ({
                [u]: d
              }));
              B(l, e) ? n[u] = a({
                sx: e,
                theme: o
              }) : n = k(n, l);
            }
          else
            n = k(n, s(u, e, o, m));
      }), x(g, n);
    }
    return Array.isArray(i) ? i.map(y) : y(i);
  }
  return a;
}
const $ = C();
$.filterProps = ["sx"];
export {
  $ as default,
  C as unstable_createStyleFunctionSx
};
