import { r as v, a3 as E, u as C, a4 as y, j as s, W as J, l as X, O as H, T as N, P as Q, x as k, a5 as D } from "./index-CsBCemCF.js";
import { memo as A, useState as r, useCallback as d } from "react";
import { u as K } from "./uniqueId-Ct03yls4.js";
import { I as M } from "./InputInstructions-BVDJIGMt.js";
import { u as O } from "./useBasicWidgetState-KOlq_goV.js";
import { u as _, a as w, b as P } from "./useUpdateUiValue-DoEkLcX2.js";
import { I as q } from "./input-BXGQ9mRm.js";
function $() {
  return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop).";
}
const tt = /* @__PURE__ */ v("div", process.env.NODE_ENV === "production" ? {
  target: "e11y4ecf0"
} : {
  target: "e11y4ecf0",
  label: "StyledTextInput"
})(process.env.NODE_ENV === "production" ? {
  name: "bjn8wh",
  styles: "position:relative"
} : {
  name: "bjn8wh",
  styles: "position:relative/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL3N0bGl0ZS9zdGxpdGUvc3RyZWFtbGl0L2Zyb250ZW5kL2xpYi9zcmMvY29tcG9uZW50cy93aWRnZXRzL1RleHRJbnB1dC9zdHlsZWQtY29tcG9uZW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFrQnlDIiwiZmlsZSI6Ii9ob21lL3J1bm5lci93b3JrL3N0bGl0ZS9zdGxpdGUvc3RyZWFtbGl0L2Zyb250ZW5kL2xpYi9zcmMvY29tcG9uZW50cy93aWRnZXRzL1RleHRJbnB1dC9zdHlsZWQtY29tcG9uZW50cy50cyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQ29weXJpZ2h0IChjKSBTdHJlYW1saXQgSW5jLiAoMjAxOC0yMDIyKSBTbm93Zmxha2UgSW5jLiAoMjAyMi0yMDI1KVxuICpcbiAqIExpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSBcIkxpY2Vuc2VcIik7XG4gKiB5b3UgbWF5IG5vdCB1c2UgdGhpcyBmaWxlIGV4Y2VwdCBpbiBjb21wbGlhbmNlIHdpdGggdGhlIExpY2Vuc2UuXG4gKiBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXRcbiAqXG4gKiAgICAgaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2Vuc2VzL0xJQ0VOU0UtMi4wXG4gKlxuICogVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZVxuICogZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gXCJBUyBJU1wiIEJBU0lTLFxuICogV0lUSE9VVCBXQVJSQU5USUVTIE9SIENPTkRJVElPTlMgT0YgQU5ZIEtJTkQsIGVpdGhlciBleHByZXNzIG9yIGltcGxpZWQuXG4gKiBTZWUgdGhlIExpY2Vuc2UgZm9yIHRoZSBzcGVjaWZpYyBsYW5ndWFnZSBnb3Zlcm5pbmcgcGVybWlzc2lvbnMgYW5kXG4gKiBsaW1pdGF0aW9ucyB1bmRlciB0aGUgTGljZW5zZS5cbiAqL1xuXG5pbXBvcnQgc3R5bGVkIGZyb20gXCJAZW1vdGlvbi9zdHlsZWRcIlxuXG5leHBvcnQgY29uc3QgU3R5bGVkVGV4dElucHV0ID0gc3R5bGVkLmRpdmBcbiAgcG9zaXRpb246IHJlbGF0aXZlO1xuYFxuIl19 */",
  toString: $
});
function et({
  disabled: i,
  element: t,
  widgetMgr: o,
  fragmentId: c
}) {
  const [n, p] = r(() => V(o, t) ?? null), {
    width: Z,
    elementRef: x
  } = E(), [a, g] = r(!1), f = d(() => {
    p(t.default ?? null), g(!0);
  }, [t.default]), [S, b] = O({
    getStateFromWidgetMgr: V,
    getDefaultStateFromProto: it,
    getCurrStateFromProto: ot,
    updateWidgetMgrState: st,
    element: t,
    widgetMgr: o,
    fragmentId: c,
    onFormCleared: f
  });
  _(S, n, p, a);
  const [B, m] = r(!1), e = C(), [G] = r(() => K("text_input_")), {
    placeholder: R,
    formId: l,
    icon: u,
    maxChars: W
  } = t, I = d(() => {
    g(!1), b({
      value: n,
      fromUi: !0
    });
  }, [n, b]), T = y({
    formId: l
  }) ? o.allowFormEnterToSubmit(l) : a, U = B && Z > e.breakpoints.hideWidgetDetails, z = d(() => {
    a && I(), m(!1);
  }, [a, I]), j = d(() => {
    m(!0);
  }, []), F = w({
    formId: l,
    maxChars: W,
    setDirty: g,
    setUiValue: p,
    setValueWithSource: b
  }), L = P(l, I, a, o, c), h = u?.startsWith(":material"), Y = h ? "lg" : "base";
  return /* @__PURE__ */ s.jsxs(tt, { className: "stTextInput", "data-testid": "stTextInput", ref: x, children: [
    /* @__PURE__ */ s.jsx(J, { label: t.label, disabled: i, labelVisibility: X(t.labelVisibility?.value), htmlFor: G, children: t.help && /* @__PURE__ */ s.jsx(H, { children: /* @__PURE__ */ s.jsx(N, { content: t.help, placement: Q.TOP_RIGHT }) }) }),
    /* @__PURE__ */ s.jsx(q, { value: n ?? "", placeholder: R, onBlur: z, onFocus: j, onChange: F, onKeyPress: L, "aria-label": t.label, disabled: i, id: G, type: at(t), autoComplete: t.autocomplete, startEnhancer: u && /* @__PURE__ */ s.jsx(k, { "data-testid": "stTextInputIcon", iconValue: u, size: Y }), overrides: {
      Input: {
        style: {
          fontWeight: e.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: e.lineHeights.inputWidget,
          // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
          paddingRight: e.spacing.sm,
          paddingLeft: e.spacing.md,
          paddingBottom: e.spacing.sm,
          paddingTop: e.spacing.sm,
          "::placeholder": {
            color: e.colors.fadedText60
          }
        }
      },
      Root: {
        props: {
          "data-testid": "stTextInputRootElement"
        },
        style: {
          height: e.sizes.minElementHeight,
          // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
          borderLeftWidth: e.sizes.borderWidth,
          borderRightWidth: e.sizes.borderWidth,
          borderTopWidth: e.sizes.borderWidth,
          borderBottomWidth: e.sizes.borderWidth,
          paddingLeft: u ? e.spacing.sm : 0
        }
      },
      StartEnhancer: {
        style: {
          paddingLeft: 0,
          paddingRight: 0,
          // Keeps emoji icons from being cut off on the right
          minWidth: e.iconSizes.lg,
          // Material icons color changed as inactionable
          color: h ? e.colors.fadedText60 : "inherit"
        }
      }
    } }),
    U && /* @__PURE__ */ s.jsx(M, { dirty: a, value: n ?? "", maxLength: W, inForm: y({
      formId: l
    }), allowEnterToSubmit: T })
  ] });
}
function V(i, t) {
  return i.getStringValue(t) ?? null;
}
function it(i) {
  return i.default ?? null;
}
function ot(i) {
  return i.value ?? null;
}
function st(i, t, o, c) {
  t.setStringValue(i, o.value, {
    fromUi: o.fromUi
  }, c);
}
function at(i) {
  return i.type === D.Type.PASSWORD ? "password" : "text";
}
const gt = A(et);
export {
  gt as default
};
//# sourceMappingURL=index-CmMya3Pz.js.map
