import * as a from "react";
import p from "./index-useThemeWithoutDefault2.js";
import h from "./index-getThemeProps.js";
import v from "./index-useEnhancedEffect2.js";
function S(t, u, e, o, i) {
  const [r, f] = a.useState(() => i && e ? e(t).matches : o ? o(t).matches : u);
  return v(() => {
    let c = !0;
    if (!e)
      return;
    const n = e(t), m = () => {
      c && f(n.matches);
    };
    return m(), n.addListener(m), () => {
      c = !1, n.removeListener(m);
    };
  }, [t, e]), r;
}
const d = a.useSyncExternalStore;
function w(t, u, e, o, i) {
  const r = a.useCallback(() => u, [u]), f = a.useMemo(() => {
    if (i && e)
      return () => e(t).matches;
    if (o !== null) {
      const {
        matches: s
      } = o(t);
      return () => s;
    }
    return r;
  }, [r, t, o, i, e]), [c, n] = a.useMemo(() => {
    if (e === null)
      return [r, () => () => {
      }];
    const s = e(t);
    return [() => s.matches, (l) => (s.addListener(l), () => {
      s.removeListener(l);
    })];
  }, [r, e, t]);
  return d(n, c, f);
}
function y(t, u = {}) {
  const e = p(), o = typeof window < "u" && typeof window.matchMedia < "u", {
    defaultMatches: i = !1,
    matchMedia: r = o ? window.matchMedia : null,
    ssrMatchMedia: f = null,
    noSsr: c = !1
  } = h({
    name: "MuiUseMediaQuery",
    props: u,
    theme: e
  });
  process.env.NODE_ENV;
  let n = typeof t == "function" ? t(e) : t;
  n = n.replace(/^@media( ?)/m, "");
  const s = (d !== void 0 ? w : S)(n, i, r, f, c);
  return process.env.NODE_ENV !== "production" && a.useDebugValue({
    query: n,
    match: s
  }), s;
}
export {
  y as default
};
