import { r as i, f as P, m as D, bV as W, j as l, c as k, aI as H, aJ as U, b0 as $, aK as B, ap as M, F as _, bY as G } from "./index-6wLGsgHc.js";
import { I as K } from "./uniqueId-DFKpdKNq-JXnJU4sg.js";
import { e as O } from "./InputInstructions-yTnPUqJo-Bm8iEcOD.js";
import { S as Y } from "./useBasicWidgetState-DqA4I-I_-Cy-zNgyc.js";
import { v as A, a as J, c as N } from "./useUpdateUiValue-09I2_X1f-BBTjBVRq.js";
import { a as Z } from "./input-BDVeiWWL-DJbU40h6.js";
const q = /* @__PURE__ */ k("div", {
  target: "e11y4ecf0"
})({
  name: "bjn8wh",
  styles: "position:relative"
});
function Q({
  disabled: a,
  element: e,
  widgetMgr: s,
  fragmentId: d
}) {
  const [o, u] = i.useState(() => S(s, e) ?? null), {
    width: I,
    elementRef: T
  } = P(), [r, p] = i.useState(!1), y = i.useCallback(() => {
    u(e.default ?? null), p(!0);
  }, [e.default]), [j, c] = Y({
    getStateFromWidgetMgr: S,
    getDefaultStateFromProto: X,
    getCurrStateFromProto: ee,
    updateWidgetMgrState: te,
    element: e,
    widgetMgr: s,
    fragmentId: d,
    onFormCleared: y
  });
  A(j, o, u, r);
  const [C, f] = i.useState(!1), t = D(), [h] = i.useState(() => K("text_input_")), {
    placeholder: F,
    formId: n,
    icon: m,
    maxChars: b
  } = e, g = i.useCallback(() => {
    p(!1), c({
      value: o,
      fromUi: !0
    });
  }, [o, c]), V = W({
    formId: n
  }) ? s.allowFormEnterToSubmit(n) : r, v = C && I > t.breakpoints.hideWidgetDetails, E = i.useCallback(() => {
    r && g(), f(!1);
  }, [r, g]), R = i.useCallback(() => {
    f(!0);
  }, []), z = J({
    formId: n,
    maxChars: b,
    setDirty: p,
    setUiValue: u,
    setValueWithSource: c
  }), L = N(n, g, r, s, d), x = m?.startsWith(":material"), w = x ? "lg" : "base";
  return /* @__PURE__ */ l.jsxs(q, {
    className: "stTextInput",
    "data-testid": "stTextInput",
    ref: T,
    children: [/* @__PURE__ */ l.jsx(H, {
      label: e.label,
      disabled: a,
      labelVisibility: U(e.labelVisibility?.value),
      htmlFor: h,
      children: e.help && /* @__PURE__ */ l.jsx($, {
        children: /* @__PURE__ */ l.jsx(B, {
          content: e.help,
          placement: M.TOP_RIGHT
        })
      })
    }), /* @__PURE__ */ l.jsx(Z, {
      value: o ?? "",
      placeholder: F,
      onBlur: E,
      onFocus: R,
      onChange: z,
      onKeyPress: L,
      "aria-label": e.label,
      disabled: a,
      id: h,
      type: ae(e),
      autoComplete: e.autocomplete,
      startEnhancer: m && /* @__PURE__ */ l.jsx(_, {
        "data-testid": "stTextInputIcon",
        iconValue: m,
        size: w
      }),
      overrides: {
        Input: {
          style: {
            fontWeight: t.fontWeights.normal,
            // Issue: https://github.com/streamlit/streamlit/issues/2495
            // The input won't shrink in Firefox,
            // unless the line below is provided.
            // See https://stackoverflow.com/a/33811151
            minWidth: 0,
            lineHeight: t.lineHeights.inputWidget,
            // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
            paddingRight: t.spacing.sm,
            paddingLeft: t.spacing.md,
            paddingBottom: t.spacing.sm,
            paddingTop: t.spacing.sm,
            "::placeholder": {
              color: t.colors.fadedText60
            }
          }
        },
        Root: {
          props: {
            "data-testid": "stTextInputRootElement"
          },
          style: {
            height: t.sizes.minElementHeight,
            // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
            borderLeftWidth: t.sizes.borderWidth,
            borderRightWidth: t.sizes.borderWidth,
            borderTopWidth: t.sizes.borderWidth,
            borderBottomWidth: t.sizes.borderWidth,
            paddingLeft: m ? t.spacing.sm : 0
          }
        },
        StartEnhancer: {
          style: {
            paddingLeft: 0,
            paddingRight: 0,
            // Keeps emoji icons from being cut off on the right
            minWidth: t.iconSizes.lg,
            // Material icons color changed as inactionable
            color: x ? t.colors.fadedText60 : "inherit"
          }
        }
      }
    }), v && /* @__PURE__ */ l.jsx(O, {
      dirty: r,
      value: o ?? "",
      maxLength: b,
      inForm: W({
        formId: n
      }),
      allowEnterToSubmit: V
    })]
  });
}
function S(a, e) {
  return a.getStringValue(e) ?? null;
}
function X(a) {
  return a.default ?? null;
}
function ee(a) {
  return a.value ?? null;
}
function te(a, e, s, d) {
  e.setStringValue(a, s.value, {
    fromUi: s.fromUi
  }, d);
}
function ae(a) {
  return a.type === G.Type.PASSWORD ? "password" : "text";
}
const de = i.memo(Q);
export {
  de as default
};
//# sourceMappingURL=index-CTwTw5ms-CpwZe9T1.js.map
