import y, { useContext as U } from "react";
import "../../../../@ant-design/cssinjs/es/extractStyle.mjs";
import "../../../../@ant-design/cssinjs/es/hooks/useCacheToken.mjs";
import Z from "../../../../@ant-design/cssinjs/es/hooks/useCSSVarRegister.mjs";
import V from "../../../../@ant-design/cssinjs/es/hooks/useStyleRegister.mjs";
import { warningOnce as H } from "../../../../rc-util/es/warning.mjs";
import "../../../../@ant-design/cssinjs/es/StyleContext.mjs";
import "../../../../@ant-design/cssinjs/es/theme/createTheme.mjs";
import "../../../../@ant-design/cssinjs/es/theme/ThemeCache.mjs";
import "../../../../@ant-design/cssinjs/es/transformers/legacyLogicalProperties.mjs";
import { token2CSSVar as K } from "../../../../@ant-design/cssinjs/es/util/css-variables.mjs";
import "../../../../rc-util/es/hooks/useLayoutEffect.mjs";
import "../../../../rc-util/node_modules/react-is/index.mjs";
import { ConfigContext as M } from "../../config-provider/context.mjs";
import { genLinkStyle as B, genCommonStyle as F } from "../../style/index.mjs";
import C, { unitless as L, ignore as N } from "../useToken.mjs";
import q from "./calc/index.mjs";
import G from "./maxmin.mjs";
import J, { merge as b } from "./statistic.mjs";
import Q from "./useResetIconStyle.mjs";
const $ = (t, l, n) => {
  var e;
  return typeof n == "function" ? n(b(l, (e = l[t]) !== null && e !== void 0 ? e : {})) : n ?? {};
}, E = (t, l, n, e) => {
  const r = Object.assign({}, l[t]);
  if (e != null && e.deprecatedTokens) {
    const {
      deprecatedTokens: c
    } = e;
    c.forEach((a) => {
      let [d, o] = a;
      var i;
      process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && H(!(r != null && r[d]), `The token '${String(d)}' of ${t} had deprecated, use '${String(o)}' instead.`), (r != null && r[d] || r != null && r[o]) && ((i = r[o]) !== null && i !== void 0 || (r[o] = r == null ? void 0 : r[d]));
    });
  }
  let s = Object.assign(Object.assign({}, n), r);
  return e != null && e.format && (s = e.format(s)), Object.keys(s).forEach((c) => {
    s[c] === l[c] && delete s[c];
  }), s;
}, W = (t, l) => `${[l, t.replace(/([A-Z]+)([A-Z][a-z]+)/g, "$1-$2").replace(/([a-z])([A-Z])/g, "$1-$2")].filter(Boolean).join("-")}`;
function x(t, l, n) {
  let e = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
  const r = Array.isArray(t) ? t : [t, t], [s] = r, c = r.join("-");
  return (a) => {
    const [d, o, i, u, m] = C(), {
      getPrefixCls: S,
      iconPrefixCls: f,
      csp: g
    } = U(M), v = S(), k = m ? "css" : "js", A = q(k), {
      max: _,
      min: R
    } = G(k), O = {
      theme: d,
      token: u,
      hashId: i,
      nonce: () => g == null ? void 0 : g.nonce,
      clientOnly: e.clientOnly,
      // antd is always at top of styles
      order: e.order || -999
    };
    return V(Object.assign(Object.assign({}, O), {
      clientOnly: !1,
      path: ["Shared", v]
    }), () => [{
      // Link
      "&": B(u)
    }]), Q(f, g), [V(Object.assign(Object.assign({}, O), {
      path: [c, a, f]
    }), () => {
      if (e.injectStyle === !1)
        return [];
      const {
        token: w,
        flush: P
      } = J(u), p = $(s, o, n), I = `.${a}`, h = E(s, o, p, {
        deprecatedTokens: e.deprecatedTokens,
        format: e.format
      });
      m && Object.keys(p).forEach((T) => {
        p[T] = `var(${K(T, W(s, m.prefix))})`;
      });
      const j = b(w, {
        componentCls: I,
        prefixCls: a,
        iconCls: `.${f}`,
        antCls: `.${v}`,
        calc: A,
        max: _,
        min: R
      }, m ? p : h), z = l(j, {
        hashId: i,
        prefixCls: a,
        rootPrefixCls: v,
        iconPrefixCls: f
      });
      return P(s, h), [e.resetStyle === !1 ? null : F(j, a), z];
    }), i];
  };
}
const Ce = (t, l, n, e) => {
  const r = x(t, l, n, Object.assign({
    resetStyle: !1,
    // Sub Style should default after root one
    order: -998
  }, e)), s = (c) => {
    let {
      prefixCls: a
    } = c;
    return r(a), null;
  };
  return process.env.NODE_ENV !== "production" && (s.displayName = `SubStyle_${Array.isArray(t) ? t.join(".") : t}`), s;
}, X = (t, l, n) => {
  function e(o) {
    return `${t}${o.slice(0, 1).toUpperCase()}${o.slice(1)}`;
  }
  const {
    unitless: r = {},
    injectStyle: s = !0
  } = n ?? {}, c = {
    [e("zIndexPopup")]: !0
  };
  Object.keys(r).forEach((o) => {
    c[e(o)] = r[o];
  });
  const a = (o) => {
    let {
      rootCls: i,
      cssVar: u
    } = o;
    const [, m] = C();
    return Z({
      path: [t],
      prefix: u.prefix,
      key: u == null ? void 0 : u.key,
      unitless: Object.assign(Object.assign({}, L), c),
      ignore: N,
      token: m,
      scope: i
    }, () => {
      const S = $(t, m, l), f = E(t, m, S, {
        format: n == null ? void 0 : n.format,
        deprecatedTokens: n == null ? void 0 : n.deprecatedTokens
      });
      return Object.keys(S).forEach((g) => {
        f[e(g)] = f[g], delete f[g];
      }), f;
    }), null;
  };
  return (o) => {
    const [, , , , i] = C();
    return [(u) => s && i ? /* @__PURE__ */ y.createElement(y.Fragment, null, /* @__PURE__ */ y.createElement(a, {
      rootCls: o,
      cssVar: i,
      component: t
    }), u) : u, i == null ? void 0 : i.key];
  };
}, ke = (t, l, n, e) => {
  const r = x(t, l, n, e), s = X(Array.isArray(t) ? t[0] : t, n, e);
  return function(c) {
    let a = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : c;
    const [, d] = r(c), [o, i] = s(a);
    return [o, d, i];
  };
};
export {
  x as default,
  ke as genStyleHooks,
  Ce as genSubStyleComponent
};
