"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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 DiscoveryImageForm_1 = tslib_1.__importDefault(require("../../clusterConfiguration/DiscoveryImageForm"));
const ModalDialogsContext_1 = require("../../hosts/ModalDialogsContext");
const Day2WizardContext_1 = require("./Day2WizardContext");
const Day2WizardNav_1 = tslib_1.__importDefault(require("./Day2WizardNav"));
const useInfraEnvImageUrl_1 = tslib_1.__importDefault(require("../../../hooks/useInfraEnvImageUrl"));
const useInfraEnvIpxeImageUrl_1 = tslib_1.__importDefault(require("../../../hooks/useInfraEnvIpxeImageUrl"));
const Day2GenerateISO = () => {
    const { day2DiscoveryImageDialog } = (0, ModalDialogsContext_1.useModalDialogsContext)();
    const { close, data } = day2DiscoveryImageDialog;
    const cluster = data.cluster;
    const wizardContext = (0, Day2WizardContext_1.useDay2WizardContext)();
    const { getIsoImageUrl } = (0, useInfraEnvImageUrl_1.default)();
    const { getIpxeImageUrl } = (0, useInfraEnvIpxeImageUrl_1.default)();
    const onImageReady = react_1.default.useCallback(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        const isoUrl = yield getIsoImageUrl(cluster.id, wizardContext.selectedCpuArchitecture);
        if (!isoUrl.error) {
            wizardContext.setSelectedIsoUrl(isoUrl.url);
            wizardContext.setSelectedIpxeUrl('');
            wizardContext.moveNext();
        }
    }), [cluster === null || cluster === void 0 ? void 0 : cluster.id, wizardContext, getIsoImageUrl]);
    const onImageIpxeReady = react_1.default.useCallback(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        const ipxeUrl = yield getIpxeImageUrl(cluster.id, wizardContext.selectedCpuArchitecture);
        if (!ipxeUrl.error) {
            wizardContext.setSelectedIpxeUrl(ipxeUrl.url);
            wizardContext.setSelectedIsoUrl('');
            wizardContext.moveNext();
        }
    }), [cluster === null || cluster === void 0 ? void 0 : cluster.id, wizardContext, getIpxeImageUrl]);
    return (react_1.default.createElement(common_1.ClusterWizardStep, { navigation: react_1.default.createElement(Day2WizardNav_1.default, null) },
        react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
            react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(common_1.ClusterWizardStepHeader, null, "Generate Discovery ISO")),
            react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(DiscoveryImageForm_1.default, { cluster: cluster, cpuArchitecture: wizardContext.selectedCpuArchitecture, onCancel: close, onSuccess: onImageReady, onSuccessIpxe: onImageIpxeReady, isIpxeSelected: wizardContext.selectedIpxeUrl !== '' })))));
};
exports.default = Day2GenerateISO;
//# sourceMappingURL=Day2GenerateISO.js.map