"use strict";
/**
 * Hook for using Native AI plugin system in React components
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useNativeAI = useNativeAI;
const react_1 = require("react");
const index_js_1 = require("../services/native-ai/index.js");
/**
 * Hook for using the Native AI plugin system
 */
function useNativeAI(providerId) {
    // State for tracking initialization
    const [initialized, setInitialized] = (0, react_1.useState)(false);
    const [error, setError] = (0, react_1.useState)(null);
    const [loading, setLoading] = (0, react_1.useState)(false);
    // Initialize the plugin system
    (0, react_1.useEffect)(() => {
        const initializePlugins = async () => {
            try {
                setLoading(true);
                await index_js_1.nativeAiService.initialize();
                setInitialized(true);
                setError(null);
            }
            catch (err) {
                setError(err instanceof Error ? err : new Error('Failed to initialize Native AI'));
            }
            finally {
                setLoading(false);
            }
        };
        // Initialize if not already initialized
        if (!index_js_1.pluginManager.isInitialized()) {
            initializePlugins();
        }
        else {
            setInitialized(true);
        }
        // Cleanup on unmount
        return () => {
            // Don't shutdown the plugin system on unmount
            // as it might be used by other components
        };
    }, []);
    // Execute a chat completion request
    const chat = (0, react_1.useCallback)(async (request, options) => {
        if (!initialized) {
            throw new Error('Native AI not initialized');
        }
        // Set provider ID if provided
        const finalRequest = {
            ...request,
            provider: providerId || request.provider
        };
        return index_js_1.nativeAiService.chat(finalRequest, options);
    }, [initialized, providerId]);
    // Generate embeddings
    const embeddings = (0, react_1.useCallback)(async (texts, model) => {
        if (!initialized) {
            throw new Error('Native AI not initialized');
        }
        return index_js_1.nativeAiService.embeddings(texts, model, providerId);
    }, [initialized, providerId]);
    // Analyze document
    const analyzeDocument = (0, react_1.useCallback)(async (document, options) => {
        if (!initialized) {
            throw new Error('Native AI not initialized');
        }
        return index_js_1.nativeAiService.analyzeDocument(document, {
            ...options,
            providerId
        });
    }, [initialized, providerId]);
    // Generate RFP content
    const generateRFPContent = (0, react_1.useCallback)(async (rfpDocument, requirements) => {
        if (!initialized) {
            throw new Error('Native AI not initialized');
        }
        return index_js_1.nativeAiService.generateRFPContent(rfpDocument, requirements, providerId);
    }, [initialized, providerId]);
    // Generate compliance report
    const generateComplianceReport = (0, react_1.useCallback)(async (requirements, implementationDetails) => {
        if (!initialized) {
            throw new Error('Native AI not initialized');
        }
        return index_js_1.nativeAiService.generateComplianceReport(requirements, implementationDetails, providerId);
    }, [initialized, providerId]);
    // Get all available plugins
    const getPlugins = (0, react_1.useCallback)(() => {
        return index_js_1.nativeAiService.getPlugins();
    }, []);
    // Register a new plugin
    const registerPlugin = (0, react_1.useCallback)(async (plugin) => {
        return index_js_1.nativeAiService.registerPlugin(plugin);
    }, []);
    return {
        initialized,
        loading,
        error,
        chat,
        embeddings,
        analyzeDocument,
        generateRFPContent,
        generateComplianceReport,
        getPlugins,
        registerPlugin
    };
}
exports.default = useNativeAI;
//# sourceMappingURL=useNativeAI.js.map