"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomManifest = exports.RemoveItemButton = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const minus_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/minus-circle-icon");
const common_1 = require("../../../../../common");
const utils_1 = require("./utils");
const CollapsedManifest_1 = tslib_1.__importDefault(require("./CollapsedManifest"));
const ExpandedManifest_1 = tslib_1.__importDefault(require("./ExpandedManifest"));
const RemoveItemButton = ({ onRemove, showRemoveButton, dataTestId, }) => (react_1.default.createElement(react_core_1.Button, { icon: react_1.default.createElement(minus_circle_icon_1.MinusCircleIcon, { onClick: onRemove }), "data-testid": dataTestId, "aria-label": "remove manifest", style: { visibility: showRemoveButton ? 'visible' : 'hidden' }, variant: "plain" }));
exports.RemoveItemButton = RemoveItemButton;
const CustomManifest = ({ fieldName, manifestIdx, onRemove, onToggleExpand, isExpanded, isDisabled, enableRemoveManifest, }) => {
    const [showRemoveButton, setShowRemoveButton] = react_1.default.useState(false);
    const updateShowRemoveButton = (value) => {
        if (isDisabled) {
            return;
        }
        if (!enableRemoveManifest) {
            setShowRemoveButton(false);
        }
        else {
            setShowRemoveButton(value);
        }
    };
    const manifestFieldName = (0, common_1.getFormikArrayItemFieldName)(fieldName, manifestIdx);
    return (react_1.default.createElement(react_core_1.Grid, { onMouseEnter: () => updateShowRemoveButton(true), onMouseLeave: () => updateShowRemoveButton(false), hasGutter: true },
        react_1.default.createElement(react_core_1.Flex, null,
            react_1.default.createElement(react_core_1.FlexItem, null,
                react_1.default.createElement(react_core_1.ExpandableSectionToggle, { isExpanded: isExpanded, onToggle: onToggleExpand, direction: "down", "data-testid": `toggle-manifest-${manifestIdx}` }, (0, utils_1.getManifestName)(manifestIdx))),
            !isDisabled && enableRemoveManifest && (react_1.default.createElement(react_core_1.FlexItem, { align: { default: 'alignRight' } },
                react_1.default.createElement(exports.RemoveItemButton, { onRemove: onRemove, showRemoveButton: showRemoveButton, dataTestId: `remove-manifest-${manifestIdx}` })))),
        isExpanded ? (react_1.default.createElement(ExpandedManifest_1.default, { fieldName: manifestFieldName, manifestIdx: manifestIdx, isDisabled: isDisabled })) : (react_1.default.createElement(CollapsedManifest_1.default, { manifestIdx: manifestIdx, fieldName: manifestFieldName }))));
};
exports.CustomManifest = CustomManifest;
//# sourceMappingURL=CustomManifest.js.map