import d from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import m from "./useEvent.mjs";
import { useLayoutUpdateEffect as g } from "./useLayoutEffect.mjs";
import S from "./useState.mjs";
function o(t) {
  return t !== void 0;
}
function P(t, V) {
  var r = V || {}, n = r.defaultValue, e = r.value, _ = r.onChange, i = r.postState, h = S(function() {
    return o(e) ? e : o(n) ? typeof n == "function" ? n() : n : typeof t == "function" ? t() : t;
  }), s = d(h, 2), f = s[0], v = s[1], a = e !== void 0 ? e : f, C = i ? i(a) : a, y = m(_), E = S([a]), l = d(E, 2), p = l[0], M = l[1];
  g(function() {
    var u = p[0];
    f !== u && y(f, u);
  }, [p]), g(function() {
    o(e) || v(e);
  }, [e]);
  var x = m(function(u, c) {
    v(u, c), M([a], c);
  });
  return [C, x];
}
export {
  P as default
};
