import d from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import { useRef as u, useState as S, useEffect as i } from "react";
function w(o) {
  var r = u(o), t = S({}), c = d(t, 2), a = c[1], e = u(null), n = u([]);
  function s(l) {
    n.current.push(l);
    var f = Promise.resolve();
    e.current = f, f.then(function() {
      if (e.current === f) {
        var m = n.current, v = r.current;
        n.current = [], m.forEach(function(p) {
          r.current = p(r.current);
        }), e.current = null, v !== r.current && a({});
      }
    });
  }
  return i(function() {
    return function() {
      e.current = null;
    };
  }, []), [r.current, s];
}
function T(o) {
  var r = u(o || null), t = u();
  function c() {
    window.clearTimeout(t.current);
  }
  function a(n) {
    r.current = n, c(), t.current = window.setTimeout(function() {
      r.current = null, t.current = void 0;
    }, 100);
  }
  function e() {
    return r.current;
  }
  return i(function() {
    return c;
  }, []), [a, e];
}
export {
  w as useLayoutState,
  T as useTimeoutLock
};
