"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAppVersionBlockCheck = void 0;
const semver_1 = __importDefault(require("semver"));
const LiveConfig_1 = require("@ledgerhq/live-config/LiveConfig");
const useAppVersionBlockCheck = ({ appVersion: uncoercedAppVersion, appKey, platform, osVersion, getConfigValue = LiveConfig_1.LiveConfig.getValueByKey, }) => {
    const llMinVersionConfig = getConfigValue("config_ll_min_version");
    const appVersion = semver_1.default.coerce(uncoercedAppVersion)?.version || "";
    let shouldUpdate = false;
    if (!llMinVersionConfig || !llMinVersionConfig[appKey][platform]) {
        return { shouldUpdate };
    }
    if (appKey === "llm" && (platform === "android" || platform === "ios") && osVersion) {
        shouldUpdate = llMinVersionConfig[appKey][platform]
            .filter(minVersionConfig => semver_1.default.satisfies(semver_1.default.coerce(osVersion), `>=${minVersionConfig.minOsVersion}`))
            .reduce((acc, curr) => {
            return acc || semver_1.default.satisfies(appVersion, `<${semver_1.default.coerce(curr.version)}`);
        }, false);
    }
    else if (appKey === "lld" &&
        (platform === "windows" || platform === "macOS" || platform === "linux")) {
        shouldUpdate = semver_1.default.satisfies(appVersion, `<${semver_1.default.coerce(llMinVersionConfig[appKey][platform])}`);
    }
    return { shouldUpdate };
};
exports.useAppVersionBlockCheck = useAppVersionBlockCheck;
//# sourceMappingURL=useAppVersionBlockCheck.js.map