import { o as L } from "./rolldown-runtime.js";
import { i as S } from "./vendor/react.js";
import { t as k } from "./useRenderElement.js";
import { n as B, t as v } from "./useIsoLayoutEffect.js";
import { t as U } from "./shadowDom.js";
import { t as q } from "./owner.js";
import { g as A, t as K } from "./createBaseUIEventDetails.js";
import { t as j } from "./useControlled.js";
import { a as z, c as G, r as H, t as J } from "./useRegisterFieldControl.js";
import { t as O } from "./useLabelableId.js";
var b = /* @__PURE__ */ L(S()), se = /* @__PURE__ */ b.forwardRef(function(s, g) {
  const { render: W, className: X, id: C, name: R, value: a, disabled: F = !1, onValueChange: V, defaultValue: u, autoFocus: l = !1, style: Y, ...y } = s, { state: E, name: D, disabled: P, setTouched: d, setDirty: T, validityData: h, setFocused: o, setFilled: r, validationMode: I, validation: t } = z(), f = P || F, w = D ?? R, x = {
    ...E,
    disabled: f
  }, { labelId: M } = H(), c = O({ id: C });
  v(() => {
    const e = a != null;
    t.inputRef.current?.value || e && a !== "" ? r(!0) : e && a === "" && r(!1);
  }, [
    t.inputRef,
    r,
    a
  ]);
  const n = b.useRef(null);
  v(() => {
    l && n.current === U(q(n.current)) && o(!0);
  }, [l, o]);
  const [N] = j({
    controlled: a,
    default: u,
    name: "FieldControl",
    state: "value"
  }), m = a !== void 0, p = m ? N : void 0, _ = B(() => t.inputRef.current?.value);
  return J(t.inputRef, {
    id: c,
    value: p,
    getValue: _
  }), k("input", s, {
    ref: [g, n],
    state: x,
    props: [
      {
        id: c,
        disabled: f,
        name: w,
        ref: t.inputRef,
        "aria-labelledby": M,
        autoFocus: l,
        ...m ? { value: p } : { defaultValue: u },
        onChange(e) {
          const i = e.currentTarget.value;
          V?.(i, K(A, e.nativeEvent)), T(i !== h.initialValue), r(i !== "");
        },
        onFocus() {
          o(!0);
        },
        onBlur(e) {
          d(!0), o(!1), I === "onBlur" && t.commit(e.currentTarget.value);
        },
        onKeyDown(e) {
          e.currentTarget.tagName === "INPUT" && e.key === "Enter" && (d(!0), t.commit(e.currentTarget.value));
        }
      },
      t.getInputValidationProps(),
      y
    ],
    stateAttributesMapping: G
  });
});
export {
  se as t
};

//# sourceMappingURL=FieldControl.js.map