import { l as R, ai as Y, r as j, a3 as w, u as k, a4 as G, j as s, W as D, O, T as Q, P as _ } from "./index-CsBCemCF.js";
import { memo as P, useRef as V, useState as I, useCallback as u } from "react";
import { u as K } from "./uniqueId-Ct03yls4.js";
import { I as q } from "./InputInstructions-BVDJIGMt.js";
import { u as $ } from "./useBasicWidgetState-KOlq_goV.js";
import { u as tt, a as et, b as it } from "./useUpdateUiValue-DoEkLcX2.js";
import { u as at, T as lt } from "./useTextInputAutoExpand-DWOWjQ4t.js";
const ot = (e, t) => {
  let a = "auto";
  if (e.heightConfig?.useStretch)
    a = "100%";
  else if (e.heightConfig?.pixelHeight && e.heightConfig.pixelHeight > 0) {
    const l = R(t.labelVisibility?.value) === Y.Collapsed ? 2 : 30;
    a = `${e.heightConfig.pixelHeight - l}px`;
  }
  return a;
};
function st() {
  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 nt = /* @__PURE__ */ j("div", process.env.NODE_ENV === "production" ? {
  target: "ezh4s2r0"
} : {
  target: "ezh4s2r0",
  label: "StyledTextAreaContainer"
})(process.env.NODE_ENV === "production" ? {
  name: "kdbhus",
  styles: "height:100%;display:flex;flex-direction:column"
} : {
  name: "kdbhus",
  styles: "height:100%;display:flex;flex-direction:column/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL3N0bGl0ZS9zdGxpdGUvc3RyZWFtbGl0L2Zyb250ZW5kL2xpYi9zcmMvY29tcG9uZW50cy93aWRnZXRzL1RleHRBcmVhL3N0eWxlZC1jb21wb25lbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWtCdUMiLCJmaWxlIjoiL2hvbWUvcnVubmVyL3dvcmsvc3RsaXRlL3N0bGl0ZS9zdHJlYW1saXQvZnJvbnRlbmQvbGliL3NyYy9jb21wb25l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VkLmRpdih7XG4gIGhlaWdodDogXCIxMDAlXCIsXG4gIGRpc3BsYXk6IFwiZmxleFwiLFxuICBmbGV4RGlyZWN0aW9uOiBcImNvbHVtblwiLFxufSlcbiJdfQ== */",
  toString: st
}), y = (e, t) => e.getStringValue(t) ?? t.default ?? null, rt = (e) => e.default ?? null, ut = (e) => e.value ?? null, ct = (e, t, a, l) => {
  t.setStringValue(e, a.value, {
    fromUi: a.fromUi
  }, l);
}, dt = ({
  disabled: e,
  element: t,
  widgetMgr: a,
  fragmentId: l,
  outerElement: c
}) => {
  const m = V(K("text_area_")).current, {
    width: C,
    elementRef: S
  } = w(), [o, d] = I(!1), [Z, W] = I(!1), n = c.heightConfig?.useContent ?? !1, B = c.heightConfig?.useStretch ?? !1, N = ot(c, t), x = V(null), [r, h] = I(() => y(a, t) ?? null), F = u(() => {
    h(t.default ?? null), d(!0);
  }, [t]), [v, g] = $({
    getStateFromWidgetMgr: y,
    getDefaultStateFromProto: rt,
    getCurrStateFromProto: ut,
    updateWidgetMgrState: ct,
    element: t,
    widgetMgr: a,
    fragmentId: l,
    onFormCleared: F
  });
  tt(v, r, h, o);
  const i = k(), {
    height: H,
    maxHeight: L,
    updateScrollHeight: f
  } = at({
    textareaRef: x,
    dependencies: [t.placeholder]
  }), b = u(() => {
    d(!1), g({
      value: r,
      fromUi: !0
    });
  }, [r, g]), X = u(() => {
    o && b(), W(!1);
  }, [o, b]), T = u(() => {
    W(!0);
  }, []), M = u(() => {
    n && f();
  }, [n, f]), z = et({
    formId: t.formId,
    maxChars: t.maxChars,
    setDirty: d,
    setUiValue: h,
    setValueWithSource: g,
    additionalAction: M
  }), E = it(t.formId, b, o, a, l, !0), {
    placeholder: U,
    formId: p
  } = t, J = G({
    formId: p
  }) ? a.allowFormEnterToSubmit(p) : o, A = Z && C > i.breakpoints.hideWidgetDetails;
  return /* @__PURE__ */ s.jsxs(nt, { className: "stTextArea", "data-testid": "stTextArea", ref: S, children: [
    /* @__PURE__ */ s.jsx(D, { label: t.label, disabled: e, labelVisibility: R(t.labelVisibility?.value), htmlFor: m, children: t.help && /* @__PURE__ */ s.jsx(O, { children: /* @__PURE__ */ s.jsx(Q, { content: t.help, placement: _.TOP_RIGHT }) }) }),
    /* @__PURE__ */ s.jsx(lt, { inputRef: n ? x : void 0, value: r ?? "", placeholder: U, onBlur: X, onFocus: T, onChange: z, onKeyDown: E, "aria-label": t.label, disabled: e, id: m, 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: n ? H : N,
          maxHeight: n ? L : "",
          minHeight: i.sizes.largestElementHeight,
          resize: B ? "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
        }
      }
    } }),
    A && /* @__PURE__ */ s.jsx(q, { dirty: o, value: r ?? "", maxLength: t.maxChars, type: "multiline", inForm: G({
      formId: p
    }), allowEnterToSubmit: J })
  ] });
}, xt = P(dt);
export {
  xt as default
};
//# sourceMappingURL=index-DgYLMrUQ.js.map
