"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentLogs = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("@chakra-ui/react");
const api_js_1 = require("../../services/api.js");
const AgentLogs = ({ agentId }) => {
    const [logs, setLogs] = (0, react_1.useState)([]);
    const [loading, setLoading] = (0, react_1.useState)(true);
    const [error, setError] = (0, react_1.useState)(null);
    const fetchLogs = async () => {
        setLoading(true);
        setError(null);
        try {
            if (typeof api_js_1.apiClient.getAgentLogs === 'function') {
                const data = await api_js_1.apiClient.getAgentLogs(agentId);
                // Assuming data is an array of log strings
                setLogs(data);
            }
            else {
                throw new Error('getAgentLogs method is not available on apiClient.');
            }
        }
        catch (err) {
            setError('Failed to load agent logs');
        }
        finally {
            setLoading(false);
        }
    };
    (0, react_1.useEffect)(() => {
        fetchLogs();
        // Optionally, set interval for real-time updates
        const interval = setInterval(fetchLogs, 5000);
        return () => clearInterval(interval);
    }, [agentId]);
    if (loading) {
        return (0, jsx_runtime_1.jsx)(react_2.Spinner, { size: "md" });
    }
    if (error) {
        return (0, jsx_runtime_1.jsx)(react_2.Text, { color: "red.500", children: error });
    }
    return ((0, jsx_runtime_1.jsxs)(react_2.Box, { borderWidth: "1px", borderRadius: "md", p: 4, maxW: "600px", overflowY: "auto", maxHeight: "300px", children: [(0, jsx_runtime_1.jsx)(react_2.VStack, { align: "start", spacing: 1, children: logs.length === 0 ? ((0, jsx_runtime_1.jsx)(react_2.Text, { children: "No logs available" })) : (logs.map((log, index) => ((0, jsx_runtime_1.jsx)(react_2.Text, { fontFamily: "monospace", fontSize: "sm", whiteSpace: "pre-wrap", children: log }, index)))) }), (0, jsx_runtime_1.jsx)(react_2.Button, { mt: 2, size: "sm", onClick: fetchLogs, children: "Refresh Logs" })] }));
};
exports.AgentLogs = AgentLogs;
//# sourceMappingURL=AgentLogs.js.map