"use client";
import * as n from "react";
function d({
  controlled: o,
  default: s,
  name: t,
  state: i = "value"
}) {
  const {
    current: e
  } = n.useRef(o !== void 0), [l, c] = n.useState(s), u = e ? o : l;
  if (process.env.NODE_ENV !== "production") {
    n.useEffect(() => {
      e !== (o !== void 0) && console.error([`Base UI: A component is changing the ${e ? "" : "un"}controlled ${i} state of ${t} to be ${e ? "un" : ""}controlled.`, "Elements should not switch from uncontrolled to controlled (or vice versa).", `Decide between using a controlled or uncontrolled ${t} element for the lifetime of the component.`, "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", "More info: https://fb.me/react-controlled-components"].join(`
`));
    }, [i, t, o]);
    const {
      current: r
    } = n.useRef(s);
    n.useEffect(() => {
      !e && JSON.stringify(r) !== JSON.stringify(s) && console.error([`Base UI: A component is changing the default ${i} state of an uncontrolled ${t} after being initialized. To suppress this warning opt to use a controlled ${t}.`].join(`
`));
    }, [JSON.stringify(s)]);
  }
  const f = n.useCallback((r) => {
    e || c(r);
  }, []);
  return [u, f];
}
export {
  d as u
};
