'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from 'react';
import { Loader2, ExternalLink, Terminal } from 'lucide-react';
import { DeploymentState } from '../../../../../../packages/core/src/domain/generated/output.js';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip.js';
import { ServerLogViewer } from '../../common/server-log-viewer/index.js';
const tbBtn = 'text-muted-foreground hover:bg-foreground/8 hover:text-foreground inline-flex size-7 items-center justify-center rounded-[3px]';
export function DeploymentStatusBadge({ status, url, targetId }) {
    const [logViewerOpen, setLogViewerOpen] = useState(false);
    const showLogButton = targetId && (status === DeploymentState.Booting || status === DeploymentState.Ready);
    switch (status) {
        case DeploymentState.Booting:
            return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-1 pl-1", children: [_jsx(Loader2, { className: "size-3 animate-spin text-blue-500" }), _jsx("span", { className: "text-muted-foreground text-[11px]", children: "Starting..." }), showLogButton ? (_jsx(TooltipProvider, { delayDuration: 300, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": "View server logs", className: tbBtn, onClick: (e) => {
                                                    e.stopPropagation();
                                                    setLogViewerOpen(true);
                                                }, children: _jsx(Terminal, { className: "size-3.5" }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Server logs" })] }) })) : null] }), showLogButton ? (_jsx(ServerLogViewer, { open: logViewerOpen, onOpenChange: setLogViewerOpen, targetId: targetId })) : null] }));
        case DeploymentState.Ready:
            return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex translate-y-px items-center gap-1 pl-1", children: [_jsx("span", { className: "inline-block size-1.5 rounded-full bg-green-500" }), url ? (_jsxs("a", { href: url, target: "_blank", rel: "noopener noreferrer", className: "inline-flex items-center gap-0.5 text-[11px] text-green-600 hover:text-green-500 dark:text-green-400 dark:hover:text-green-300", onClick: (e) => e.stopPropagation(), children: [url, _jsx(ExternalLink, { className: "size-2.5 shrink-0" })] })) : (_jsx("span", { className: "text-[11px] text-green-600 dark:text-green-400", children: "Ready" })), showLogButton ? (_jsx(TooltipProvider, { delayDuration: 300, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": "View server logs", className: tbBtn, onClick: (e) => {
                                                    e.stopPropagation();
                                                    setLogViewerOpen(true);
                                                }, children: _jsx(Terminal, { className: "size-3.5" }) }) }), _jsx(TooltipContent, { side: "bottom", className: "text-xs", children: "Server logs" })] }) })) : null] }), showLogButton ? (_jsx(ServerLogViewer, { open: logViewerOpen, onOpenChange: setLogViewerOpen, targetId: targetId })) : null] }));
        default:
            return null;
    }
}
