'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Code2, Terminal, FolderOpen, FileText, Copy, Check, Loader2, CircleAlert, } from 'lucide-react';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip.js';
const COPY_FEEDBACK_DELAY = 2000;
const tbBtn = 'text-muted-foreground hover:bg-foreground/8 hover:text-foreground inline-flex size-8 items-center justify-center rounded-[3px] disabled:opacity-40';
function TbIcon({ loading, error, icon: Icon, }) {
    if (loading)
        return _jsx(Loader2, { className: "size-3.5 animate-spin" });
    if (error)
        return _jsx(CircleAlert, { className: "text-destructive size-3.5" });
    return _jsx(Icon, { className: "size-4" });
}
export function OpenActionMenu({ actions, repositoryPath, worktreePath, showSpecs, }) {
    const [copied, setCopied] = useState(false);
    const handleCopyPath = () => {
        void navigator.clipboard.writeText(worktreePath ?? repositoryPath);
        setCopied(true);
        setTimeout(() => setCopied(false), COPY_FEEDBACK_DELAY);
    };
    return (_jsx(TooltipProvider, { delayDuration: 300, children: _jsxs("div", { className: "flex items-center", children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", className: tbBtn, onClick: actions.openInIde, disabled: actions.ideLoading, "aria-label": "Open in IDE", children: _jsx(TbIcon, { loading: actions.ideLoading, error: actions.ideError, icon: Code2 }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Open in IDE" })] }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", className: tbBtn, onClick: actions.openInShell, disabled: actions.shellLoading, "aria-label": "Open terminal", children: _jsx(TbIcon, { loading: actions.shellLoading, error: actions.shellError, icon: Terminal }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Open terminal" })] }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", className: tbBtn, onClick: actions.openFolder, disabled: actions.folderLoading, "aria-label": "Open folder", children: _jsx(TbIcon, { loading: actions.folderLoading, error: actions.folderError, icon: FolderOpen }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Open folder" })] }), showSpecs ? (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", className: tbBtn, onClick: actions.openSpecsFolder, disabled: actions.specsLoading, "aria-label": "Open specs", children: _jsx(TbIcon, { loading: actions.specsLoading, error: actions.specsError, icon: FileText }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Open specs" })] })) : null, _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", className: tbBtn, onClick: handleCopyPath, "aria-label": "Copy path", children: copied ? _jsx(Check, { className: "size-3.5 text-green-500" }) : _jsx(Copy, { className: "size-4" }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: copied ? 'Copied!' : 'Copy path' })] })] }) }));
}
