import g from "../../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import D from "../../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as C from "react";
import E from "../StyleContext.mjs";
import H from "./useCompatibleInsertionEffect.mjs";
import O from "./useEffectCleanupRegister.mjs";
import V from "./useHMR.mjs";
function U(N, h, y, e, n) {
  var M = C.useContext(E), o = M.cache, i = [N].concat(D(h)), s = i.join("_"), $ = O([s]), b = V(), d = function(u) {
    o.update(i, function(a) {
      var r = a || [void 0, void 0], t = g(r, 2), f = t[0], c = f === void 0 ? 0 : f, l = t[1], _ = l;
      process.env.NODE_ENV !== "production" && l && b && (e == null || e(_, b), _ = null);
      var A = _ || y(), x = [c, A];
      return u ? u(x) : x;
    });
  };
  C.useMemo(
    function() {
      d();
    },
    /* eslint-disable react-hooks/exhaustive-deps */
    [s]
    /* eslint-enable */
  );
  var v = o.get(i);
  process.env.NODE_ENV !== "production" && !v && (d(), v = o.get(i));
  var m = v[1];
  return H(function() {
    n == null || n(m);
  }, function(p) {
    return d(function(u) {
      var a = g(u, 2), r = a[0], t = a[1];
      return p && r === 0 && (n == null || n(m)), [r + 1, t];
    }), function() {
      o.update(i, function(u) {
        var a = u || [], r = g(a, 2), t = r[0], f = t === void 0 ? 0 : t, c = r[1], l = f - 1;
        return l === 0 ? ($(function() {
          (p || !o.get(i)) && (e == null || e(c, !1));
        }), null) : [f - 1, c];
      });
    };
  }, [s]), m;
}
export {
  U as default
};
