import { jsx, jsxs } from "react/jsx-runtime";
import { useState } from "react";
/* empty css                     */
import FormControl from "../../node_modules/@mui/material/FormControl/FormControl.js";
import { TextareaAutosize } from "../../node_modules/@mui/base/TextareaAutosize/TextareaAutosize.js";
function TextArea({
  label,
  maxRows = 5,
  placeholder,
  defaultValue,
  value,
  onChange,
  secondaryLabel,
  isDisabled,
  isRequired,
  characterLimit,
  isError = false,
  isSuccess = false,
  isWarning = false,
  width = "240px",
  height = "100px",
  className,
  "data-testid": dataTestId,
  onBlur,
  onFocus,
  ...restProps
}) {
  const [isFocused, setIsFocused] = useState(false);
  const currentValue = value ?? defaultValue ?? "";
  const displayValue = typeof value === "string" ? value : void 0;
  const displayDefaultValue = typeof value !== "string" ? defaultValue : void 0;
  const containerClass = [
    "impact_textarea_container",
    isDisabled && "impact_textarea_disabled",
    isError && "impact_textarea_error",
    isSuccess && "impact_textarea_success",
    isWarning && "impact_textarea_warning"
  ].filter(Boolean).join(" ");
  const textareaStyle = {
    minWidth: width,
    minHeight: height,
    width,
    height
  };
  const showBottomRow = Boolean(secondaryLabel ?? characterLimit);
  const renderTextarea = () => /* @__PURE__ */ jsx(
    TextareaAutosize,
    {
      "aria-label": label ?? "textarea",
      "data-testid": dataTestId ? `${dataTestId}-input` : void 0,
      defaultValue: displayDefaultValue,
      disabled: isDisabled,
      maxRows,
      placeholder: isFocused ? "" : placeholder,
      style: textareaStyle,
      value: displayValue,
      onChange,
      ...restProps,
      onBlur: (e) => {
        setIsFocused(false);
        onBlur == null ? void 0 : onBlur(e);
      },
      onFocus: (e) => {
        setIsFocused(true);
        onFocus == null ? void 0 : onFocus(e);
      }
    }
  );
  if (!showBottomRow) {
    return /* @__PURE__ */ jsx(
      FormControl,
      {
        className: `impact_textarea_layout ${className ?? ""}`.trim(),
        "data-testid": dataTestId,
        children: /* @__PURE__ */ jsxs("div", { className: containerClass, children: [
          /* @__PURE__ */ jsxs("label", { className: "impact_textarea_label", children: [
            label,
            " ",
            isRequired && /* @__PURE__ */ jsx("span", { style: { color: "red" }, children: "*" })
          ] }),
          /* @__PURE__ */ jsx("div", { className: "impact_textarea", children: renderTextarea() })
        ] })
      }
    );
  }
  const currentLength = String(currentValue).length;
  return /* @__PURE__ */ jsx(
    FormControl,
    {
      className: `impact_textarea_layout ${className ?? ""}`.trim(),
      "data-testid": dataTestId,
      children: /* @__PURE__ */ jsxs("div", { className: containerClass, children: [
        /* @__PURE__ */ jsxs("label", { className: "impact_textarea_label", children: [
          label,
          " ",
          isRequired && /* @__PURE__ */ jsx("span", { style: { color: "red" }, children: "*" })
        ] }),
        /* @__PURE__ */ jsx("div", { className: "impact_textarea", children: renderTextarea() }),
        /* @__PURE__ */ jsxs("div", { className: "impact_textarea_btm_container", children: [
          /* @__PURE__ */ jsx("div", { className: "left_secondary_label_container", children: secondaryLabel ?? "" }),
          characterLimit != null && /* @__PURE__ */ jsxs("div", { className: "right_numeric_container", children: [
            currentLength,
            "/",
            characterLimit
          ] })
        ] })
      ] })
    }
  );
}
TextArea.displayName = "TextArea";
export {
  TextArea
};
