import { cn as e } from "../../../lib/utils.js";
import { i as t, n, r, t as i } from "../../../tooltip-34vRSwJG.js";
import { Textarea as a } from "../atoms/textarea.js";
import o, { createContext as s, useContext as c, useLayoutEffect as l, useRef as u, useState as d } from "react";
import { jsx as f, jsxs as p } from "react/jsx-runtime";
//#region lib/components/ui/molecules/prompt-input.tsx
var m = s({
	isLoading: !1,
	value: "",
	setValue: () => {},
	maxHeight: 240,
	onSubmit: void 0,
	disabled: !1,
	textareaRef: o.createRef()
});
function h() {
	return c(m);
}
function g({ className: t, isLoading: n = !1, maxHeight: i = 240, value: a, onValueChange: o, onSubmit: s, children: c, disabled: l = !1, onClick: p, ...h }) {
	let [g, _] = d(a || ""), v = u(null);
	return /* @__PURE__ */ f(r, { children: /* @__PURE__ */ f(m.Provider, {
		value: {
			isLoading: n,
			value: a ?? g,
			setValue: o ?? ((e) => {
				_(e), o?.(e);
			}),
			maxHeight: i,
			onSubmit: s,
			disabled: l,
			textareaRef: v
		},
		children: /* @__PURE__ */ f("div", {
			className: e("cursor-text rounded-lg border border-input bg-background p-2 shadow-xs transition-[box-shadow,border-color] focus-within:border focus-within:border-muted-foreground focus-within:shadow-[0_0_4px_color-mix(in_oklch,var(--ring)_4%,transparent)] dark:focus-within:shadow-[0_0_4px_color-mix(in_oklch,var(--ring)_8%,transparent)]", t),
			"data-slot": "prompt-input",
			onClick: (e) => {
				let t = e.target, n = t ? e.currentTarget.contains(t) : !1;
				!l && n && v.current?.focus(), p?.(e);
			},
			...h,
			children: c
		})
	}) });
}
function _({ className: t, onKeyDown: n, disableAutosize: r = !1, ...i }) {
	let { value: o, setValue: s, maxHeight: c, onSubmit: u, disabled: d, textareaRef: p } = h(), m = (e) => {
		!e || r || (e.style.height = "auto", typeof c == "number" ? e.style.height = `${Math.min(e.scrollHeight, c)}px` : e.style.height = `min(${e.scrollHeight}px, ${c})`);
	};
	return l(() => {
		if (!p.current || r) return;
		let e = p.current;
		e.style.height = "auto", typeof c == "number" ? e.style.height = `${Math.min(e.scrollHeight, c)}px` : e.style.height = `min(${e.scrollHeight}px, ${c})`;
	}, [
		o,
		c,
		r
	]), /* @__PURE__ */ f(a, {
		className: e("min-h-[56px] w-full resize-none border-none bg-transparent text-foreground shadow-none outline-none focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-transparent", t),
		"data-slot": "prompt-input-textarea",
		onChange: (e) => {
			m(e.target), s(e.target.value);
		},
		onKeyDown: (e) => {
			e.key === "Enter" && !e.shiftKey && (e.preventDefault(), d || u?.()), n?.(e);
		},
		ref: (e) => {
			p.current = e, m(e);
		},
		rows: 1,
		value: o,
		...i
	});
}
function v({ children: t, className: n, ...r }) {
	return /* @__PURE__ */ f("div", {
		className: e("flex items-center gap-2", n),
		"data-slot": "prompt-input-actions",
		...r,
		children: t
	});
}
function y({ tooltip: e, children: r, className: a, side: o = "top", ...s }) {
	let { disabled: c } = h();
	return /* @__PURE__ */ p(i, {
		...s,
		children: [/* @__PURE__ */ f(t, {
			disabled: c,
			onClick: (e) => e.stopPropagation(),
			onPointerDown: (e) => {
				e.pointerType !== "touch" && e.preventDefault();
			},
			render: r
		}), /* @__PURE__ */ f(n, {
			className: a,
			side: o,
			children: e
		})]
	});
}
//#endregion
export { g as PromptInput, y as PromptInputAction, v as PromptInputActions, _ as PromptInputTextarea };
