"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MacIpMapping = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const plus_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/plus-circle-icon");
const common_1 = require("../../../../../../common");
const OcmFormFields_1 = require("../../../../ui/OcmFormFields");
const react_redux_1 = require("react-redux");
const selectors_1 = require("../../../../../store/slices/current-cluster/selectors");
const AddMapping = ({ onPush }) => {
    return (react_1.default.createElement(react_core_1.Button, { icon: react_1.default.createElement(plus_circle_icon_1.PlusCircleIcon, null), isInline: true, onClick: () => onPush({ macAddress: '', logicalNicName: '' }), "data-testid": "add-mapping", variant: "link" }, "Add another MAC to interface name mapping"));
};
const MacMappingItem = ({ fieldName, onRemove, mapIdx, enableRemove, hostIdx, }) => {
    return (react_1.default.createElement(common_1.RemovableField, { hideRemoveButton: !enableRemove, onRemove: onRemove },
        react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
            react_1.default.createElement(react_core_1.GridItem, { span: 6 },
                react_1.default.createElement(OcmFormFields_1.OcmInputField, { label: "MAC address", isRequired: true, name: `${fieldName}.macAddress`, "data-testid": `mac-address-${hostIdx}-${mapIdx}` })),
            react_1.default.createElement(react_core_1.GridItem, { span: 6 },
                react_1.default.createElement(OcmFormFields_1.OcmInputField, { label: "Interface name", isRequired: true, name: `${fieldName}.logicalNicName`, "data-testid": `interface-name-${hostIdx}-${mapIdx}` })))));
};
const MacIpMapping = ({ fieldName, macInterfaceMap, hostIdx, }) => {
    const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
    return (react_1.default.createElement(react_core_1.Grid, { className: "mac-ip-mapping" },
        react_1.default.createElement(formik_1.FieldArray, { name: fieldName, validateOnChange: false, render: ({ push, remove }) => (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
                react_1.default.createElement(react_core_1.GridItem, { span: 6 }, macInterfaceMap.map((_, idx) => (react_1.default.createElement(MacMappingItem, { key: (0, common_1.getFormikArrayItemFieldName)(fieldName, idx), fieldName: (0, common_1.getFormikArrayItemFieldName)(fieldName, idx), onRemove: () => remove(idx), mapIdx: idx, enableRemove: !isViewerMode && idx > 0, hostIdx: hostIdx })))),
                react_1.default.createElement(react_core_1.GridItem, null, !isViewerMode && react_1.default.createElement(AddMapping, { onPush: push })))) })));
};
exports.MacIpMapping = MacIpMapping;
//# sourceMappingURL=MacIpMapping.js.map