"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReviewConfigMapsTable = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const hooks_1 = require("../../../hooks");
const react_table_1 = require("@patternfly/react-table");
const common_1 = require("../../../../common");
const ReviewConfigMapsTable = ({ agentClusterInstall, }) => {
    var _a, _b;
    const [configMaps, loaded] = (0, hooks_1.useConfigMaps)({
        namespace: (_a = agentClusterInstall.metadata) === null || _a === void 0 ? void 0 : _a.namespace,
        isList: true,
    });
    const customManifests = react_1.default.useMemo(() => {
        const maps = configMaps.filter((configMap) => {
            var _a, _b, _c;
            return (_b = (_a = agentClusterInstall.spec) === null || _a === void 0 ? void 0 : _a.manifestsConfigMapRefs) === null || _b === void 0 ? void 0 : _b.flatMap((ref) => ref.name).includes(((_c = configMap.metadata) === null || _c === void 0 ? void 0 : _c.name) || '');
        });
        return maps
            .map((map, index) => {
            var _a;
            return [
                {
                    rowId: `config-map-${index}`,
                    cells: [{ title: (_a = map.metadata) === null || _a === void 0 ? void 0 : _a.name, isExpanded: true, level: 1, posInset: 1 }],
                },
                ...Object.keys(map.data || {}).map((key) => ({
                    rowId: `config-map-${index}-${key}`,
                    cells: [
                        {
                            title: (react_1.default.createElement(react_1.default.Fragment, null,
                                react_1.default.createElement("span", { style: { width: '1rem', display: 'inline-block' } }),
                                key)),
                            posInset: 2,
                            level: 2,
                        },
                    ],
                })),
            ];
        })
            .flat();
    }, [(_b = agentClusterInstall.spec) === null || _b === void 0 ? void 0 : _b.manifestsConfigMapRefs, configMaps]);
    return loaded ? (react_1.default.createElement(react_table_1.Table, { variant: react_table_1.TableVariant.compact, borders: false, "data-testid": "review-custom-manifests-table" },
        react_1.default.createElement(react_table_1.Tbody, null, customManifests.map((row, i) => (react_1.default.createElement(react_table_1.Tr, { key: (0, common_1.genericTableRowKey)(row.rowId) }, row.cells.map((_a, j) => {
            var { title } = _a, props = tslib_1.__rest(_a, ["title"]);
            return (react_1.default.createElement(react_table_1.Td, Object.assign({ key: `cell-${i}-${j}` }, props), title));
        }))))))) : (react_1.default.createElement(common_1.LoadingState, null));
};
exports.ReviewConfigMapsTable = ReviewConfigMapsTable;
//# sourceMappingURL=ReviewConfigMapsTable.js.map