import { useState as V, useRef as $, useEffect as E, useCallback as N } from "react";
function h(o, a, l) {
  let [p, s] = V(o || a), i = $(o !== void 0), e = o !== void 0;
  E(() => {
    let t = i.current;
    t !== e && process.env.NODE_ENV !== "production" && console.warn(`WARN: A component changed from ${t ? "controlled" : "uncontrolled"} to ${e ? "controlled" : "uncontrolled"}.`), i.current = e;
  }, [
    e
  ]);
  let n = e ? o : p, b = N((t, ...u) => {
    let f = (r, ...c) => {
      l && (Object.is(n, r) || l(r, ...c)), e || (n = r);
    };
    typeof t == "function" ? (process.env.NODE_ENV !== "production" && console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"), s((c, ...m) => {
      let d = t(e ? n : c, ...m);
      return f(d, ...u), e ? c : d;
    })) : (e || s(t), f(t, ...u));
  }, [
    e,
    n,
    l
  ]);
  return [
    n,
    b
  ];
}
export {
  h as $
};
//# sourceMappingURL=useControlledState-u436Wbp1.es.js.map
