"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.networkingStatusColumn = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const NetworkingStatus_1 = tslib_1.__importDefault(require("../../hosts/NetworkingStatus"));
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const common_1 = require("../../../../common");
const usePagination_1 = require("../../../../common/components/hosts/usePagination");
const HostRowDetail_1 = require("../../../../common/components/hosts/HostRowDetail");
const HostsTable_1 = tslib_1.__importDefault(require("../../../../common/components/hosts/HostsTable"));
const ClusterWizardContext_1 = require("../../clusterWizard/ClusterWizardContext");
const utils_1 = require("../../../../common/utils");
const networkingStatusColumn = (onEditHostname) => ({
    header: {
        title: 'Status',
        sort: true,
    },
    cell: (host) => {
        const editHostname = onEditHostname ? () => onEditHostname(host) : undefined;
        const validationsInfo = (0, utils_1.stringToJSON)(host.validationsInfo) || {};
        return {
            title: (React.createElement(NetworkingStatus_1.default, { host: host, onEditHostname: editHostname, validationsInfo: validationsInfo })),
            props: { 'data-testid': 'host-status' },
            sortableValue: status,
        };
    },
});
exports.networkingStatusColumn = networkingStatusColumn;
const NetworkConfigurationTableBase = ({ cluster, AdditionalNTPSourcesDialogToggleComponent, onEditHost, onEditRole, canEditRole, canEditHostname, actionResolver, children, onSelect, selectedIDs, }) => {
    const { wizardPerPage, setWizardPerPage } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const content = React.useMemo(() => [
        (0, common_1.hostnameColumn)(t, onEditHost, undefined, canEditHostname),
        (0, common_1.roleColumn)(t, canEditRole, onEditRole, (0, common_1.selectSchedulableMasters)(cluster)),
        (0, exports.networkingStatusColumn)(onEditHost),
        (0, common_1.activeNICColumn)(cluster, t),
        (0, common_1.ipv4Column)(cluster),
        (0, common_1.ipv6Column)(cluster),
        (0, common_1.macAddressColumn)(cluster),
        (0, common_1.countColumn)(cluster),
    ], [t, onEditHost, onEditRole, canEditHostname, canEditRole, cluster]);
    const hosts = cluster.hosts || [];
    const paginationProps = (0, usePagination_1.usePagination)(hosts.length, wizardPerPage, setWizardPerPage);
    const ExpandComponent = React.useCallback(({ obj }) => {
        return (React.createElement(HostRowDetail_1.HostDetail, { host: obj, AdditionalNTPSourcesDialogToggleComponent: AdditionalNTPSourcesDialogToggleComponent }));
    }, [AdditionalNTPSourcesDialogToggleComponent]);
    return (React.createElement(HostsTable_1.default, Object.assign({ testId: "networking-host-table", hosts: hosts, ExpandComponent: ExpandComponent, content: content, actionResolver: actionResolver, onSelect: onSelect, selectedIDs: selectedIDs }, paginationProps), children));
};
exports.default = NetworkConfigurationTableBase;
//# sourceMappingURL=NetworkConfigurationTableBase.js.map