import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useThread } from "@openuidev/react-headless";
import clsx from "clsx";
import { useStartersFromContext } from "./_shared/startersContext";
import { isChatEmpty } from "./_shared/utils";
import { DesktopWelcomeComposer } from "./components";
import { ConversationStarter } from "./ConversationStarter";
/**
 * Type guard to check if image is a URL object
 */
const isImageUrl = (image) => {
    return typeof image === "object" && image !== null && "url" in image;
};
export const WelcomeScreen = (props) => {
    const { className } = props;
    const fromCtx = useStartersFromContext();
    const ownStarters = "starters" in props ? props.starters : undefined;
    const ownVariant = "starterVariant" in props ? props.starterVariant : undefined;
    const starters = ownStarters ?? fromCtx.starters ?? [];
    const starterVariant = ownVariant ?? fromCtx.starterVariant ?? "long";
    const messages = useThread((s) => s.messages);
    const isLoadingMessages = useThread((s) => s.isLoadingMessages);
    // Only show when there are no messages
    if (!isChatEmpty({ isLoadingMessages, messages })) {
        return null;
    }
    // Check if children are provided
    if ("children" in props && props.children) {
        return _jsx("div", { className: clsx("openui-agent-welcome-screen", className), children: props.children });
    }
    // Props-based content
    const { title, description, image } = props;
    const renderImage = () => {
        if (!image)
            return null;
        if (isImageUrl(image)) {
            return (_jsx("img", { src: image.url, alt: title || "", className: "openui-agent-welcome-screen__image" }));
        }
        return image;
    };
    return (_jsxs("div", { className: clsx("openui-agent-welcome-screen", "openui-agent-welcome-screen--with-composer", className), children: [_jsxs("div", { className: "openui-agent-welcome-screen__header", children: [image && (_jsx("div", { className: "openui-agent-welcome-screen__image-container", children: renderImage() })), (title || description) && (_jsxs("div", { className: "openui-agent-welcome-screen__content", children: [title && _jsx("h2", { className: "openui-agent-welcome-screen__title", children: title }), description && (_jsx("p", { className: "openui-agent-welcome-screen__description", children: description }))] }))] }), _jsxs("div", { className: "openui-agent-welcome-screen__composer-starters-container", children: [_jsx("div", { className: "openui-agent-welcome-screen__desktop-composer", children: _jsx(DesktopWelcomeComposer, {}) }), starters.length > 0 && (_jsx("div", { className: "openui-agent-welcome-screen__desktop-starters", children: _jsx(ConversationStarter, { starters: starters, variant: starterVariant }) }))] })] }));
};
export default WelcomeScreen;
//# sourceMappingURL=WelcomeScreen.js.map