import { o as m } from "./rolldown-runtime.js";
import { i as p } from "./vendor/react.js";
import { i as a, r as c, s as T } from "./useRenderElement.js";
import { t as g } from "./useIsoLayoutEffect.js";
var r = /* @__PURE__ */ m(p()), v = /* @__PURE__ */ (function(e) {
  return e.disabled = "data-disabled", e.valid = "data-valid", e.invalid = "data-invalid", e.touched = "data-touched", e.dirty = "data-dirty", e.filled = "data-filled", e.focused = "data-focused", e;
})({}), E = {
  badInput: !1,
  customError: !1,
  patternMismatch: !1,
  rangeOverflow: !1,
  rangeUnderflow: !1,
  stepMismatch: !1,
  tooLong: !1,
  tooShort: !1,
  typeMismatch: !1,
  valid: null,
  valueMissing: !1
}, t = {
  valid: null,
  touched: !1,
  dirty: !1,
  filled: !1,
  focused: !1
}, y = {
  disabled: !1,
  ...t
}, V = { valid(e) {
  return e === null ? null : e ? { [v.valid]: "" } : { [v.invalid]: "" };
} }, I = /* @__PURE__ */ r.createContext({
  invalid: void 0,
  name: void 0,
  validityData: {
    state: E,
    errors: [],
    error: "",
    value: "",
    initialValue: null
  },
  setValidityData: a,
  disabled: void 0,
  touched: t.touched,
  setTouched: a,
  dirty: t.dirty,
  setDirty: a,
  filled: t.filled,
  setFilled: a,
  focused: t.focused,
  setFocused: a,
  validate: () => null,
  validationMode: "onSubmit",
  validationDebounceTime: 0,
  shouldValidateOnChange: () => !1,
  state: y,
  markedDirtyRef: { current: !1 },
  registerFieldControl: a,
  validation: {
    getValidationProps: (e = c) => e,
    getInputValidationProps: (e = c) => e,
    inputRef: { current: null },
    commit: async () => {
    }
  }
});
function h(e = !0) {
  const i = r.useContext(I);
  if (i.setValidityData === a && !e) throw new Error(T(28));
  return i;
}
var _ = /* @__PURE__ */ r.createContext({
  controlId: void 0,
  registerControlId: a,
  labelId: void 0,
  setLabelId: a,
  messageIds: [],
  setMessageIds: a,
  getDescriptionProps: (e) => e
});
function C() {
  return r.useContext(_);
}
function R(e, i) {
  const { enabled: d = !0, getValue: n, id: u, value: f } = i, { registerFieldControl: s } = h(), l = r.useRef(null);
  l.current || (l.current = /* @__PURE__ */ Symbol()), g(() => {
    const o = l.current;
    if (!(!o || !d))
      return s(o, {
        controlRef: e,
        getValue: n,
        id: u,
        value: f
      }), () => {
        s(o, void 0);
      };
  }, [
    e,
    d,
    n,
    u,
    s,
    f
  ]);
}
export {
  h as a,
  V as c,
  I as i,
  _ as n,
  t as o,
  C as r,
  E as s,
  R as t
};

//# sourceMappingURL=useRegisterFieldControl.js.map