"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReviewNetworkingTable = void 0;
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const react_table_1 = require("@patternfly/react-table");
const react_1 = tslib_1.__importDefault(require("react"));
const common_1 = require("../../../../common");
const utils_1 = require("./utils");
const ReviewNetworkingTable = ({ cluster }) => {
    const { t } = (0, common_1.useTranslation)();
    const rows = react_1.default.useMemo(() => {
        var _a, _b, _c, _d, _e, _f, _g;
        const networkRows = [
            {
                rowId: 'network-management',
                cells: [
                    { title: 'Networking management type' },
                    {
                        title: (0, utils_1.getManagementType)(cluster),
                        props: { 'data-testid': 'networking-management-type', colSpan: 2 },
                    },
                ],
            },
            {
                rowId: 'stack-type',
                cells: [
                    { title: 'Stack type', colSpan: 2 },
                    {
                        title: (0, utils_1.getStackTypeLabel)(cluster),
                        props: { 'data-testid': 'stack-type', colSpan: 2 },
                    },
                ],
            },
        ];
        !!((_a = cluster.machineNetworks) === null || _a === void 0 ? void 0 : _a.length) &&
            networkRows.push({
                rowId: 'machine-networks-cidr',
                cells: [
                    { title: 'Machine networks CIDR' },
                    {
                        title: (_b = cluster.machineNetworks) === null || _b === void 0 ? void 0 : _b.map((network) => (react_1.default.createElement("span", { key: network.cidr },
                            network.cidr,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'machine-networks' },
                    },
                    (0, common_1.isDualStack)(cluster)
                        ? {
                            title: (_c = cluster.machineNetworks) === null || _c === void 0 ? void 0 : _c.map((network, index) => (react_1.default.createElement("span", { key: network.cidr },
                                index === 0 ? 'Primary' : 'Secondary',
                                react_1.default.createElement("br", null)))),
                        }
                        : { title: '' },
                ],
            });
        cluster.apiVips &&
            cluster.apiVips.length > 0 &&
            networkRows.push({
                rowId: 'api-ip',
                cells: [
                    { title: 'API IP' },
                    {
                        title: (_d = cluster.apiVips) === null || _d === void 0 ? void 0 : _d.map((apiVip) => (react_1.default.createElement("span", { key: apiVip.ip },
                            apiVip.ip,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'api-vip' },
                    },
                    (0, common_1.isDualStack)(cluster)
                        ? {
                            title: (_e = cluster.apiVips) === null || _e === void 0 ? void 0 : _e.map((apiVip, index) => (react_1.default.createElement("span", { key: apiVip.ip },
                                index === 0 ? 'Primary' : 'Secondary',
                                react_1.default.createElement("br", null)))),
                        }
                        : { title: '' },
                ],
            });
        cluster.ingressVips &&
            cluster.ingressVips.length &&
            networkRows.push({
                rowId: 'ingress-ip',
                cells: [
                    { title: 'Ingress IP' },
                    {
                        title: (_f = cluster.ingressVips) === null || _f === void 0 ? void 0 : _f.map((ingressVip) => (react_1.default.createElement("span", { key: ingressVip.ip },
                            ingressVip.ip,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'ingress-vip' },
                    },
                    (0, common_1.isDualStack)(cluster)
                        ? {
                            title: (_g = cluster.ingressVips) === null || _g === void 0 ? void 0 : _g.map((ingressVip, index) => (react_1.default.createElement("span", { key: ingressVip.ip },
                                index === 0 ? 'Primary' : 'Secondary',
                                react_1.default.createElement("br", null)))),
                        }
                        : { title: '' },
                ],
            });
        return networkRows;
    }, [cluster]);
    const rowsAdvanced = react_1.default.useMemo(() => {
        var _a, _b, _c, _d, _e, _f;
        return [
            {
                rowId: 'cluster-network-cidr',
                cells: [
                    { title: 'Cluster network CIDR' },
                    {
                        title: (_a = cluster.clusterNetworks) === null || _a === void 0 ? void 0 : _a.map((network) => (react_1.default.createElement("span", { key: network.cidr },
                            network.cidr,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'cluster-network-cidr' },
                    },
                    (0, common_1.isDualStack)(cluster) && {
                        title: (_b = cluster.clusterNetworks) === null || _b === void 0 ? void 0 : _b.map((network, index) => (react_1.default.createElement("span", { key: network.cidr },
                            index === 0 ? 'Primary' : 'Secondary',
                            react_1.default.createElement("br", null)))),
                    },
                ].filter(Boolean),
            },
            {
                rowId: 'cluster-network-host-prefix',
                cells: [
                    { title: 'Cluster network host prefix' },
                    {
                        title: (_c = cluster.clusterNetworks) === null || _c === void 0 ? void 0 : _c.map((network) => (react_1.default.createElement("span", { key: network.hostPrefix },
                            network.hostPrefix,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'cluster-network-prefix' },
                    },
                    (0, common_1.isDualStack)(cluster) && {
                        title: (_d = cluster.clusterNetworks) === null || _d === void 0 ? void 0 : _d.map((network, index) => (react_1.default.createElement("span", { key: network.hostPrefix },
                            index === 0 ? 'Primary' : 'Secondary',
                            react_1.default.createElement("br", null)))),
                    },
                ].filter(Boolean),
            },
            {
                rowId: 'service-network-cidr',
                cells: [
                    { title: 'Service network CIDR' },
                    {
                        title: (_e = cluster.serviceNetworks) === null || _e === void 0 ? void 0 : _e.map((network) => (react_1.default.createElement("span", { key: network.cidr },
                            network.cidr,
                            react_1.default.createElement("br", null)))),
                        props: { 'data-testid': 'service-network-cidr' },
                    },
                    (0, common_1.isDualStack)(cluster) && {
                        title: (_f = cluster.serviceNetworks) === null || _f === void 0 ? void 0 : _f.map((network, index) => (react_1.default.createElement("span", { key: network.cidr },
                            index === 0 ? 'Primary' : 'Secondary',
                            react_1.default.createElement("br", null)))),
                    },
                ].filter(Boolean),
            },
            {
                rowId: 'networking-type',
                cells: [
                    { title: 'Networking type' },
                    {
                        title: cluster.networkType ? (0, common_1.NETWORK_TYPE_LABELS)(t)[cluster.networkType] : '-',
                        props: { 'data-testid': 'networking-type', colSpan: 2 },
                    },
                ],
            },
        ];
    }, [cluster, t]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_table_1.Table, { variant: react_table_1.TableVariant.compact, borders: false, className: 'review-table', "aria-label": 'Networking review table' },
            react_1.default.createElement(react_table_1.Tbody, null, rows.map((row, i) => (react_1.default.createElement(react_table_1.Tr, { key: (0, common_1.genericTableRowKey)(row.rowId) }, row.cells.map((cell, j) => (react_1.default.createElement(react_table_1.Td, Object.assign({ key: `cell-${i}-${j}` }, cell.props), cell.title)))))))),
        react_1.default.createElement("br", null),
        react_1.default.createElement(react_core_1.Title, { className: "pf-v6-u-color-400", headingLevel: "h4" }, "Advanced networking settings"),
        react_1.default.createElement(react_table_1.Table, { variant: react_table_1.TableVariant.compact, borders: false, className: 'review-table', "aria-label": 'Advanced networking review table' },
            react_1.default.createElement(react_table_1.Tbody, null, rowsAdvanced.map((row, i) => (react_1.default.createElement(react_table_1.Tr, { key: (0, common_1.genericTableRowKey)(row.rowId) }, row.cells.map((cell, j) => (react_1.default.createElement(react_table_1.Td, Object.assign({ key: `cell-${i}-${j}` }, cell.props), cell.title))))))))));
};
exports.ReviewNetworkingTable = ReviewNetworkingTable;
//# sourceMappingURL=ReviewNetworkingTable.js.map