"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useOFACGeoBlockCheck = void 0;
const react_1 = require("react");
const featureFlags_1 = require("../featureFlags");
const react_query_1 = require("@tanstack/react-query");
const live_env_1 = require("@ledgerhq/live-env");
const baseURL = () => (0, live_env_1.getEnv)("LEDGER_COUNTERVALUES_API");
const useOFACGeoBlockCheck = ({ onFinish, geoBlockingFeatureFlagKey, }) => {
    const [blocked, setBlocked] = (0, react_1.useState)(false);
    const platformOfacGeoBlocking = (0, featureFlags_1.useFeature)(geoBlockingFeatureFlagKey);
    const { data, isLoading } = (0, react_query_1.useQuery)({
        queryKey: ["ofac-geo-block", geoBlockingFeatureFlagKey],
        queryFn: async () => {
            if (!platformOfacGeoBlocking?.enabled)
                return false;
            const res = await fetch(`${baseURL()}/v3/markets`);
            return res.status === 451;
        },
    });
    (0, react_1.useEffect)(() => {
        if (!platformOfacGeoBlocking?.enabled)
            return;
        setBlocked(data ?? false);
        if (typeof onFinish === "function") {
            onFinish();
        }
    }, [data, onFinish, platformOfacGeoBlocking]);
    return { blocked, isLoading };
};
exports.useOFACGeoBlockCheck = useOFACGeoBlockCheck;
//# sourceMappingURL=useOFACGeoBlockCheck.js.map