import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useMemo, useState } from "react";
import { RefreshCw, RotateCcw } from "lucide-react";
import { ParheliaAgentIcon } from "../../ui/Icons";
import { LoadingState } from "../../ui/LoadingState";
import { Button } from "../../../components/ui/button";
import { AgentTerminal } from "../../ai/AgentTerminal";
import { getAiProfilesErrorMessage, loadAiProfiles, } from "../../services/aiService";
export function JavaScriptToolAgentPanel({ toolName, agentId, loading, resetting, error, onStartOver, headerStart, }) {
    const [profiles, setProfiles] = useState([]);
    const [profilesError, setProfilesError] = useState(null);
    useEffect(() => {
        let cancelled = false;
        setProfilesError(null);
        loadAiProfiles()
            .then((items) => {
            if (!cancelled) {
                setProfiles(items || []);
            }
        })
            .catch((loadError) => {
            if (!cancelled) {
                setProfiles([]);
                setProfilesError(getAiProfilesErrorMessage(loadError));
            }
        });
        return () => {
            cancelled = true;
        };
    }, []);
    const agentStub = useMemo(() => {
        if (!agentId)
            return null;
        return {
            id: agentId,
            name: "",
            userId: "",
            updatedDate: "",
            status: "idle",
        };
    }, [agentId]);
    const headerTitle = toolName?.trim()
        ? `${toolName} Assistant`
        : "JavaScript Tool Assistant";
    return (_jsxs("div", { className: "bg-neutral-grey-5 flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "border-border-default flex items-center justify-between gap-2 border-b px-4 py-3", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [headerStart ? _jsx("div", { className: "shrink-0", children: headerStart }) : null, _jsx(ParheliaAgentIcon, { className: "text-muted-foreground h-5 w-5 shrink-0" }), _jsx("div", { className: "min-w-0 truncate text-sm font-medium", children: headerTitle })] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: onStartOver, disabled: !toolName || loading || resetting, title: "Create a fresh assistant conversation for this JavaScript tool", children: [resetting ? (_jsx(RefreshCw, { className: "h-4 w-4 animate-spin", strokeWidth: 1 })) : (_jsx(RotateCcw, { className: "h-4 w-4", strokeWidth: 1 })), "Start Over"] })] }), profilesError ? (_jsx("div", { className: "border-feedback-orange bg-feedback-orange-light text-feedback-orange border-b px-4 py-2 text-xs", children: profilesError })) : null, error ? (_jsx("div", { className: "border-feedback-red bg-feedback-red-light text-feedback-red border-b px-4 py-2 text-xs", children: error })) : null, _jsx("div", { className: "min-h-0 flex-1", children: loading ? (_jsx(LoadingState, { variant: "fill", message: "Loading JavaScript tool assistant...", spinnerClassName: "text-muted-foreground/60" })) : !toolName ? (_jsxs("div", { className: "flex h-full flex-col items-center justify-center gap-3 p-6 text-center", children: [_jsx(ParheliaAgentIcon, { className: "text-muted-foreground/40 h-10 w-10" }), _jsxs("div", { className: "grid gap-1", children: [_jsx("div", { className: "text-muted-foreground text-sm font-medium", children: "No tool selected" }), _jsx("div", { className: "text-muted-foreground text-xs", children: "Select a JavaScript tool to open its dedicated assistant." })] })] })) : !agentStub ? (_jsxs("div", { className: "flex h-full flex-col items-center justify-center gap-3 p-6 text-center", children: [_jsx(ParheliaAgentIcon, { className: "text-muted-foreground/40 h-10 w-10" }), _jsxs("div", { className: "grid gap-1", children: [_jsx("div", { className: "text-muted-foreground text-sm font-medium", children: "Assistant unavailable" }), _jsx("div", { className: "text-muted-foreground text-xs", children: "Try selecting the tool again or use Start Over to create a fresh session." })] })] })) : (_jsx(AgentTerminal, { agentStub: agentStub, profiles: profiles, isActive: true, compact: true, hideGreeting: true, displayMode: "full", showSummaryInput: false, className: "h-full" })) })] }));
}
export default JavaScriptToolAgentPanel;
//# sourceMappingURL=JavaScriptToolAgentPanel.js.map