import { jsx as _jsx } from "react/jsx-runtime";
import { LiFi } from '@lifi/sdk';
import { createContext, useContext, useMemo } from 'react';
import { version } from '../../config/version';
import { useWidgetConfig } from '../WidgetProvider';
let lifi;
const SDKContext = createContext(null);
export const useLiFi = () => useContext(SDKContext);
export const SDKProvider = ({ children, }) => {
    const { sdkConfig, fee, integrator, referrer, routePriority, slippage } = useWidgetConfig();
    const value = useMemo(() => {
        const config = {
            ...sdkConfig,
            integrator: integrator ?? window.location.hostname,
            defaultRouteOptions: {
                fee,
                integrator: integrator ?? window.location.hostname,
                referrer,
                routePriority,
                slippage,
                ...sdkConfig?.defaultRouteOptions,
            },
        };
        if (!lifi) {
            lifi = new LiFi({
                disableVersionCheck: true,
                widgetVersion: version,
                ...config,
            });
        }
        lifi.setConfig(config);
        return lifi;
    }, [fee, integrator, referrer, routePriority, sdkConfig, slippage]);
    return _jsx(SDKContext.Provider, { value: value, children: children });
};
