import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEditContext } from "../../client/editContext";
import { SimpleIconButton } from "../../ui/SimpleIconButton";
import { ParheliaAgentIcon } from "../../ui/Icons";
import { MessageCircleMore } from "lucide-react";
import { useAgentStatus } from "../../ai/useAgentStatus";
import { AgentStatusBadge } from "../../ai/AgentStatusBadge";
import { LicenseFeatures, useFeature } from "../../../licensing";
import { useActiveAgentConversation } from "../../ai/useActiveAgentConversation";
import { toggleCommentsFeedback } from "../../reviews/openCommentsFeedback";
import { CountBadge } from "../../../components/ui/badge";
export function UtilityControls() {
    const editContext = useEditContext();
    const canUseAi = useFeature(LicenseFeatures.AI);
    const agentStatus = useAgentStatus(canUseAi);
    const hasActiveAgentConversation = useActiveAgentConversation();
    if (!editContext)
        return null;
    // Get page from active slot context if available, fallback to editContext.page
    const activeSlotContext = editContext.getActiveSlotContext?.();
    const page = activeSlotContext?.primaryPageViewContext?.page ?? editContext.page;
    const hasItem = Boolean(activeSlotContext?.item ??
        editContext.item ??
        page?.item ??
        editContext.currentItemDescriptor);
    const isMobile = editContext.isMobile;
    const isAgentsSidebarOpen = editContext.openSidebars.includes("agents-panel");
    const commentsCount = editContext.comments?.filter((comment) => !comment.isResolved).length || 0;
    const handleAgentsClick = () => {
        if (isMobile) {
            editContext.toggleSidebar?.("agents-panel");
            return;
        }
        editContext.setShowAgentsPanel(!editContext.showAgentsPanel);
    };
    return (_jsxs(_Fragment, { children: [!isMobile && hasItem && (_jsx(SimpleIconButton, { className: "relative", selected: !!editContext.showComments, icon: _jsx(MessageCircleMore, { className: "h-6 w-6 p-1", strokeWidth: 1 }), label: "Show comments", size: "large", "data-testid": "toggle-comments-button", onClick: () => toggleCommentsFeedback(editContext), children: commentsCount > 0 && (_jsx(CountBadge, { className: "absolute -top-1 -right-1 min-w-[16px]", children: commentsCount > 99 ? "99+" : commentsCount })) })), canUseAi && (_jsxs(_Fragment, { children: [_jsx(SimpleIconButton, { icon: _jsxs("div", { className: "relative", children: [_jsx(ParheliaAgentIcon, { className: "h-6 w-6 p-0.5" }), _jsx(AgentStatusBadge, { status: agentStatus })] }), label: "Agents", size: "large", "data-testid": "agents-panel-button", selected: isMobile ? isAgentsSidebarOpen : editContext.showAgentsPanel, onClick: handleAgentsClick }), hasActiveAgentConversation && (_jsx("span", { "data-testid": "active-agent-conversation", hidden: true }))] }))] }));
}
//# sourceMappingURL=UtilityControls.js.map