"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 use_hosts_table_1 = require("./use-hosts-table");
const HostsTable_1 = tslib_1.__importDefault(require("../../../common/components/hosts/HostsTable"));
const HostRowDetail_1 = require("../../../common/components/hosts/HostRowDetail");
const AdditionaNTPSourceDialogToggle_1 = require("./AdditionaNTPSourceDialogToggle");
const usePagination_1 = require("../../../common/components/hosts/usePagination");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const HardwareStatus_1 = require("./HardwareStatus");
const HostsTableEmptyState_1 = tslib_1.__importDefault(require("../hosts/HostsTableEmptyState"));
const react_redux_1 = require("react-redux");
const selectors_1 = require("../../store/slices/current-cluster/selectors");
const ClusterWizardContext_1 = require("../clusterWizard/ClusterWizardContext");
const HostRowDetailExpand = ({ obj: host }) => (react_1.default.createElement(HostRowDetail_1.HostDetail, { key: host.id, host: host, AdditionalNTPSourcesDialogToggleComponent: AdditionaNTPSourceDialogToggle_1.AdditionalNTPSourcesDialogToggle }));
const HostsDiscoveryTable = ({ cluster, hosts }) => {
    const _a = (0, use_hosts_table_1.useHostsTable)(cluster), { onEditHost, actionChecks, onEditRole, actionResolver, onSelect, selectedHostIDs, setSelectedHostIDs, onMassChangeHostname, onMassDeleteHost } = _a, modalProps = tslib_1.__rest(_a, ["onEditHost", "actionChecks", "onEditRole", "actionResolver", "onSelect", "selectedHostIDs", "setSelectedHostIDs", "onMassChangeHostname", "onMassDeleteHost"]);
    const { wizardPerPage, setWizardPerPage } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
    const isSNOCluster = (0, common_1.isSNO)(cluster);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const content = react_1.default.useMemo(() => [
        (0, common_1.hostnameColumn)(t, onEditHost, undefined, actionChecks.canEditHostname),
        (0, common_1.roleColumn)(t, actionChecks.canEditRole, onEditRole, (0, common_1.selectSchedulableMasters)(cluster), cluster.kind),
        (0, HardwareStatus_1.hardwareStatusColumn)({
            onEditHostname: onEditHost,
            openshiftVersion: cluster.openshiftVersion,
        }),
        (0, common_1.discoveredAtColumn)(t),
        (0, common_1.cpuCoresColumn)(t),
        (0, common_1.memoryColumn)(t),
        (0, common_1.disksColumn)(t),
        (0, common_1.countColumn)(cluster),
    ], [t, onEditHost, actionChecks.canEditHostname, actionChecks.canEditRole, onEditRole, cluster]);
    const paginationProps = (0, usePagination_1.usePagination)(hosts.length, wizardPerPage, setWizardPerPage);
    const itemIDs = hosts.map((h) => h.id);
    const showBulkActions = !(isViewerMode || isSNOCluster);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
            showBulkActions && (react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(common_1.TableToolbar, Object.assign({ selectedIDs: selectedHostIDs || [], itemIDs: itemIDs, setSelectedIDs: setSelectedHostIDs, actions: [
                        react_1.default.createElement(common_1.ChangeHostnameAction, { key: "hostname", onChangeHostname: onMassChangeHostname }),
                        react_1.default.createElement(common_1.DeleteHostAction, { key: "delete", onDeleteHost: onMassDeleteHost }),
                    ] }, paginationProps)))),
            react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(HostsTable_1.default, Object.assign({ testId: "hosts-discovery-table", hosts: hosts, content: content, actionResolver: actionResolver, ExpandComponent: HostRowDetailExpand, onSelect: showBulkActions ? onSelect : undefined, selectedIDs: selectedHostIDs, setSelectedIDs: setSelectedHostIDs }, paginationProps),
                    react_1.default.createElement(HostsTableEmptyState_1.default, { isSingleNode: isSNOCluster })))),
        react_1.default.createElement(use_hosts_table_1.HostsTableModals, Object.assign({ cluster: cluster }, modalProps))));
};
exports.default = HostsDiscoveryTable;
//# sourceMappingURL=HostsDiscoveryTable.js.map