"use strict";
/**
 * useQuantumSwarm.ts
 *
 * React hook for interacting with the Quantum Swarm Orchestrator API.
 * Provides access to the quantum swarm client and common operations.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useQuantumSwarm = useQuantumSwarm;
const react_1 = require("react");
const index_js_1 = __importDefault(require("./index.js"));
/**
 * React hook for interacting with the Quantum Swarm Orchestrator
 *
 * @param options Configuration options for the quantum swarm client
 * @returns Object containing the client, data, loading states, errors, and methods
 */
function useQuantumSwarm(options = {}) {
    const { autoInitialize = true, ...clientOptions } = options;
    // Initialize the client
    const client = new index_js_1.default(clientOptions);
    // State for data
    const [agents, setAgents] = (0, react_1.useState)([]);
    const [workflows, setWorkflows] = (0, react_1.useState)([]);
    const [insights, setInsights] = (0, react_1.useState)([]);
    // State for loading
    const [loading, setLoading] = (0, react_1.useState)({
        agents: false,
        workflows: false,
        insights: false,
    });
    // State for errors
    const [error, setError] = (0, react_1.useState)({
        agents: null,
        workflows: null,
        insights: null,
    });
    // Fetch agents
    const fetchAgents = (0, react_1.useCallback)(async () => {
        setLoading(prev => ({ ...prev, agents: true }));
        setError(prev => ({ ...prev, agents: null }));
        try {
            // In a real implementation, we would fetch agents from the server
            // For now, we'll simulate it with an empty array
            setAgents([]);
        }
        catch (err) {
            setError(prev => ({ ...prev, agents: err }));
        }
        finally {
            setLoading(prev => ({ ...prev, agents: false }));
        }
    }, []);
    // Fetch workflows
    const fetchWorkflows = (0, react_1.useCallback)(async () => {
        setLoading(prev => ({ ...prev, workflows: true }));
        setError(prev => ({ ...prev, workflows: null }));
        try {
            // In a real implementation, we would fetch workflows from the server
            // For now, we'll simulate it with an empty array
            setWorkflows([]);
        }
        catch (err) {
            setError(prev => ({ ...prev, workflows: err }));
        }
        finally {
            setLoading(prev => ({ ...prev, workflows: false }));
        }
    }, []);
    // Fetch workflow insights
    const fetchWorkflowInsights = (0, react_1.useCallback)(async (workflowId) => {
        setLoading(prev => ({ ...prev, insights: true }));
        setError(prev => ({ ...prev, insights: null }));
        try {
            const workflowInsights = await client.getWorkflowInsights(workflowId);
            setInsights(workflowInsights);
        }
        catch (err) {
            setError(prev => ({ ...prev, insights: err }));
        }
        finally {
            setLoading(prev => ({ ...prev, insights: false }));
        }
    }, [client]);
    // Create agent
    const createAgent = (0, react_1.useCallback)(async (agent) => {
        // Generate a unique ID for the agent
        const uniqueId = `agent-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
        const newAgent = await client.registerAgent({
            id: uniqueId,
            ...agent,
        });
        setAgents(prev => [...prev, newAgent]);
        return newAgent;
    }, [client]);
    // Create workflow
    const createWorkflow = (0, react_1.useCallback)(async (name, description, agentIds = [], specializationAreas = []) => {
        const workflow = await client.createCognitiveWorkflow(name, description, agentIds, specializationAreas);
        setWorkflows(prev => [...prev, workflow]);
        return workflow;
    }, [client]);
    // Contribute insight
    const contributeInsight = (0, react_1.useCallback)(async (workflowId, agentId, insightType, insightContent, confidence = 0.7) => {
        const insight = await client.contributeInsight(workflowId, agentId, insightType, insightContent, confidence);
        setInsights(prev => [...prev, insight]);
        return insight;
    }, [client]);
    // Initiate consensus
    const initiateConsensus = (0, react_1.useCallback)(async (workflowId, topic) => {
        return client.initiateConsensus(workflowId, topic);
    }, [client]);
    // Specialize agent
    const specializeAgent = (0, react_1.useCallback)(async (agentId, specializations) => {
        const agent = await client.specializeAgent(agentId, specializations);
        setAgents(prev => prev.map(a => a.id === agentId ? agent : a));
        return agent;
    }, [client]);
    // Auto-initialize
    (0, react_1.useEffect)(() => {
        if (autoInitialize) {
            fetchAgents();
            fetchWorkflows();
        }
    }, [autoInitialize, fetchAgents, fetchWorkflows]);
    return {
        client,
        agents,
        workflows,
        insights,
        loading,
        error,
        fetchAgents,
        fetchWorkflows,
        fetchWorkflowInsights,
        createAgent,
        createWorkflow,
        contributeInsight,
        initiateConsensus,
        specializeAgent,
    };
}
exports.default = useQuantumSwarm;
//# sourceMappingURL=useQuantumSwarm.js.map