"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@open-mercato/shared/lib/utils";
const baseTextareaClass = "flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-xs transition-colors placeholder:text-muted-foreground outline-none focus-visible:outline-none focus-visible:shadow-focus focus-visible:border-foreground hover:bg-muted/40 disabled:cursor-not-allowed disabled:bg-bg-disabled disabled:border-border-disabled disabled:shadow-none disabled:hover:bg-bg-disabled aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-visible:border-destructive resize-y min-h-[80px]";
const Textarea = React.forwardRef(
  ({ className, showCount, wrapperClassName, value, defaultValue, maxLength, onChange, ...props }, ref) => {
    const [internalValue, setInternalValue] = React.useState(
      typeof defaultValue === "string" ? defaultValue : typeof value === "string" ? value : ""
    );
    const isControlled = value !== void 0;
    const currentValue = isControlled ? String(value ?? "") : internalValue;
    const handleChange = React.useCallback(
      (event) => {
        if (!isControlled) setInternalValue(event.target.value);
        onChange?.(event);
      },
      [isControlled, onChange]
    );
    const textarea = /* @__PURE__ */ jsx(
      "textarea",
      {
        ref,
        value,
        defaultValue: isControlled ? void 0 : defaultValue,
        maxLength,
        onChange: handleChange,
        className: cn(baseTextareaClass, className),
        ...props
      }
    );
    if (!showCount) return textarea;
    const length = currentValue.length;
    const max = typeof maxLength === "number" ? maxLength : void 0;
    const isError = max != null && length > max;
    const isDisabled = props.disabled;
    return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-1", wrapperClassName), children: [
      textarea,
      /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(
        "span",
        {
          className: cn(
            "text-overline uppercase",
            isDisabled ? "text-text-disabled" : isError ? "text-destructive" : "text-muted-foreground"
          ),
          "aria-live": "polite",
          children: max != null ? `${length}/${max}` : `${length}`
        }
      ) })
    ] });
  }
);
Textarea.displayName = "Textarea";
export {
  Textarea
};
//# sourceMappingURL=textarea.js.map
