'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState, useEffect } from 'react';
import { Sparkle, X } from '@phosphor-icons/react';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import { useSuggestions } from '@/lib/api-docs/agent/use-suggestions';
export function AgentPopupButton({ onClick, onQuestionClick, className, currentEndpoint, endpointIndex = [] }) {
    const [showSuggestions, setShowSuggestions] = useState(false);
    const [isDismissed, setIsDismissed] = useState(false);
    // Use shared suggestions hook - limit to 3 for popup
    const { suggestions, isLoading } = useSuggestions({
        currentEndpoint,
        endpointIndex,
        limit: 3
    });
    // Show suggestions after a delay (only if not dismissed and we have suggestions)
    useEffect(()=>{
        if (isDismissed || isLoading || suggestions.length === 0) return;
        const timer = setTimeout(()=>{
            setShowSuggestions(true);
        }, 1500) // 1.5 second delay
        ;
        return ()=>clearTimeout(timer);
    }, [
        isDismissed,
        isLoading,
        suggestions.length
    ]);
    // Reset dismissed state when endpoint changes
    useEffect(()=>{
        setIsDismissed(false);
        setShowSuggestions(false);
    }, [
        currentEndpoint?.id
    ]);
    const handleDismiss = (e)=>{
        e.stopPropagation();
        setShowSuggestions(false);
        setIsDismissed(true);
    };
    const handleQuestionClick = (prompt)=>{
        if (onQuestionClick) {
            onQuestionClick(prompt);
        } else {
            onClick();
        }
    };
    return /*#__PURE__*/ _jsxs("div", {
        className: "fixed bottom-6 right-6 z-50 flex flex-col items-end gap-2",
        children: [
            showSuggestions && suggestions.length > 0 && /*#__PURE__*/ _jsxs(_Fragment, {
                children: [
                    /*#__PURE__*/ _jsx("button", {
                        onClick: handleDismiss,
                        className: "size-6 rounded-full bg-background border border-border shadow-sm flex items-center justify-center hover:bg-muted transition-colors agent-suggestions-enter",
                        "aria-label": "Dismiss suggestions",
                        children: /*#__PURE__*/ _jsx(X, {
                            className: "size-3 text-muted-foreground",
                            weight: "bold"
                        })
                    }),
                    suggestions.map((suggestion, index)=>/*#__PURE__*/ _jsxs("button", {
                            onClick: ()=>handleQuestionClick(suggestion.prompt),
                            className: cn("text-sm px-4 py-2 rounded-full", "bg-background border border-border shadow-md", "hover:bg-muted hover:shadow-lg transition-all", "text-foreground", "agent-suggestion-item"),
                            style: {
                                animationDelay: `${(suggestions.length - index) * 80}ms`
                            },
                            children: [
                                /*#__PURE__*/ _jsx("span", {
                                    className: "font-medium",
                                    children: suggestion.title
                                }),
                                ' ',
                                /*#__PURE__*/ _jsx("span", {
                                    className: "text-muted-foreground",
                                    children: suggestion.label
                                })
                            ]
                        }, index))
                ]
            }),
            /*#__PURE__*/ _jsxs(Button, {
                onClick: onClick,
                className: cn("h-10 px-4 rounded-full", "bg-primary hover:bg-primary/90 text-primary-foreground", "shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30", "transition-all duration-200", "agent-popup-enter", "gap-2 font-medium", className),
                "aria-label": "Open AI Assistant",
                children: [
                    /*#__PURE__*/ _jsx(Sparkle, {
                        className: "size-4",
                        weight: "fill"
                    }),
                    /*#__PURE__*/ _jsx("span", {
                        children: "Ask AI"
                    })
                ]
            })
        ]
    });
}
