"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentFleetOrchestration = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const react_2 = require("@chakra-ui/react");
const fi_1 = require("react-icons/fi");
const AgentFleetOrchestration = ({ fleetStatus, onAgentAction }) => {
    const [selectedAgent, setSelectedAgent] = (0, react_1.useState)(null);
    const [scalingAgent, setScalingAgent] = (0, react_1.useState)(null);
    const [autoScaling, setAutoScaling] = (0, react_1.useState)(true);
    const [scaleTarget, setScaleTarget] = (0, react_1.useState)(1);
    const { isOpen: isScaleModalOpen, onOpen: onScaleModalOpen, onClose: onScaleModalClose } = (0, react_2.useDisclosure)();
    const { isOpen: isConfirmOpen, onOpen: onConfirmOpen, onClose: onConfirmClose } = (0, react_2.useDisclosure)();
    const [confirmAction, setConfirmAction] = (0, react_1.useState)(null);
    const toast = (0, react_2.useToast)();
    const cardBg = (0, react_2.useColorModeValue)('white', 'gray.800');
    const borderColor = (0, react_2.useColorModeValue)('gray.200', 'gray.600');
    const cancelRef = react_1.default.useRef(null);
    // Mock agent data
    const agents = [
        {
            id: 'agent-001',
            name: 'Content Analyzer',
            type: 'llm-analysis',
            status: 'active',
            currentTasks: 3,
            maxTasks: 5,
            instances: 2,
            resourceUsage: { cpu: 65, memory: 70, tokens: 40 },
            lastActivity: '2 minutes ago',
            endpoints: ['POST /analyze/content', 'POST /analyze/sentiment']
        },
        {
            id: 'agent-002',
            name: 'SEO Optimizer',
            type: 'content-optimization',
            status: 'active',
            currentTasks: 2,
            maxTasks: 3,
            instances: 1,
            resourceUsage: { cpu: 45, memory: 55, tokens: 30 },
            lastActivity: '5 minutes ago',
            endpoints: ['POST /optimize/seo', 'POST /optimize/keywords']
        },
        {
            id: 'agent-003',
            name: 'Translation Service',
            type: 'language-processing',
            status: 'idle',
            currentTasks: 0,
            maxTasks: 4,
            instances: 1,
            resourceUsage: { cpu: 15, memory: 25, tokens: 10 },
            lastActivity: '15 minutes ago',
            endpoints: ['POST /translate/text', 'POST /translate/batch']
        },
        {
            id: 'agent-004',
            name: 'Code Assistant',
            type: 'code-generation',
            status: 'error',
            currentTasks: 0,
            maxTasks: 2,
            instances: 1,
            resourceUsage: { cpu: 5, memory: 20, tokens: 0 },
            lastActivity: '30 minutes ago',
            endpoints: ['POST /generate/code', 'POST /review/code']
        }
    ];
    const handleAgentAction = async (action, agentId, params) => {
        if (action === 'stop' || action === 'restart') {
            setConfirmAction({ action, agentId });
            onConfirmOpen();
            return;
        }
        try {
            if (onAgentAction) {
                onAgentAction(action, agentId, params);
            }
            toast({
                title: `Agent ${action} initiated`,
                description: `Action ${action} has been sent to agent ${agentId}`,
                status: 'success',
                duration: 3000,
                isClosable: true,
            });
        }
        catch (error) {
            toast({
                title: `Failed to ${action} agent`,
                description: error instanceof Error ? error.message : 'Unknown error',
                status: 'error',
                duration: 5000,
                isClosable: true,
            });
        }
    };
    const handleConfirmedAction = async () => {
        if (confirmAction) {
            await handleAgentAction(confirmAction.action, confirmAction.agentId);
            setConfirmAction(null);
        }
        onConfirmClose();
    };
    const openScaleModal = (agentId) => {
        setScalingAgent(agentId);
        const agent = agents.find(a => a.id === agentId);
        setScaleTarget(agent?.instances || 1);
        onScaleModalOpen();
    };
    const handleScale = async () => {
        if (scalingAgent) {
            await handleAgentAction('scale', scalingAgent, { instances: scaleTarget });
            onScaleModalClose();
            setScalingAgent(null);
        }
    };
    const getStatusColor = (status) => {
        switch (status) {
            case 'active': return 'green';
            case 'idle': return 'gray';
            case 'error': return 'red';
            case 'scaling': return 'blue';
            default: return 'gray';
        }
    };
    const getStatusIcon = (status) => {
        switch (status) {
            case 'active': return fi_1.FiActivity;
            case 'idle': return fi_1.FiPause;
            case 'error': return fi_1.FiAlertTriangle;
            case 'scaling': return fi_1.FiTrendingUp;
            default: return fi_1.FiActivity;
        }
    };
    return ((0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 6, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Card, { bg: cardBg, borderColor: borderColor, children: [(0, jsx_runtime_1.jsx)(react_2.CardHeader, { children: (0, jsx_runtime_1.jsxs)(react_2.HStack, { justify: "space-between", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "md", fontWeight: "semibold", children: "Fleet Controls" }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 3, children: [(0, jsx_runtime_1.jsxs)(react_2.FormControl, { display: "flex", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(react_2.FormLabel, { htmlFor: "auto-scaling", mb: "0", fontSize: "sm", children: "Auto-scaling" }), (0, jsx_runtime_1.jsx)(react_2.Switch, { id: "auto-scaling", isChecked: autoScaling, onChange: (e) => setAutoScaling(e.target.checked), colorScheme: "green" })] }), (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiRefreshCw }), onClick: () => handleAgentAction('refresh-all', 'fleet'), children: "Refresh All" })] })] }) }), (0, jsx_runtime_1.jsx)(react_2.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_2.Grid, { templateColumns: "repeat(auto-fit, minmax(150px, 1fr))", gap: 4, children: [(0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "green", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiPlay }), onClick: () => handleAgentAction('start-all', 'fleet'), children: "Start All" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "yellow", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiPause }), onClick: () => handleAgentAction('pause-all', 'fleet'), children: "Pause All" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "red", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiSquare }), onClick: () => handleAgentAction('stop-all', 'fleet'), children: "Stop All" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "blue", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiRefreshCw }), onClick: () => handleAgentAction('restart-all', 'fleet'), children: "Restart All" })] }) })] }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 4, align: "stretch", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "md", fontWeight: "semibold", children: "Individual Agent Management" }), agents.map((agent) => ((0, jsx_runtime_1.jsx)(react_2.Card, { bg: cardBg, borderColor: borderColor, children: (0, jsx_runtime_1.jsx)(react_2.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_2.Grid, { templateColumns: { base: '1fr', md: '2fr 1fr 1fr 1fr' }, gap: 4, alignItems: "center", children: [(0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 2, children: [(0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 3, children: [(0, jsx_runtime_1.jsx)(react_2.Icon, { as: getStatusIcon(agent.status), color: `${getStatusColor(agent.status)}.500` }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 0, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "semibold", children: agent.name }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: "gray.500", children: agent.type })] }), (0, jsx_runtime_1.jsx)(react_2.Badge, { colorScheme: getStatusColor(agent.status), size: "sm", children: agent.status })] }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", color: "gray.500", children: ["Last active: ", agent.lastActivity] })] }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 1, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", fontWeight: "medium", children: "Tasks" }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 2, children: [(0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "sm", children: [agent.currentTasks, "/", agent.maxTasks] }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", color: "gray.500", children: ["(", Math.round((agent.currentTasks / agent.maxTasks) * 100), "%)"] })] }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", color: "gray.500", children: [agent.instances, " instance", agent.instances !== 1 ? 's' : ''] })] }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 1, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", fontWeight: "medium", children: "Resources" }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 3, children: [(0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: `CPU: ${agent.resourceUsage.cpu}%`, children: (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 1, children: [(0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiCpu, size: "12px" }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", children: [agent.resourceUsage.cpu, "%"] })] }) }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: "gray.500", children: "|" }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", children: ["MEM: ", agent.resourceUsage.memory, "%"] }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: "gray.500", children: "|" }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "xs", children: ["TOK: ", agent.resourceUsage.tokens, "%"] })] })] }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 2, justify: "end", children: [(0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: "Start Agent", children: (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", colorScheme: "green", variant: "outline", onClick: () => handleAgentAction('start', agent.id), isDisabled: agent.status === 'active', children: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiPlay }) }) }), (0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: "Pause Agent", children: (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", colorScheme: "yellow", variant: "outline", onClick: () => handleAgentAction('pause', agent.id), isDisabled: agent.status !== 'active', children: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiPause }) }) }), (0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: "Stop Agent", children: (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", colorScheme: "red", variant: "outline", onClick: () => handleAgentAction('stop', agent.id), children: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiSquare }) }) }), (0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: "Scale Agent", children: (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", colorScheme: "blue", variant: "outline", onClick: () => openScaleModal(agent.id), children: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiTrendingUp }) }) }), (0, jsx_runtime_1.jsx)(react_2.Tooltip, { label: "Configure Agent", children: (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", colorScheme: "purple", variant: "outline", onClick: () => handleAgentAction('configure', agent.id), children: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiSettings }) }) })] })] }) }) }, agent.id)))] }), (0, jsx_runtime_1.jsxs)(react_2.Modal, { isOpen: isScaleModalOpen, onClose: onScaleModalClose, children: [(0, jsx_runtime_1.jsx)(react_2.ModalOverlay, {}), (0, jsx_runtime_1.jsxs)(react_2.ModalContent, { children: [(0, jsx_runtime_1.jsx)(react_2.ModalHeader, { children: "Scale Agent" }), (0, jsx_runtime_1.jsx)(react_2.ModalCloseButton, {}), (0, jsx_runtime_1.jsx)(react_2.ModalBody, { children: (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 4, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Text, { children: ["Scale agent: ", agents.find(a => a.id === scalingAgent)?.name] }), (0, jsx_runtime_1.jsxs)(react_2.FormControl, { children: [(0, jsx_runtime_1.jsx)(react_2.FormLabel, { children: "Number of instances" }), (0, jsx_runtime_1.jsxs)(react_2.NumberInput, { value: scaleTarget, onChange: (_, value) => setScaleTarget(value), min: 0, max: 10, children: [(0, jsx_runtime_1.jsx)(react_2.NumberInputField, {}), (0, jsx_runtime_1.jsxs)(react_2.NumberInputStepper, { children: [(0, jsx_runtime_1.jsx)(react_2.NumberIncrementStepper, {}), (0, jsx_runtime_1.jsx)(react_2.NumberDecrementStepper, {})] })] })] })] }) }), (0, jsx_runtime_1.jsxs)(react_2.ModalFooter, { children: [(0, jsx_runtime_1.jsx)(react_2.Button, { variant: "ghost", mr: 3, onClick: onScaleModalClose, children: "Cancel" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "blue", onClick: handleScale, children: "Scale" })] })] })] }), (0, jsx_runtime_1.jsx)(react_2.AlertDialog, { isOpen: isConfirmOpen, leastDestructiveRef: cancelRef, onClose: onConfirmClose, children: (0, jsx_runtime_1.jsx)(react_2.AlertDialogOverlay, { children: (0, jsx_runtime_1.jsxs)(react_2.AlertDialogContent, { children: [(0, jsx_runtime_1.jsx)(react_2.AlertDialogHeader, { fontSize: "lg", fontWeight: "bold", children: "Confirm Action" }), (0, jsx_runtime_1.jsxs)(react_2.AlertDialogBody, { children: ["Are you sure you want to ", confirmAction?.action, " the agent? This action may interrupt running tasks."] }), (0, jsx_runtime_1.jsxs)(react_2.AlertDialogFooter, { children: [(0, jsx_runtime_1.jsx)(react_2.Button, { ref: cancelRef, onClick: onConfirmClose, children: "Cancel" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "red", onClick: handleConfirmedAction, ml: 3, children: confirmAction?.action })] })] }) }) })] }));
};
exports.AgentFleetOrchestration = AgentFleetOrchestration;
//# sourceMappingURL=AgentFleetOrchestration.js.map