"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSupportedOCPVersions = exports.getSupportedCM = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const helpers_1 = require("../../helpers");
const getSupportedCM = (configMaps) => configMaps.find((cm) => { var _a, _b; return ((_b = (_a = cm.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['hypershift.openshift.io/supported-versions']) === 'true'; });
exports.getSupportedCM = getSupportedCM;
const useSupportedOCPVersions = (clusterImages, supportedVersionsCM, extended) => {
    return React.useMemo(() => {
        var _a;
        const ocpVersions = (0, helpers_1.getOCPVersions)(clusterImages, false, undefined, extended);
        const supportedVersionsString = (_a = supportedVersionsCM === null || supportedVersionsCM === void 0 ? void 0 : supportedVersionsCM.data) === null || _a === void 0 ? void 0 : _a['supported-versions'];
        if (supportedVersionsString) {
            try {
                const supportedVersions = JSON.parse(supportedVersionsString)
                    .versions;
                return ocpVersions.filter((v) => supportedVersions.find((sv) => v.version.startsWith(sv)));
            }
            catch (err) {
                // console.error('Could not parse supported versions config map value.', getErrorMessage(err));
            }
        }
        return ocpVersions;
    }, [clusterImages, extended, supportedVersionsCM === null || supportedVersionsCM === void 0 ? void 0 : supportedVersionsCM.data]);
};
exports.useSupportedOCPVersions = useSupportedOCPVersions;
//# sourceMappingURL=useSupportedOCPVersions.js.map