"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentControlActions = 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 AgentControlActions = ({ agentId }) => {
    const [loading, setLoading] = (0, react_1.useState)(false);
    const toast = (0, react_2.useToast)();
    const sendControlCommand = async (command) => {
        setLoading(true);
        try {
            if (typeof api_js_1.apiClient.controlAgent === 'function') {
                await api_js_1.apiClient.controlAgent(agentId, { command });
                toast({
                    title: `Agent ${command} command sent.`,
                    status: 'success',
                    duration: 3000,
                    isClosable: true,
                });
            }
            else {
                throw new Error('controlAgent method is not available on apiClient.');
            }
        }
        catch (error) {
            toast({
                title: `Failed to send ${command} command.`,
                description: error instanceof Error ? error.message : undefined,
                status: 'error',
                duration: 3000,
                isClosable: true,
            });
        }
        finally {
            setLoading(false);
        }
    };
    return ((0, jsx_runtime_1.jsxs)(react_2.Box, { borderWidth: "1px", borderRadius: "md", p: 4, maxW: "400px", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { mb: 2, children: "Control Actions" }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 4, children: [(0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "green", isLoading: loading, onClick: () => sendControlCommand('start'), children: "Start" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "red", isLoading: loading, onClick: () => sendControlCommand('stop'), children: "Stop" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "yellow", isLoading: loading, onClick: () => sendControlCommand('restart'), children: "Restart" })] })] }));
};
exports.AgentControlActions = AgentControlActions;
//# sourceMappingURL=AgentControlActions.js.map