"use client";
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsxs, jsx } from 'react/jsx-runtime';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function Composer({
  value,
  onValueChange,
  onSubmit,
  disabled,
  placeholder,
  submitOnEnter = true,
  textareaAriaLabel,
  children,
  className,
  ...rest
}) {
  function trySubmit() {
    const trimmed = value.trim();
    if (!trimmed || disabled) return;
    onSubmit(trimmed);
  }
  function handleKeyDown(event) {
    if (!submitOnEnter) return;
    if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
      event.preventDefault();
      trySubmit();
    }
  }
  function handleSubmit(event) {
    event.preventDefault();
    trySubmit();
  }
  return /* @__PURE__ */ jsxs(
    "form",
    {
      ...rest,
      onSubmit: handleSubmit,
      className: cn(
        "flex items-end gap-2 rounded-lg border bg-background p-2",
        "focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
        "transition-all duration-[var(--duration-normal,200ms)] ease-out",
        className
      ),
      children: [
        /* @__PURE__ */ jsx(
          "textarea",
          {
            value,
            onChange: (event) => onValueChange(event.target.value),
            onKeyDown: handleKeyDown,
            disabled,
            placeholder,
            "aria-label": textareaAriaLabel ?? placeholder ?? "Message",
            rows: 1,
            className: cn(
              "flex-1 resize-none bg-transparent px-2 py-1.5 text-sm leading-6",
              "placeholder:text-muted-foreground focus:outline-none",
              "disabled:cursor-not-allowed disabled:opacity-50",
              "max-h-48 min-h-[2.25rem] overflow-y-auto"
            )
          }
        ),
        children
      ]
    }
  );
}

export { Composer };
//# sourceMappingURL=composer.js.map
//# sourceMappingURL=composer.js.map