import d, { useState as R, useRef as s, useEffect as V, useReducer as m, useCallback as _ } from "react";
var l;
const y = typeof document < "u" ? (l = d.useInsertionEffect) !== null && l !== void 0 ? l : d.useLayoutEffect : () => {
};
function w(r, i, c) {
  let [u, $] = R(r || i), n = s(u), f = s(r !== void 0), t = r !== void 0;
  V(() => {
    let e = f.current;
    e !== t && process.env.NODE_ENV !== "production" && console.warn(`WARN: A component changed from ${e ? "controlled" : "uncontrolled"} to ${t ? "controlled" : "uncontrolled"}.`), f.current = t;
  }, [
    t
  ]);
  let a = t ? r : u;
  y(() => {
    n.current = a;
  });
  let [, p] = m(() => ({}), {}), b = _((e, ...E) => {
    let o = typeof e == "function" ? e(n.current) : e;
    Object.is(n.current, o) || (n.current = o, $(o), p(), c?.(o, ...E));
  }, [
    c
  ]);
  return [
    a,
    b
  ];
}
export {
  w as $
};
//# sourceMappingURL=useControlledState-3TGZUXux.es.js.map
