"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigationPopup = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const uikit_1 = require("@gravity-ui/uikit");
const utils_1 = require("../../../../utils/index.js");
const models_1 = require("../../models.js");
const NavigationItem_1 = tslib_1.__importDefault(require("../NavigationItem/index.js"));
const b = (0, utils_1.block)('navigation-popup');
const OFFSET_RESET = { mainAxis: 0, crossAxis: 0 };
const NavigationPopup = ({ anchorRef, items, onClose, open }) => {
    // Opening and closing is controlled by the associated button,
    // but in order to give the popup control over closing as well (e.g. on click outside or escape key press)
    // there needs to be an awkward looking handler like this.
    const onOpenChange = (isOpen) => {
        if (!isOpen) {
            onClose();
        }
    };
    return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { className: b(), 
        // Workaround to recalculate position on every opening. Required for valid position calculation for scrolled header links.
        anchorElement: anchorRef.current, open: open, onOpenChange: onOpenChange, keepMounted: true, strategy: "fixed", placement: "bottom-start", offset: OFFSET_RESET, children: (0, jsx_runtime_1.jsx)("ul", { className: b('list'), children: items.map((item) => ((0, jsx_runtime_1.jsx)(NavigationItem_1.default, { className: b('link'), data: item, menuLayout: models_1.NavigationLayout.Dropdown }, item.text))) }) }));
};
exports.NavigationPopup = NavigationPopup;
exports.default = exports.NavigationPopup;
//# sourceMappingURL=NavigationPopup.js.map
