var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import React, { useContext, useEffect, useState } from 'react';
import { CyberClient } from '@cybercongress/cyber-js';
import { useQuery } from '@tanstack/react-query';
const QueryClientContext = React.createContext(undefined);
export function useQueryClient() {
    return useContext(QueryClientContext);
}
function QueryClientProvider({ children }) {
    const [cyber, setCyber] = useState();
    useEffect(() => {
        (() => __awaiter(this, void 0, void 0, function* () {
            const cyber = (yield import('./config')).CYBER;
            console.log("useEffect queryClient", cyber);
            setCyber(cyber);
        }))();
    }, []);
    const { data, error, isFetching } = useQuery({
        queryKey: ['cyberClient', 'connect'],
        queryFn: () => __awaiter(this, void 0, void 0, function* () {
            const cyber = (yield import('./config')).CYBER;
            console.log("useQuery queryClient", cyber);
            return CyberClient.connect(cyber.CYBER_NODE_URL_API);
        }),
    });
    if (isFetching) {
        return null;
    }
    if (error) {
        return React.createElement("span", null,
            "Error queryClient connect: ", error === null || error === void 0 ? void 0 :
            error.message);
    }
    return (React.createElement(QueryClientContext.Provider, { value: data }, children));
}
export default QueryClientProvider;
//# sourceMappingURL=queryClient.js.map