"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.VectorSearch = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const framer_motion_1 = require("framer-motion");
const react_query_1 = require("@tanstack/react-query");
const js_client_rest_1 = require("@qdrant/js-client-rest");
exports.VectorSearch = react_1.default.memo(({ qdrantUrl, collectionName, onResultSelect }) => {
    const [query, setQuery] = (0, react_1.useState)('');
    const [results, setResults] = (0, react_1.useState)([]);
    const qdrantClient = new js_client_rest_1.QdrantClient({ url: qdrantUrl });
    const searchVectors = async (searchQuery) => {
        if (!searchQuery)
            return [];
        const searchResult = await qdrantClient.search(collectionName, {
            vector: await generateEmbedding(searchQuery),
            limit: 10
        });
        return searchResult;
    };
    const { data, isLoading } = (0, react_query_1.useQuery)({
        queryKey: ['vectorSearch', query],
        queryFn: () => searchVectors(query),
        enabled: query.length > 2
    });
    return ((0, jsx_runtime_1.jsxs)("div", { className: "vector-search-container", children: [(0, jsx_runtime_1.jsxs)("div", { className: "search-input-wrapper", children: [(0, jsx_runtime_1.jsx)("input", { type: "text", value: query, onChange: (e) => setQuery(e.target.value), placeholder: "Search vectors...", className: "vector-search-input", "aria-label": "Vector search input" }), isLoading && (0, jsx_runtime_1.jsx)("div", { className: "loading-spinner", "aria-live": "polite", children: "Searching..." })] }), (0, jsx_runtime_1.jsx)("div", { className: "search-results", role: "list", "aria-label": "Search results", children: data?.map((result, index) => ((0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { delay: index * 0.05 }, className: "search-result-item", role: "listitem", onClick: () => onResultSelect?.(result), children: [(0, jsx_runtime_1.jsxs)("div", { className: "similarity-score", children: [(result.score * 100).toFixed(2), "%"] }), (0, jsx_runtime_1.jsx)("div", { className: "result-content", children: result.payload?.text || 'No content' })] }, result.id))) })] }));
});
async function generateEmbedding(text) {
    // This would call your embedding service
    // For demo, returning mock embedding
    return Array(384).fill(0).map(() => Math.random());
}
//# sourceMappingURL=VectorSearch.js.map