import React, { useEffect, useState, useCallback } from "react";
import { HiroGraphContext } from "../contexts";
const ME_POLL = 30000;
export const HiroGraph = ({ orm, children }) => {
    const [me, setMe] = useState();
    const getMe = useCallback(() => orm &&
        orm
            .me()
            .then(newMe => void setMe(newMe))
            .catch(() => {
            if (process.env && process.env.NODE_ENV === "development") {
                if (!window.sessionStorage.getItem("access_token")) {
                    return;
                }
                window.sessionStorage.removeItem("access_token");
                window.location.reload();
            }
        }), [orm]);
    useEffect(() => {
        getMe();
        const i = setInterval(() => {
            getMe();
        }, ME_POLL);
        return () => clearInterval(i);
    }, [getMe]);
    const value = {
        orm,
        me
    };
    return (React.createElement(HiroGraphContext.Provider, { value: value }, children));
};
