import d from "react";
import "../../../@ant-design/cssinjs/es/extractStyle.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useCacheToken.mjs";
import "../../../@ant-design/cssinjs/es/StyleContext.mjs";
import "../../../@ant-design/cssinjs/es/theme/createTheme.mjs";
import "../../../rc-util/es/warning.mjs";
import "../../../@ant-design/cssinjs/es/theme/ThemeCache.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useCompatibleInsertionEffect.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useEffectCleanupRegister.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useHMR.mjs";
import "../../../@ant-design/cssinjs/es/transformers/legacyLogicalProperties.mjs";
import h from "../theme/useToken.mjs";
const m = ["xxl", "xl", "lg", "md", "sm", "xs"], u = (n) => ({
  xs: `(max-width: ${n.screenXSMax}px)`,
  sm: `(min-width: ${n.screenSM}px)`,
  md: `(min-width: ${n.screenMD}px)`,
  lg: `(min-width: ${n.screenLG}px)`,
  xl: `(min-width: ${n.screenXL}px)`,
  xxl: `(min-width: ${n.screenXXL}px)`
}), x = (n) => {
  const e = n, t = [].concat(m).reverse();
  return t.forEach((c, a) => {
    const s = c.toUpperCase(), i = `screen${s}Min`, r = `screen${s}`;
    if (!(e[i] <= e[r]))
      throw new Error(`${i}<=${r} fails : !(${e[i]}<=${e[r]})`);
    if (a < t.length - 1) {
      const o = `screen${s}Max`;
      if (!(e[r] <= e[o]))
        throw new Error(`${r}<=${o} fails : !(${e[r]}<=${e[o]})`);
      const p = `screen${t[a + 1].toUpperCase()}Min`;
      if (!(e[o] <= e[p]))
        throw new Error(`${o}<=${p} fails : !(${e[o]}<=${e[p]})`);
    }
  }), n;
};
function L() {
  const [, n] = h(), e = u(x(n));
  return d.useMemo(() => {
    const t = /* @__PURE__ */ new Map();
    let c = -1, a = {};
    return {
      matchHandlers: {},
      dispatch(s) {
        return a = s, t.forEach((i) => i(a)), t.size >= 1;
      },
      subscribe(s) {
        return t.size || this.register(), c += 1, t.set(c, s), s(a), c;
      },
      unsubscribe(s) {
        t.delete(s), t.size || this.unregister();
      },
      unregister() {
        Object.keys(e).forEach((s) => {
          const i = e[s], r = this.matchHandlers[i];
          r == null || r.mql.removeListener(r == null ? void 0 : r.listener);
        }), t.clear();
      },
      register() {
        Object.keys(e).forEach((s) => {
          const i = e[s], r = (l) => {
            let {
              matches: p
            } = l;
            this.dispatch(Object.assign(Object.assign({}, a), {
              [s]: p
            }));
          }, o = window.matchMedia(i);
          o.addListener(r), this.matchHandlers[i] = {
            mql: o,
            listener: r
          }, r(o);
        });
      },
      responsiveMap: e
    };
  }, [n]);
}
const O = (n, e) => {
  if (e && typeof e == "object")
    for (let t = 0; t < m.length; t++) {
      const c = m[t];
      if (n[c] && e[c] !== void 0)
        return e[c];
    }
};
export {
  L as default,
  O as matchScreen,
  m as responsiveArray
};
