import URL from "../../Types/API/URL";
import HTTPErrorResponse from "../../Types/API/HTTPErrorResponse";
import API from "../../Utils/API";
import { APP_API_URL } from "../Config";
class GlobalConfigUtil {
    static async fetchVars() {
        if (GlobalConfigUtil.cache) {
            return GlobalConfigUtil.cache;
        }
        if (GlobalConfigUtil.fetchPromise) {
            return GlobalConfigUtil.fetchPromise;
        }
        GlobalConfigUtil.fetchPromise = (async () => {
            const apiUrl = URL.fromURL(APP_API_URL).addRoute("/global-config/vars");
            const response = await API.get({ url: apiUrl });
            const data = response instanceof HTTPErrorResponse
                ? {}
                : response.data;
            GlobalConfigUtil.cache = {
                disableUserProjectCreation: Boolean(data["disableUserProjectCreation"]),
            };
            return GlobalConfigUtil.cache;
        })();
        try {
            return await GlobalConfigUtil.fetchPromise;
        }
        finally {
            GlobalConfigUtil.fetchPromise = null;
        }
    }
    static clearCache() {
        GlobalConfigUtil.cache = null;
    }
}
GlobalConfigUtil.cache = null;
GlobalConfigUtil.fetchPromise = null;
export default GlobalConfigUtil;
//# sourceMappingURL=GlobalConfig.js.map