"use client";
import { jsx as y } from "react/jsx-runtime";
import { cn as U } from "../../../lib/utils.js";
import * as f from "react";
import { u as _ } from "../../../useControlled-Sx-_x7Sz.js";
import { u as R } from "../../../useIsoLayoutEffect-DpJo20by.js";
import { o as j } from "../../../owner-rKN292Q9.js";
import { a as A, u as K, b as S, f as $ } from "../../../LabelableContext-Dzw1DWuj.js";
import { u as q } from "../../../useLabelableId-DF_d91GP.js";
import { u as z } from "../../../useRenderElement-DNB2vtF1.js";
import { c as G, n as H } from "../../../createBaseUIEventDetails-CqidROtw.js";
import { a as J } from "../../../element-DSo91iOi.js";
const C = /* @__PURE__ */ f.forwardRef(function(n, a) {
  const {
    render: Q,
    className: W,
    id: N,
    name: h,
    value: r,
    disabled: w = !1,
    onValueChange: F,
    defaultValue: c,
    autoFocus: s = !1,
    ...V
  } = n, {
    state: I,
    name: D,
    disabled: P,
    setTouched: m,
    setDirty: T,
    validityData: k,
    setFocused: i,
    setFilled: o,
    validationMode: L,
    validation: t
  } = A(), p = P || w, b = D ?? h, M = {
    ...I,
    disabled: p
  }, {
    labelId: B
  } = K(), v = q({
    id: N
  });
  R(() => {
    const e = r != null;
    t.inputRef.current?.value || e && r !== "" ? o(!0) : e && r === "" && o(!1);
  }, [t.inputRef, o, r]);
  const u = f.useRef(null);
  R(() => {
    s && u.current === J(j(u.current)) && i(!0);
  }, [s, i]);
  const [O] = _({
    controlled: r,
    default: c,
    name: "FieldControl",
    state: "value"
  }), g = r !== void 0, x = g ? O : void 0;
  return S({
    id: v,
    name: b,
    commit: t.commit,
    value: x,
    getValue: () => t.inputRef.current?.value,
    controlRef: t.inputRef
  }), z("input", n, {
    ref: [a, u],
    state: M,
    props: [{
      id: v,
      disabled: p,
      name: b,
      ref: t.inputRef,
      "aria-labelledby": B,
      autoFocus: s,
      ...g ? {
        value: x
      } : {
        defaultValue: c
      },
      onChange(e) {
        const d = e.currentTarget.value;
        F?.(d, G(H, e.nativeEvent)), T(d !== k.initialValue), o(d !== "");
      },
      onFocus() {
        i(!0);
      },
      onBlur(e) {
        m(!0), i(!1), L === "onBlur" && t.commit(e.currentTarget.value);
      },
      onKeyDown(e) {
        e.currentTarget.tagName === "INPUT" && e.key === "Enter" && (m(!0), t.commit(e.currentTarget.value));
      }
    }, t.getInputValidationProps(), V],
    stateAttributesMapping: $
  });
});
process.env.NODE_ENV !== "production" && (C.displayName = "FieldControl");
const E = /* @__PURE__ */ f.forwardRef(function(n, a) {
  return /* @__PURE__ */ y(C, {
    ref: a,
    ...n
  });
});
process.env.NODE_ENV !== "production" && (E.displayName = "Input");
function se({ className: l, type: n, ...a }) {
  return /* @__PURE__ */ y(
    E,
    {
      className: U(
        "h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs outline-none transition-[color,box-shadow] file:inline-flex file:h-7 file:border-0 file:bg-transparent file:font-medium file:text-foreground file:text-sm placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
        l
      ),
      "data-slot": "input",
      type: n,
      ...a
    }
  );
}
export {
  se as Input
};
