"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostsClusterDetailTabMock = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const HostsClusterDetailTab_1 = tslib_1.__importDefault(require("./HostsClusterDetailTab"));
const ClustersAPI_1 = tslib_1.__importDefault(require("../../../common/api/assisted-service/ClustersAPI"));
const OpenShiftVersionsContext_1 = require("../clusterWizard/OpenShiftVersionsContext");
const clusterWithoutMetrics = {
    id: 'ocm-cluster-id',
    external_id: 'day2flow-day1-ai-cluster-id',
    openshift_version: '4.12',
    cpu_architecture: common_1.OcmCpuArchitecture.x86,
    name: 'day2-flow',
};
const clusterWithMetrics = Object.assign(Object.assign({}, clusterWithoutMetrics), { metrics: { nodes: { total: 3 } }, api: { url: 'https://console-openshift-console.apps.day2-flow.redhat.com' } });
const getCluster = (type) => {
    switch (type) {
        case 'no-metrics':
            return clusterWithoutMetrics;
        case 'with-metrics':
        default:
            return clusterWithMetrics;
    }
};
const HostsClusterDetailTabMock = () => {
    const [tabShown, setTabShown] = react_1.default.useState('');
    const [isMocked, setIsMocked] = react_1.default.useState(false);
    react_1.default.useEffect(() => {
        const checkMockedClusterLoads = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            try {
                yield ClustersAPI_1.default.get('day2flow-day1-ai-cluster-id');
                setIsMocked(true);
            }
            catch (e) {
                setIsMocked(false);
            }
        });
        void checkMockedClusterLoads();
    }, []);
    const onAddHosts = (whichCase) => {
        if (!tabShown) {
            setTabShown(whichCase);
        }
    };
    if (!isMocked) {
        return (react_1.default.createElement(react_core_1.PageSection, { hasBodyWrapper: false, isFilled: true },
            react_1.default.createElement(react_core_1.EmptyState, { headingLevel: "h4", titleText: "Mocked environment not detected" },
                react_1.default.createElement(react_core_1.EmptyStateBody, null, "You can only use this page on a mocked environment"))));
    }
    return (react_1.default.createElement(react_core_1.PageSection, { hasBodyWrapper: false, isFilled: true }, tabShown ? (react_1.default.createElement(OpenShiftVersionsContext_1.OpenShiftVersionsContextProvider, null,
        react_1.default.createElement(HostsClusterDetailTab_1.default, { cluster: getCluster(tabShown), allEnabledFeatures: common_1.STANDALONE_DEPLOYMENT_ENABLED_FEATURES, isVisible: true }))) : (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
        react_1.default.createElement(common_1.ToolbarButton, { variant: react_core_1.ButtonVariant.primary, onClick: () => onAddHosts('no-metrics') }, "Add hosts (No metrics)"),
        react_1.default.createElement(common_1.ToolbarButton, { variant: react_core_1.ButtonVariant.primary, onClick: () => onAddHosts('with-metrics') }, "Add hosts (With metrics)")))));
};
exports.HostsClusterDetailTabMock = HostsClusterDetailTabMock;
//# sourceMappingURL=HostsClusterDetailTabMock.js.map