import React, { useEffect, useState } from "react";
import HiroGraphOrm from "@hiro-graph/orm";
import HiroGraphMappings from "@hiro-graph/orm-mappings";
import { useTokenDispatch, useToken } from "../stores/auth/hooks";
import { HiroAuthContext } from "../contexts";
export const HiroAuth = ({ config, children }) => {
    const { setToken } = useTokenDispatch();
    const currentToken = useToken();
    const [orm, setOrm] = useState();
    useEffect(() => {
        if (config.token) {
            setToken(config.token);
            setOrm(new HiroGraphOrm(config, HiroGraphMappings));
        }
    }, [config, setToken]);
    const value = {
        token: currentToken,
        orm
    };
    return (React.createElement(HiroAuthContext.Provider, { value: value }, children));
};
