"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSupportLevelInfo = exports.getFeatureSupportLevelTitle = exports.FullySupportedCluster = exports.LimitedSupportedCluster = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const check_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/check-circle-icon");
const info_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/info-circle-icon");
const react_core_1 = require("@patternfly/react-core");
const types_1 = require("../../../common/types");
const docs_links_1 = require("../../../common/config/docs_links");
const ExternalLink_1 = tslib_1.__importDefault(require("../../../common/components/ui/ExternalLink"));
const common_1 = require("../../../common");
const utils_1 = require("../../../common/components/newFeatureSupportLevels/utils");
const WithErrorBoundary_1 = require("../../../common/components/ErrorHandling/WithErrorBoundary");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const OpenShiftVersionsContext_1 = require("../clusterWizard/OpenShiftVersionsContext");
const newFeatureSupportLevels_1 = require("../../../common/components/newFeatureSupportLevels");
const use_feature_1 = require("../../hooks/use-feature");
const getFeatureReviewText = (featureId) => {
    switch (featureId) {
        case 'SNO':
            return 'Install single node OpenShift (SNO)';
        case 'VIP_AUTO_ALLOC':
            return 'Allocate IPs via DHCP server';
        case 'ARM64_ARCHITECTURE':
            return 'Use ARM architecture for the cluster';
        default:
            return featureId;
    }
};
const getPreviewSupportLevelTitle = (supportLevel) => {
    if (supportLevel === 'dev-preview') {
        return 'Developer Preview Features';
    }
    return react_1.default.createElement(ExternalLink_1.default, { href: docs_links_1.TECH_SUPPORT_LEVEL_LINK }, "Technology Preview Features");
};
const getPreviewFeatureList = (supportLevelMap) => {
    const previewSupportLevels = {
        'tech-preview': [],
        'dev-preview': [],
    };
    for (const [featureId, supportLevel] of Object.entries(supportLevelMap)) {
        if (!(0, types_1.isPreviewSupportLevel)(supportLevel)) {
            continue;
        }
        previewSupportLevels[supportLevel].push(featureId);
    }
    let supportLevel;
    //Show only one preview support level list, first priority to developer preview features
    if (previewSupportLevels['dev-preview'].length) {
        supportLevel = 'dev-preview';
    }
    else if (previewSupportLevels['tech-preview'].length) {
        supportLevel = 'tech-preview';
    }
    else {
        return null;
    }
    const featureList = previewSupportLevels[supportLevel].map((featureId) => (react_1.default.createElement(react_core_1.Content, { component: "li", key: featureId }, getFeatureReviewText(featureId))));
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Content, { component: "li" },
            getPreviewSupportLevelTitle(supportLevel),
            react_1.default.createElement(react_core_1.Content, { component: "ul" }, featureList))));
};
const LimitedSupportedCluster = ({ clusterFeatureSupportLevels, showVersionWarning, }) => (react_1.default.createElement(react_1.default.Fragment, null,
    showVersionWarning && (react_1.default.createElement(react_core_1.Content, { component: "p" },
        react_1.default.createElement(react_core_1.Icon, { status: "info", size: "sm" },
            react_1.default.createElement(info_circle_icon_1.InfoCircleIcon, null)),
        "\u00A0The installed OpenShift version is not production-ready")),
    Object.keys(clusterFeatureSupportLevels).length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Icon, { status: "info", size: "sm" },
            react_1.default.createElement(info_circle_icon_1.InfoCircleIcon, null)),
        "\u00A0Your cluster will be subject to support limitations because it includes:",
        react_1.default.createElement(react_core_1.Content, { component: "ul" }, getPreviewFeatureList(clusterFeatureSupportLevels))))));
exports.LimitedSupportedCluster = LimitedSupportedCluster;
const FullySupportedCluster = () => (react_1.default.createElement(react_1.default.Fragment, null,
    react_1.default.createElement(react_core_1.Icon, { status: "success" },
        react_1.default.createElement(check_circle_icon_1.CheckCircleIcon, null)),
    "\u00A0Your installed cluster will be fully supported"));
exports.FullySupportedCluster = FullySupportedCluster;
const getFeatureSupportLevelTitle = (fullySupported) => {
    const supportLevel = fullySupported ? 'Full' : 'Limited';
    return `Cluster support level: ${supportLevel}`;
};
exports.getFeatureSupportLevelTitle = getFeatureSupportLevelTitle;
const getSupportLevelInfo = (cluster, featureSupportLevelData, isSupportedOpenShiftVersion, t, isSingleClusterFeatureEnabled) => {
    const limitedClusterFeatures = (0, utils_1.getLimitedFeatureSupportLevels)(cluster, featureSupportLevelData, t);
    const hasSupportedVersion = isSupportedOpenShiftVersion(cluster.openshiftVersion);
    return {
        limitedClusterFeatures,
        hasSupportedVersion,
        isFullySupported: hasSupportedVersion &&
            Object.keys(limitedClusterFeatures || {}).length === 0 &&
            !isSingleClusterFeatureEnabled,
    };
};
exports.getSupportLevelInfo = getSupportLevelInfo;
const SupportLevel = ({ cluster }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const featureSupportLevelData = (0, newFeatureSupportLevels_1.useNewFeatureSupportLevel)();
    const { isSupportedOpenShiftVersion } = (0, OpenShiftVersionsContext_1.useOpenShiftVersionsContext)();
    const isSingleClusterFeatureEnabled = (0, use_feature_1.useFeature)('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
    const { limitedClusterFeatures, hasSupportedVersion, isFullySupported } = react_1.default.useMemo(() => (0, exports.getSupportLevelInfo)(cluster, featureSupportLevelData, isSupportedOpenShiftVersion, t, isSingleClusterFeatureEnabled), [
        cluster,
        featureSupportLevelData,
        t,
        isSupportedOpenShiftVersion,
        isSingleClusterFeatureEnabled,
    ]);
    if (!limitedClusterFeatures) {
        return null;
    }
    return (react_1.default.createElement(common_1.DetailItem, { title: (0, exports.getFeatureSupportLevelTitle)(isFullySupported), value: isFullySupported ? (react_1.default.createElement(exports.FullySupportedCluster, null)) : (react_1.default.createElement(exports.LimitedSupportedCluster, { clusterFeatureSupportLevels: limitedClusterFeatures, showVersionWarning: !hasSupportedVersion || isSingleClusterFeatureEnabled })), classNameValue: 'pf-v6-u-mb-md', testId: "feature-support-levels" }));
};
const ClusterFeatureSupportLevelsDetailItem = (_a) => {
    var props = tslib_1.__rest(_a, []);
    return (react_1.default.createElement(WithErrorBoundary_1.WithErrorBoundary, { title: "Failed to load feature support levels" },
        react_1.default.createElement(SupportLevel, Object.assign({}, props))));
};
exports.default = ClusterFeatureSupportLevelsDetailItem;
//# sourceMappingURL=ReviewClusterFeatureSupportLevels.js.map