import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button } from '../ui/Button';
import { memo } from 'react';
import { Terminal as TerminalIcon, User, Bot } from 'lucide-react';
import { useTerminalStore } from '../../stores/terminalStore';
export const TerminalList = memo(function TerminalList({ terminals, isLoading, }) {
    const selectTerminal = useTerminalStore((state) => state.selectTerminal);
    if (isLoading) {
        return (_jsx("div", { className: "flex items-center justify-center h-full text-muted-foreground", children: _jsx("div", { className: "text-sm", children: "Loading terminals..." }) }));
    }
    if (terminals.length === 0) {
        return (_jsxs("div", { className: "flex flex-col items-center justify-center h-full text-muted-foreground px-4 text-center", children: [_jsx(TerminalIcon, { className: "w-12 h-12 mb-3 opacity-50" }), _jsx("div", { className: "text-sm font-medium mb-1", children: "No active terminals" }), _jsx("div", { className: "text-xs", children: "Click the + button to create a new terminal" })] }));
    }
    return (_jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx("div", { className: "p-2 space-y-1", children: terminals.map((terminal) => (_jsx(Button, { variant: "ghost", className: "w-full justify-start h-auto py-3 px-3", onClick: () => selectTerminal(terminal.id), children: _jsxs("div", { className: "flex items-start gap-3 w-full", children: [_jsx("div", { className: "shrink-0 mt-0.5", children: terminal.createdBy === 'llm' ? (_jsx(Bot, { className: "w-4 h-4 text-blue-500" })) : (_jsx(User, { className: "w-4 h-4 text-green-500" })) }), _jsxs("div", { className: "flex-1 min-w-0 text-left", children: [_jsx("div", { className: "text-sm font-medium truncate", children: terminal.title }), _jsxs("div", { className: "text-xs text-muted-foreground truncate", children: [terminal.command, ' ', terminal.args.length > 0 && terminal.args.join(' ')] }), _jsxs("div", { className: "flex items-center gap-2 mt-1", children: [_jsx("span", { className: `text-xs ${terminal.status === 'running'
                                                ? 'text-green-600'
                                                : 'text-orange-600'}`, children: terminal.status === 'running'
                                                ? 'Running'
                                                : `Exited (${terminal.exitCode})` }), _jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u2022 ", formatUptime(terminal.uptime)] })] })] })] }) }, terminal.id))) }) }));
});
function formatUptime(ms) {
    const seconds = Math.floor(ms / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    if (hours > 0) {
        return `${hours}h ${minutes % 60}m`;
    }
    if (minutes > 0) {
        return `${minutes}m`;
    }
    return `${seconds}s`;
}
//# sourceMappingURL=TerminalList.js.map