"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const connected_icon_1 = require("@patternfly/react-icons/dist/js/icons/connected-icon");
const common_1 = require("../../../../common");
const helpers_1 = require("../../helpers");
const AdditionalNTPSourcesDialogToggle_1 = require("../components/AdditionalNTPSourcesDialogToggle");
const Agent_1 = require("../../Agent");
const HostsTable_1 = tslib_1.__importDefault(require("../../../../common/components/hosts/HostsTable"));
const HostRowDetail_1 = require("../../../../common/components/hosts/HostRowDetail");
const usePagination_1 = require("../../../../common/components/hosts/usePagination");
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const agentStatus_1 = require("../../helpers/agentStatus");
const ExpandComponentContext = React.createContext({
    onSetInstallationDiskId: undefined,
    agents: [],
});
const ExpandComponent = ({ obj }) => {
    const { onSetInstallationDiskId, agents } = React.useContext(ExpandComponentContext);
    return (React.createElement(HostRowDetail_1.HostDetail, { host: obj, AdditionalNTPSourcesDialogToggleComponent: AdditionalNTPSourcesDialogToggle_1.AdditionalNTPSourcesDialogToggle, canEditDisks: () => true, onDiskRole: onSetInstallationDiskId
            ? (hostID, diskID, role) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
                const agent = agents.find((a) => { var _a; return ((_a = a.metadata) === null || _a === void 0 ? void 0 : _a.uid) === obj.id; });
                if (agent && diskID && role === 'install') {
                    yield (onSetInstallationDiskId === null || onSetInstallationDiskId === void 0 ? void 0 : onSetInstallationDiskId(agent, diskID));
                }
            })
            : undefined }));
};
const ClusterDeploymentHostsNetworkTable = 
// eslint-disable-next-line react/display-name
React.memo(({ clusterDeployment, agentClusterInstall, agents, onEditHost, onEditRole, onSetInstallationDiskId, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const agentStatuses = (0, agentStatus_1.agentStatus)(t);
    const cluster = React.useMemo(() => (0, helpers_1.getAICluster)({ clusterDeployment, agentClusterInstall, agents }), [clusterDeployment, agentClusterInstall, agents]);
    const [hosts, hostActions, actionResolver] = (0, Agent_1.useAgentsTable)({ agents }, {
        onEditHost,
        onEditRole,
        onSetInstallationDiskId,
    });
    const isSNOCluster = (0, helpers_1.getIsSNOCluster)(agentClusterInstall);
    const content = React.useMemo(() => isSNOCluster
        ? [
            (0, common_1.hostnameColumn)(t, hostActions.onEditHost, hosts),
            (0, Agent_1.agentStatusColumn)({
                agents,
                agentStatuses,
                onEditHostname: onEditHost,
                wizardStepId: 'networking',
                t,
            }),
            (0, common_1.activeNICColumn)(cluster, t),
        ]
        : [
            (0, common_1.hostnameColumn)(t, hostActions.onEditHost, hosts),
            (0, common_1.roleColumn)(t, hostActions.canEditRole, hostActions.onEditRole),
            (0, Agent_1.agentStatusColumn)({
                agents,
                agentStatuses,
                onEditHostname: onEditHost,
                wizardStepId: 'networking',
                t,
            }),
            (0, common_1.activeNICColumn)(cluster, t),
        ], [
        isSNOCluster,
        t,
        hostActions.onEditHost,
        hostActions.canEditRole,
        hostActions.onEditRole,
        hosts,
        agents,
        agentStatuses,
        onEditHost,
        cluster,
    ]);
    const paginationProps = (0, usePagination_1.usePagination)(hosts.length);
    return (React.createElement(ExpandComponentContext.Provider, { value: { onSetInstallationDiskId, agents } },
        React.createElement(HostsTable_1.default, Object.assign({ testId: "networking-host-table", hosts: hosts, ExpandComponent: ExpandComponent, content: content, actionResolver: actionResolver }, paginationProps),
            React.createElement(common_1.EmptyState, { icon: connected_icon_1.ConnectedIcon, title: t('ai:Waiting for hosts...'), content: t('ai:Hosts may take a few minutes to appear here after booting.') }))));
});
exports.default = ClusterDeploymentHostsNetworkTable;
//# sourceMappingURL=ClusterDeploymentHostsNetworkTable.js.map