import { r as a, f as U, m as B, bV as S, j as s, c as _, aI as G, aJ as y, b0 as J, aK as K, ap as N, bW as O } from "./index-6wLGsgHc.js";
import { I as X } from "./uniqueId-DFKpdKNq-JXnJU4sg.js";
import { e as Z } from "./InputInstructions-yTnPUqJo-Bm8iEcOD.js";
import { S as q } from "./useBasicWidgetState-DqA4I-I_-Cy-zNgyc.js";
import { v as Q, a as Y, c as $ } from "./useUpdateUiValue-09I2_X1f-BBTjBVRq.js";
import { p as ee, r as te } from "./useTextInputAutoExpand-Di5cdshf-AADZhTlW.js";
const ie = (t, e) => {
  let l = "auto";
  if (t.heightConfig?.useStretch) l = "100%";
  else if (t.heightConfig?.pixelHeight && t.heightConfig.pixelHeight > 0) {
    const r = y(e.labelVisibility?.value) === O.Collapsed ? 2 : 30;
    l = `${t.heightConfig.pixelHeight - r}px`;
  }
  return l;
}, le = /* @__PURE__ */ _("div", {
  target: "ezh4s2r0"
})({
  name: "kdbhus",
  styles: "height:100%;display:flex;flex-direction:column"
}), W = (t, e) => t.getStringValue(e) ?? e.default ?? null, ae = (t) => t.default ?? null, re = (t) => t.value ?? null, oe = (t, e, l, r) => {
  e.setStringValue(t, l.value, {
    fromUi: l.fromUi
  }, r);
}, se = ({
  disabled: t,
  element: e,
  widgetMgr: l,
  fragmentId: r,
  outerElement: m
}) => {
  const c = a.useRef(X("text_area_")).current, {
    width: I,
    elementRef: T
  } = U(), [o, u] = a.useState(!1), [v, b] = a.useState(!1), d = m.heightConfig?.useContent ?? !1, H = m.heightConfig?.useStretch ?? !1, R = ie(m, e), x = a.useRef(null), [n, h] = a.useState(() => W(l, e) ?? null), V = a.useCallback(() => {
    h(e.default ?? null), u(!0);
  }, [e]), [E, g] = q({
    getStateFromWidgetMgr: W,
    getDefaultStateFromProto: ae,
    getCurrStateFromProto: re,
    updateWidgetMgrState: oe,
    element: e,
    widgetMgr: l,
    fragmentId: r,
    onFormCleared: V
  });
  Q(E, n, h, o);
  const i = B(), {
    height: F,
    maxHeight: j,
    updateScrollHeight: C
  } = ee({
    textareaRef: x,
    dependencies: [e.placeholder]
  }), f = a.useCallback(() => {
    u(!1), g({
      value: n,
      fromUi: !0
    });
  }, [n, g]), z = a.useCallback(() => {
    o && f(), b(!1);
  }, [o, f]), k = a.useCallback(() => {
    b(!0);
  }, []), w = a.useCallback(() => {
    d && C();
  }, [d, C]), L = Y({
    formId: e.formId,
    maxChars: e.maxChars,
    setDirty: u,
    setUiValue: h,
    setValueWithSource: g,
    additionalAction: w
  }), A = $(e.formId, f, o, l, r, !0), {
    placeholder: D,
    formId: p
  } = e, M = S({
    formId: p
  }) ? l.allowFormEnterToSubmit(p) : o, P = v && I > i.breakpoints.hideWidgetDetails;
  return /* @__PURE__ */ s.jsxs(le, {
    className: "stTextArea",
    "data-testid": "stTextArea",
    ref: T,
    children: [/* @__PURE__ */ s.jsx(G, {
      label: e.label,
      disabled: t,
      labelVisibility: y(e.labelVisibility?.value),
      htmlFor: c,
      children: e.help && /* @__PURE__ */ s.jsx(J, {
        children: /* @__PURE__ */ s.jsx(K, {
          content: e.help,
          placement: N.TOP_RIGHT
        })
      })
    }), /* @__PURE__ */ s.jsx(te, {
      inputRef: d ? x : void 0,
      value: n ?? "",
      placeholder: D,
      onBlur: z,
      onFocus: k,
      onChange: L,
      onKeyDown: A,
      "aria-label": e.label,
      disabled: t,
      id: c,
      overrides: {
        Input: {
          style: {
            fontWeight: i.fontWeights.normal,
            lineHeight: i.lineHeights.inputWidget,
            // The default height of the text area is calculated to perfectly fit 3 lines of text.
            height: d ? F : R,
            maxHeight: d ? j : "",
            minHeight: i.sizes.largestElementHeight,
            resize: H ? "none" : "vertical",
            // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
            paddingRight: i.spacing.md,
            paddingLeft: i.spacing.md,
            paddingBottom: i.spacing.md,
            paddingTop: i.spacing.md,
            "::placeholder": {
              color: i.colors.fadedText60
            }
          }
        },
        Root: {
          props: {
            "data-testid": "stTextAreaRootElement"
          },
          style: {
            // Baseweb requires long-hand props, short-hand leads to weird bugs & warnings.
            borderLeftWidth: i.sizes.borderWidth,
            borderRightWidth: i.sizes.borderWidth,
            borderTopWidth: i.sizes.borderWidth,
            borderBottomWidth: i.sizes.borderWidth,
            flexGrow: 1
          }
        }
      }
    }), P && /* @__PURE__ */ s.jsx(Z, {
      dirty: o,
      value: n ?? "",
      maxLength: e.maxChars,
      type: "multiline",
      inForm: S({
        formId: p
      }),
      allowEnterToSubmit: M
    })]
  });
}, fe = a.memo(se);
export {
  fe as default
};
//# sourceMappingURL=index-BPtHoAnG-smGqz1xP.js.map
