"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dropdown = void 0;
var react_1 = __importStar(require("react"));
var useClickOutside_1 = require("../../../hooks/useClickOutside");
var Dropdown_style_1 = __importDefault(require("./Dropdown.style"));
exports.Dropdown = function (_a) {
    var children = _a.children, menu = _a.menu;
    var _b = react_1.useState(false), open = _b[0], setOpen = _b[1];
    var dropDownMenu = react_1.useRef(null);
    useClickOutside_1.useClickOutside(function () { return setOpen(false); }, dropDownMenu);
    function toggleMenu() {
        setOpen(!open);
    }
    function clickItem(item) {
        setOpen(false);
        item.onClick();
    }
    return (react_1.default.createElement(Dropdown_style_1.default, { "data-cy": "dropdown", ref: dropDownMenu },
        react_1.default.createElement("span", { onClick: toggleMenu, "data-cy": "dropdown-btn" }, children),
        open && (react_1.default.createElement("div", { className: "ds-dropdown-menu", "data-testid": "dropmenu-popup" }, menu.map(function (e, i) { return (react_1.default.createElement("div", { key: i, onClick: function () { return clickItem(e); }, className: "menu-item", "data-testid": "dropmenu-menu-" + i }, e.name)); })))));
};
//# sourceMappingURL=Dropdown.js.map