import { jsxs, jsx } from "react/jsx-runtime";
import HelperText from "./HelperText.js";
import FormControl from "../../node_modules/@mui/material/FormControl/FormControl.js";
import OutlinedInput from "../../node_modules/@mui/material/OutlinedInput/OutlinedInput.js";
function InputWithIcon({
  label,
  isRequired = false,
  leftIcon,
  leftIconClick,
  rightIcon,
  rightIconClick,
  isError = false,
  isDisabled = false,
  helperText,
  isHelperText = false,
  focusedText,
  htmlFor,
  iconClickOnDisabled = false,
  size = "large",
  className = "",
  ...args
}) {
  const getContainerClass = () => {
    let baseClass = `impact_inputbox_container_with_icons ${size} ${className}`;
    if (isError) {
      baseClass += " input-with-error";
    } else if (isDisabled) {
      baseClass += " input-with-disabled";
      if (iconClickOnDisabled) {
        baseClass += " icon-click-on-disabled";
      }
    }
    return baseClass.trim();
  };
  const handleLeftIconClick = () => {
    if (!isDisabled || iconClickOnDisabled) {
      leftIconClick == null ? void 0 : leftIconClick();
    }
  };
  const handleRightIconClick = () => {
    if (!isDisabled || iconClickOnDisabled) {
      rightIconClick == null ? void 0 : rightIconClick();
    }
  };
  return /* @__PURE__ */ jsxs(FormControl, { className: getContainerClass(), children: [
    label && /* @__PURE__ */ jsxs("label", { htmlFor, children: [
      label,
      " ",
      isRequired && /* @__PURE__ */ jsx("span", { style: { color: "red" }, children: "*" })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "impact-input-wrapper", children: [
      leftIcon && /* @__PURE__ */ jsx(
        "div",
        {
          "aria-label": "Left icon action",
          className: "left-input-icon",
          role: "button",
          tabIndex: isDisabled && !iconClickOnDisabled ? -1 : 0,
          onClick: handleLeftIconClick,
          onKeyDown: (e) => {
            if (e.key === "Enter" || e.key === " ") {
              e.preventDefault();
              handleLeftIconClick();
            }
          },
          children: leftIcon
        }
      ),
      /* @__PURE__ */ jsx(OutlinedInput, { ...args, "aria-invalid": isError, disabled: isDisabled, error: isError }),
      rightIcon && /* @__PURE__ */ jsx(
        "div",
        {
          "aria-label": "Right icon action",
          className: "right-input-icon",
          role: "button",
          tabIndex: isDisabled && !iconClickOnDisabled ? -1 : 0,
          onClick: handleRightIconClick,
          onKeyDown: (e) => {
            if (e.key === "Enter" || e.key === " ") {
              e.preventDefault();
              handleRightIconClick();
            }
          },
          children: rightIcon
        }
      )
    ] }),
    isHelperText && /* @__PURE__ */ jsx(HelperText, { focusedText, helper: helperText })
  ] });
}
export {
  InputWithIcon as default
};
