"use client";
import { jsxs as l, jsx as t } from "react/jsx-runtime";
import { useState as I } from "react";
import e from "../../components/TextInput/textInput.module.css";
import { cn as c } from "../../utils/cn/cn.es.js";
import { Button as E } from "../Button/Button.es.js";
import { Icon as w } from "../Icon/Icon.es.js";
import { EIconName as z } from "../Icon/constants.es.js";
import { Typography as B } from "../Typography/Typography.es.js";
const q = ({
  placeholder: v,
  variant: s = "primary",
  handleChange: i,
  handleKeyDown: m,
  disabled: u = !1,
  buttonText: x = "SUBMIT",
  onButtonClick: r,
  error: a = !1,
  errorText: p,
  active: f = !1,
  value: d,
  label: y,
  type: b = "button",
  showButton: T = !1
}) => {
  const [V, N] = I(!1), [g, F] = I(""), h = typeof d == "string" && typeof i == "function", o = h ? d : g, S = (n) => {
    h ? i && i(n) : F(n.target.value);
  }, _ = () => {
    r && r(o || "");
  }, j = (n) => {
    n.key === "Enter" && r && r(o || ""), m && m(n);
  };
  return /* @__PURE__ */ l("div", { className: e.root, children: [
    y && /* @__PURE__ */ t("div", { className: c(e.label, o && e.hidden), children: y }),
    /* @__PURE__ */ l(
      "div",
      {
        className: c(
          e.container,
          e[s],
          { [e.focused]: V },
          { [e.disabled]: u },
          { [e.error]: a },
          { [e.active]: f }
        ),
        children: [
          /* @__PURE__ */ t("div", { className: e.input_container, children: /* @__PURE__ */ t(
            "input",
            {
              className: c(
                e.input,
                e[`input_${s}`],
                { [e.error]: a },
                { [e.active]: f }
              ),
              disabled: u,
              placeholder: v,
              onChange: S,
              onKeyDown: j,
              onFocus: () => N(!0),
              onBlur: () => N(!1),
              value: o,
              style: { outline: "none" }
            }
          ) }),
          T && /* @__PURE__ */ t("div", { className: e.button_container, children: /* @__PURE__ */ t(
            E,
            {
              variant: s === "primary" ? "primary" : "primary-invert",
              as: "button",
              size: "sm",
              type: b,
              onClick: _,
              children: x
            }
          ) })
        ]
      }
    ),
    a && p && /* @__PURE__ */ l("div", { className: e.errorTextContainer, children: [
      /* @__PURE__ */ t(w, { name: z.INFO, className: e.errorIcon }),
      /* @__PURE__ */ t(B, { defaultVariant: "labelSm", className: e.errorText, children: p })
    ] })
  ] });
};
export {
  q as TextInput
};
