import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useThread } from "@openuidev/react-headless";
import clsx from "clsx";
import { ArrowUp, Square } from "lucide-react";
import { useLayoutEffect, useRef } from "react";
import { useComposerState } from "../../../hooks/useComposerState";
import { IconButton } from "../../IconButton";
export const DesktopWelcomeComposer = ({ className, placeholder = "Type your query here", }) => {
    const { textContent, setTextContent } = useComposerState();
    const processMessage = useThread((s) => s.processMessage);
    const cancelMessage = useThread((s) => s.cancelMessage);
    const isRunning = useThread((s) => s.isRunning);
    const isLoadingMessages = useThread((s) => s.isLoadingMessages);
    const inputRef = useRef(null);
    const handleSubmit = () => {
        if (!textContent.trim() || isRunning || isLoadingMessages) {
            return;
        }
        processMessage({
            role: "user",
            content: textContent,
        });
        setTextContent("");
    };
    useLayoutEffect(() => {
        const input = inputRef.current;
        if (!input)
            return;
        // Reset to 0 (not "auto") so scrollHeight reflects content, not container
        input.style.height = "0px";
        input.style.height = `${Math.max(input.scrollHeight, 24)}px`;
    }, [textContent]);
    return (_jsxs("div", { className: clsx("openui-agent-desktop-welcome-composer", className), "data-drafting": textContent.length > 0 || undefined, children: [_jsx("textarea", { ref: inputRef, value: textContent, onChange: (e) => setTextContent(e.target.value), className: "openui-agent-desktop-welcome-composer__input", placeholder: placeholder, rows: 1, onKeyDown: (e) => {
                    if (e.key === "Enter" && !e.shiftKey) {
                        e.preventDefault();
                        handleSubmit();
                    }
                } }), _jsx("div", { className: "openui-agent-desktop-welcome-composer__action-bar", children: _jsx(IconButton, { onClick: isRunning ? cancelMessage : handleSubmit, disabled: !textContent.trim() && !isRunning, "aria-label": isRunning ? "Cancel" : "Send", icon: isRunning ? _jsx(Square, { size: "1em", fill: "currentColor" }) : _jsx(ArrowUp, { size: "1em" }), size: "extra-small", variant: "primary", className: "openui-agent-desktop-welcome-composer__submit-button" }) })] }));
};
export default DesktopWelcomeComposer;
//# sourceMappingURL=DesktopWelcomeComposer.js.map