"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FolderDropdown = 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 formik_2 = require("../../../../../common/components/ui/formik");
const common_1 = require("../../../../../common");
const FolderLabel = () => {
    return (react_1.default.createElement(react_1.default.Fragment, null,
        "Folder",
        ' ',
        react_1.default.createElement(common_1.PopoverIcon, { bodyContent: react_1.default.createElement(react_1.default.Fragment, null, "To overwrite an existing manifest, save the new manifest in the same folder with the same name.") })));
};
const dropdownItems = [
    react_1.default.createElement(react_core_1.DropdownItem, { key: "manifests", id: "manifests" }, 'manifests'),
    react_1.default.createElement(react_core_1.DropdownItem, { key: "openshift", id: "openshift" }, 'openshift'),
];
const FolderDropdown = ({ name }) => {
    const [field, { value }, { setValue }] = (0, formik_1.useField)(name);
    const [isOpen, setOpen] = react_1.default.useState(false);
    const fieldId = (0, formik_2.getFieldId)(name, 'input');
    const onSelect = (event) => {
        setValue(event === null || event === void 0 ? void 0 : event.currentTarget.id);
        setOpen(false);
    };
    const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, { ref: toggleRef, onClick: () => setOpen(!isOpen), isExpanded: isOpen, className: "pf-v6-u-w-100", id: fieldId, "data-testid": "folder-dropdown-toggle" }, value || 'manifests'));
    return (react_1.default.createElement(react_core_1.FormGroup, { fieldId: fieldId, label: react_1.default.createElement(FolderLabel, null), isRequired: true },
        react_1.default.createElement(react_core_1.Dropdown, Object.assign({}, field, { id: fieldId, onOpenChange: () => setOpen(!isOpen), onSelect: onSelect, toggle: toggle, isOpen: isOpen }), dropdownItems),
        react_1.default.createElement(react_core_1.HelperText, { style: { display: 'inherit' } }, 'Manifests can be placed in "manifests" or "openshift" directories.')));
};
exports.FolderDropdown = FolderDropdown;
//# sourceMappingURL=FolderDropdown.js.map