"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const React = tslib_1.__importStar(require("react"));
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const modals_1 = require("../modals");
require("./AddHostDropdown.css");
const react_i18next_1 = require("react-i18next");
const react_router_dom_v5_compat_1 = require("react-router-dom-v5-compat");
const outlined_question_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/outlined-question-circle-icon");
const DropdownItemWithLoading = (props) => {
    return (React.createElement(react_core_1.DropdownItem, Object.assign({}, props, { isDisabled: props.isDisabled || props.isLoading }),
        React.createElement(react_core_1.Split, { hasGutter: true },
            React.createElement(react_core_1.SplitItem, null, props.label),
            props.isLoading && (React.createElement(react_core_1.SplitItem, null,
                React.createElement(react_core_1.Spinner, { size: "sm" }))))));
};
const AddHostDropdown = ({ infraEnv, agentClusterInstall, onSaveISOParams, usedHostnames, onCreateBMH, docVersion, onCreateBmcByYaml, provisioningConfigResult, }) => {
    const [addModalType, setAddModalType] = React.useState(undefined);
    const [isKebabOpen, setIsKebabOpen] = React.useState(false);
    const [provisioningConfig, provisioningConfigLoaded, provisioningConfigError] = provisioningConfigResult;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (React.createElement(React.Fragment, null,
        React.createElement(react_core_1.Dropdown, { id: "infraenv-actions", isOpen: isKebabOpen, onSelect: () => setIsKebabOpen(false), onOpenChange: () => setIsKebabOpen(!isKebabOpen), toggle: (toggleRef) => (React.createElement(react_core_1.MenuToggle, { id: "dropdown-basic", variant: "primary", ref: toggleRef, onClick: () => setIsKebabOpen(!isKebabOpen), isExpanded: isKebabOpen }, t('ai:Add hosts'))), shouldFocusToggleOnSelect: true, popperProps: { preventOverflow: true } }, [
            React.createElement(react_core_1.DropdownItem, { key: "discovery-iso", onClick: () => {
                    setIsKebabOpen(false);
                    setAddModalType('iso');
                }, description: t('ai:Discover hosts by booting a discovery image') }, t('ai:With Discovery ISO')),
            React.createElement(react_core_1.DropdownItem, { key: "ipxe", onClick: () => {
                    setIsKebabOpen(false);
                    setAddModalType('ipxe');
                }, description: t('ai:Use when you have an iPXE server that has already been set up') }, t('ai:With iPXE')),
            React.createElement(react_core_1.Divider, { component: "li", key: "separator" }),
            React.createElement(react_core_1.DropdownList, { id: "discovery-bmc", key: "discovery-bmc", className: "ai-discovery-bmc__group" },
                !provisioningConfig && (React.createElement(react_core_1.DropdownItem, { isAriaDisabled: true, className: "pf-v6-u-color-200" // visually muted
                    , component: "div" },
                    React.createElement(react_core_1.Flex, { alignItems: { default: 'alignItemsCenter' }, spaceItems: { default: 'spaceItemsMd' } },
                        React.createElement("span", null, t('ai:Baseboard Management Controller (BMC)')),
                        React.createElement(react_core_1.Popover, { triggerAction: "hover", position: "top", bodyContent: React.createElement(react_i18next_1.Trans, { t: t },
                                "ai:To enable the host's baseboard management controller (BMC) on the hub cluster, you must first",
                                ' ',
                                React.createElement(react_router_dom_v5_compat_1.Link, { to: "/k8s/cluster/metal3.io~v1alpha1~Provisioning/~new" }, "create a provisioning configuration.")) },
                            React.createElement(outlined_question_circle_icon_1.OutlinedQuestionCircleIcon, null))))),
                React.createElement(DropdownItemWithLoading, { key: "with-credentials", onClick: () => {
                        setIsKebabOpen(false);
                        setAddModalType('bmc');
                    }, description: t('ai:Discover a single host via Baseboard Management Controller'), label: t('ai:With BMC form'), isLoading: !provisioningConfigLoaded, isDisabled: !provisioningConfig && !provisioningConfigError }),
                React.createElement(DropdownItemWithLoading, { key: "upload-yaml", onClick: () => {
                        setIsKebabOpen(false);
                        setAddModalType('yaml');
                    }, description: t('ai:Discover multiple hosts by providing yaml with Bare Metal Host definitions'), label: t('ai:By uploading a YAML'), isLoading: !provisioningConfigLoaded, isDisabled: !provisioningConfig && !provisioningConfigError })),
        ]),
        addModalType === 'iso' && (React.createElement(modals_1.AddHostModal, { infraEnv: infraEnv, agentClusterInstall: agentClusterInstall, isOpen: true, onClose: () => setAddModalType(undefined), onSaveISOParams: onSaveISOParams, docVersion: docVersion })),
        addModalType === 'ipxe' && (React.createElement(modals_1.AddHostModal, { infraEnv: infraEnv, agentClusterInstall: agentClusterInstall, isOpen: true, onClose: () => setAddModalType(undefined), onSaveISOParams: onSaveISOParams, docVersion: docVersion, isIPXE: true })),
        addModalType === 'bmc' && (React.createElement(modals_1.AddBmcHostModal, { infraEnv: infraEnv, isOpen: true, onClose: () => setAddModalType(undefined), onCreateBMH: onCreateBMH, usedHostnames: usedHostnames, docVersion: docVersion, provisioningConfigError: provisioningConfigError })),
        addModalType === 'yaml' && (React.createElement(modals_1.AddBmcHostYamlModal, { infraEnv: infraEnv, isOpen: true, onClose: () => setAddModalType(undefined), onCreateBmcByYaml: onCreateBmcByYaml, docVersion: docVersion, provisioningConfigError: provisioningConfigError }))));
};
exports.default = AddHostDropdown;
//# sourceMappingURL=AddHostDropdown.js.map