"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentFleetLogs = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("@chakra-ui/react");
const fi_1 = require("react-icons/fi");
const AgentFleetLogs = ({ activities }) => {
    const [searchTerm, setSearchTerm] = (0, react_1.useState)('');
    const [filterType, setFilterType] = (0, react_1.useState)('all');
    const [filterAgent, setFilterAgent] = (0, react_1.useState)('all');
    const [expandedLogs, setExpandedLogs] = (0, react_1.useState)(new Set());
    const cardBg = (0, react_2.useColorModeValue)('white', 'gray.800');
    const borderColor = (0, react_2.useColorModeValue)('gray.200', 'gray.600');
    // Extended mock data for more comprehensive logs
    const extendedActivities = [
        ...activities,
        {
            id: '4',
            timestamp: new Date(Date.now() - 1200000).toISOString(),
            type: 'task_started',
            agentId: 'agent-001',
            agentName: 'Content Analyzer',
            message: 'Started batch processing of 25 documents',
            metadata: {
                taskId: 'task-001',
                batchSize: 25,
                estimatedDuration: '5 minutes'
            }
        },
        {
            id: '5',
            timestamp: new Date(Date.now() - 1500000).toISOString(),
            type: 'agent_deployed',
            agentId: 'agent-004',
            agentName: 'Code Assistant',
            message: 'Agent deployed with updated configuration',
            metadata: {
                version: '1.2.3',
                configHash: 'abc123def',
                deploymentTime: '30 seconds'
            }
        },
        {
            id: '6',
            timestamp: new Date(Date.now() - 1800000).toISOString(),
            type: 'task_completed',
            agentId: 'agent-002',
            agentName: 'SEO Optimizer',
            message: 'Completed SEO analysis for blog posts batch',
            metadata: {
                itemsProcessed: 15,
                avgScore: 8.7,
                improvements: ['keyword density', 'meta descriptions']
            }
        }
    ].sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
    const filteredActivities = (0, react_1.useMemo)(() => {
        return extendedActivities.filter(activity => {
            const matchesSearch = searchTerm === '' ||
                activity.message.toLowerCase().includes(searchTerm.toLowerCase()) ||
                activity.agentName.toLowerCase().includes(searchTerm.toLowerCase());
            const matchesType = filterType === 'all' || activity.type === filterType;
            const matchesAgent = filterAgent === 'all' || activity.agentId === filterAgent;
            return matchesSearch && matchesType && matchesAgent;
        });
    }, [extendedActivities, searchTerm, filterType, filterAgent]);
    const uniqueAgents = (0, react_1.useMemo)(() => {
        const agentMap = new Map();
        extendedActivities.forEach(activity => {
            agentMap.set(activity.agentId, activity.agentName);
        });
        return Array.from(agentMap.entries());
    }, [extendedActivities]);
    const getActivityIcon = (type) => {
        switch (type) {
            case 'task_completed': return fi_1.FiCheckCircle;
            case 'task_failed': return fi_1.FiAlertCircle;
            case 'task_started': return fi_1.FiClock;
            case 'agent_deployed': return fi_1.FiTrendingUp;
            case 'agent_scaled': return fi_1.FiActivity;
            default: return fi_1.FiActivity;
        }
    };
    const getActivityColor = (type) => {
        switch (type) {
            case 'task_completed': return 'green.500';
            case 'task_failed': return 'red.500';
            case 'task_started': return 'blue.500';
            case 'agent_deployed': return 'purple.500';
            case 'agent_scaled': return 'orange.500';
            default: return 'gray.500';
        }
    };
    const getTypeBadgeColor = (type) => {
        switch (type) {
            case 'task_completed': return 'green';
            case 'task_failed': return 'red';
            case 'task_started': return 'blue';
            case 'agent_deployed': return 'purple';
            case 'agent_scaled': return 'orange';
            default: return 'gray';
        }
    };
    const toggleExpanded = (id) => {
        const newExpanded = new Set(expandedLogs);
        if (newExpanded.has(id)) {
            newExpanded.delete(id);
        }
        else {
            newExpanded.add(id);
        }
        setExpandedLogs(newExpanded);
    };
    const exportLogs = () => {
        const logsData = filteredActivities.map(activity => ({
            timestamp: activity.timestamp,
            type: activity.type,
            agent: activity.agentName,
            message: activity.message,
            metadata: activity.metadata
        }));
        const dataStr = JSON.stringify(logsData, null, 2);
        const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
        const exportFileDefaultName = `agent-fleet-logs-${new Date().toISOString().split('T')[0]}.json`;
        const linkElement = document.createElement('a');
        linkElement.setAttribute('href', dataUri);
        linkElement.setAttribute('download', exportFileDefaultName);
        linkElement.click();
    };
    return ((0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 4, align: "stretch", children: [(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.VStack, { spacing: 4, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Flex, { wrap: "wrap", gap: 4, align: "center", children: [(0, jsx_runtime_1.jsx)(react_2.Input, { placeholder: "Search logs...", value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), size: "sm", maxW: "300px" }), (0, jsx_runtime_1.jsxs)(react_2.Select, { value: filterType, onChange: (e) => setFilterType(e.target.value), size: "sm", maxW: "200px", children: [(0, jsx_runtime_1.jsx)("option", { value: "all", children: "All Types" }), (0, jsx_runtime_1.jsx)("option", { value: "task_completed", children: "Task Completed" }), (0, jsx_runtime_1.jsx)("option", { value: "task_failed", children: "Task Failed" }), (0, jsx_runtime_1.jsx)("option", { value: "task_started", children: "Task Started" }), (0, jsx_runtime_1.jsx)("option", { value: "agent_deployed", children: "Agent Deployed" }), (0, jsx_runtime_1.jsx)("option", { value: "agent_scaled", children: "Agent Scaled" })] }), (0, jsx_runtime_1.jsxs)(react_2.Select, { value: filterAgent, onChange: (e) => setFilterAgent(e.target.value), size: "sm", maxW: "200px", children: [(0, jsx_runtime_1.jsx)("option", { value: "all", children: "All Agents" }), uniqueAgents.map(([id, name]) => ((0, jsx_runtime_1.jsx)("option", { value: id, children: name }, id)))] }), (0, jsx_runtime_1.jsx)(react_2.Spacer, {}), (0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 2, children: [(0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiRefreshCw }), onClick: () => window.location.reload(), children: "Refresh" }), (0, jsx_runtime_1.jsx)(react_2.Button, { size: "sm", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiDownload }), onClick: exportLogs, colorScheme: "blue", children: "Export" })] })] }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "sm", color: "gray.500", children: ["Showing ", filteredActivities.length, " of ", extendedActivities.length, " log entries"] })] }) }) }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 3, align: "stretch", children: [filteredActivities.map((activity) => {
                        const isExpanded = expandedLogs.has(activity.id);
                        const hasMetadata = activity.metadata && Object.keys(activity.metadata).length > 0;
                        return ((0, jsx_runtime_1.jsx)(react_2.Card, { bg: cardBg, borderColor: borderColor, size: "sm", children: (0, jsx_runtime_1.jsx)(react_2.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "stretch", spacing: 3, children: [(0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 3, align: "start", children: [(0, jsx_runtime_1.jsx)(react_2.Icon, { as: getActivityIcon(activity.type), color: getActivityColor(activity.type), mt: 1 }), (0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 1, flex: "1", children: [(0, jsx_runtime_1.jsxs)(react_2.HStack, { justify: "space-between", w: "full", children: [(0, jsx_runtime_1.jsxs)(react_2.HStack, { spacing: 2, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", fontWeight: "medium", children: activity.agentName }), (0, jsx_runtime_1.jsx)(react_2.Badge, { colorScheme: getTypeBadgeColor(activity.type), size: "sm", children: activity.type.replace('_', ' ') })] }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: "gray.500", children: new Date(activity.timestamp).toLocaleString() })] }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: "gray.700", _dark: { color: 'gray.300' }, children: activity.message }), hasMetadata && ((0, jsx_runtime_1.jsxs)(react_2.Button, { size: "xs", variant: "ghost", leftIcon: (0, jsx_runtime_1.jsx)(react_2.Icon, { as: isExpanded ? fi_1.FiChevronDown : fi_1.FiChevronRight }), onClick: () => toggleExpanded(activity.id), color: "gray.500", children: [isExpanded ? 'Hide' : 'Show', " Details"] }))] })] }), hasMetadata && ((0, jsx_runtime_1.jsx)(react_2.Collapse, { in: isExpanded, children: (0, jsx_runtime_1.jsxs)(react_2.Box, { pl: 8, pt: 2, borderLeft: `2px solid ${(0, react_2.useColorModeValue)('#E2E8F0', '#4A5568')}`, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", fontWeight: "medium", mb: 2, color: "gray.600", children: "Metadata:" }), (0, jsx_runtime_1.jsx)(react_2.Code, { fontSize: "xs", p: 2, borderRadius: "md", display: "block", whiteSpace: "pre-wrap", children: JSON.stringify(activity.metadata, null, 2) })] }) }))] }) }) }, activity.id));
                    }), filteredActivities.length === 0 && ((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.VStack, { spacing: 2, py: 8, children: [(0, jsx_runtime_1.jsx)(react_2.Icon, { as: fi_1.FiActivity, size: "32px", color: "gray.400" }), (0, jsx_runtime_1.jsx)(react_2.Text, { color: "gray.500", children: "No log entries match your filters" }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: "gray.400", children: "Try adjusting your search terms or filters" })] }) }) }))] })] }));
};
exports.AgentFleetLogs = AgentFleetLogs;
//# sourceMappingURL=AgentFleetLogs.js.map