"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 resize_observer_1 = tslib_1.__importDefault(require("@react-hook/resize-observer"));
const common_1 = require("../../../../common");
const helpers_1 = require("../../helpers");
const MinimalHWRequirements_1 = tslib_1.__importDefault(require("../../Agent/MinimalHWRequirements"));
const modals_1 = require("../../modals");
const ClusterDeploymentHostDiscoveryTable_1 = tslib_1.__importDefault(require("./ClusterDeploymentHostDiscoveryTable"));
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const AddHostDropdown_1 = tslib_1.__importDefault(require("../../InfraEnv/AddHostDropdown"));
const DiscoveryInstructions = () => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Content, { component: "h3" }, t('ai:Adding hosts instructions')),
        react_1.default.createElement(react_core_1.Content, { component: "ol", type: react_core_1.OrderType.number, style: { marginLeft: 0 } },
            react_1.default.createElement(react_core_1.Content, { component: "li" }, t('ai:Click the Add hosts button.')),
            react_1.default.createElement(react_core_1.Content, { component: "li" }, t('ai:Configure the SSH key and proxy settings after the modal appears (optional).')),
            react_1.default.createElement(react_core_1.Content, { component: "li" }, t("ai:Select how you'd like to add hosts (Discovery ISO, iPXE, or BMC form) and follow the instructions that appear.")),
            react_1.default.createElement(react_core_1.Content, { component: "li" }, t('ai:Booted hosts should appear in the host inventory table. This may take a few minutes.')))));
};
const ClusterDeploymentHostsDiscovery = (_a) => {
    var { agentClusterInstall, agents, bareMetalHosts, aiConfigMap, infraEnv, infraNMStates, usedHostnames, onChangeHostname, onEditRole, onSetInstallationDiskId, onSaveBMH, fetchSecret, onChangeBMHHostname, onApproveAgent, onDeleteHost } = _a, rest = tslib_1.__rest(_a, ["agentClusterInstall", "agents", "bareMetalHosts", "aiConfigMap", "infraEnv", "infraNMStates", "usedHostnames", "onChangeHostname", "onEditRole", "onSetInstallationDiskId", "onSaveBMH", "fetchSecret", "onChangeBMHHostname", "onApproveAgent", "onDeleteHost"]);
    const [isDiscoveryHintModalOpen, setDiscoveryHintModalOpen] = react_1.default.useState(false);
    const [editBMH, setEditBMH] = react_1.default.useState();
    const [editAgent, setEditAgent] = react_1.default.useState();
    const isVM = true; // TODO(mlibra): calculate from agent's inventory
    const isSNOCluster = (0, helpers_1.getIsSNOCluster)(agentClusterInstall);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const tableRef = react_1.default.useRef(null);
    const [tableWidth, setTableWidth] = react_1.default.useState();
    (0, resize_observer_1.default)(tableRef, (entry) => {
        setTableWidth(entry.contentRect.width);
    });
    return (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
        react_1.default.createElement(react_core_1.GridItem, null,
            react_1.default.createElement(DiscoveryInstructions, null)),
        react_1.default.createElement(react_core_1.GridItem, { span: 5 },
            react_1.default.createElement(AddHostDropdown_1.default, Object.assign({ infraEnv: infraEnv, agentClusterInstall: agentClusterInstall, usedHostnames: usedHostnames }, rest))),
        react_1.default.createElement(react_core_1.GridItem, null,
            react_1.default.createElement(react_core_1.Content, null,
                react_1.default.createElement(react_core_1.Content, { component: "h3" }, t('ai:Information and warnings')),
                aiConfigMap && (react_1.default.createElement(react_core_1.Content, { component: "p" },
                    react_1.default.createElement(MinimalHWRequirements_1.default, { aiConfigMap: aiConfigMap, isSNOCluster: isSNOCluster }))),
                react_1.default.createElement(react_core_1.Content, { component: "p" },
                    react_1.default.createElement(common_1.HostsNotShowingLink, { setDiscoveryHintModalOpen: setDiscoveryHintModalOpen })),
                isVM && react_1.default.createElement(common_1.VMRebootConfigurationInfo, null))),
        react_1.default.createElement(react_core_1.GridItem, null,
            react_1.default.createElement(common_1.FormatDiskWarning, null)),
        react_1.default.createElement(react_core_1.GridItem, null,
            react_1.default.createElement("div", { ref: tableRef },
                react_1.default.createElement(ClusterDeploymentHostDiscoveryTable_1.default, { agents: agents, bareMetalHosts: bareMetalHosts, infraEnv: infraEnv, onEditHost: setEditAgent, onEditRole: onEditRole, onSetInstallationDiskId: onSetInstallationDiskId, onEditBMH: setEditBMH, onChangeHostname: onChangeHostname, onChangeBMHHostname: onChangeBMHHostname, onApprove: onApproveAgent, width: tableWidth, onDeleteHost: onDeleteHost })),
            react_1.default.createElement(modals_1.EditBMHModal, { infraEnv: infraEnv, bmh: editBMH, nmStates: infraNMStates, isOpen: !!editBMH, onClose: () => setEditBMH(undefined), onEdit: onSaveBMH, fetchSecret: fetchSecret, usedHostnames: usedHostnames || [] }),
            editAgent && (react_1.default.createElement(modals_1.EditAgentModal, { onClose: () => setEditAgent(undefined), usedHostnames: usedHostnames, agent: editAgent, onSave: (0, helpers_1.onAgentChangeHostname)(agents, bareMetalHosts, onChangeHostname, onChangeBMHHostname) }))),
        react_1.default.createElement(common_1.DiscoveryTroubleshootingModal, { isOpen: isDiscoveryHintModalOpen, setDiscoveryHintModalOpen: setDiscoveryHintModalOpen })));
};
exports.default = ClusterDeploymentHostsDiscovery;
//# sourceMappingURL=ClusterDeploymentHostsDiscovery.js.map