"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableCellFloatingButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const icons_1 = require("@gravity-ui/icons");
const uikit_1 = require("@gravity-ui/uikit");
require("./floating.css");
const TableCellFloatingButton = ({ dom, actions }) => {
    if (!dom) {
        return null;
    }
    return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { open: true, keepMounted: false, hasArrow: false, anchorElement: dom, offset: { crossAxis: 2, mainAxis: -12 }, placement: "left-start", children: (0, jsx_runtime_1.jsx)(uikit_1.DropdownMenu, { icon: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Ellipsis, size: 12, className: "table-cell-floating-icon" }), defaultSwitcherClassName: "table-cell-floating-button", items: actions.map(buildMenuItem) }) }));
};
exports.TableCellFloatingButton = TableCellFloatingButton;
exports.TableCellFloatingButton.displayName = 'TableCellFloatingButton';
function buildMenuItem(floatingAction) {
    if (Array.isArray(floatingAction)) {
        // @ts-expect-error
        return floatingAction.map(buildMenuItem);
    }
    const { action, text } = floatingAction;
    const active = action.isActive();
    const disabled = !active && !action.isEnable();
    return {
        text,
        action: () => action.run({}),
        active,
        disabled,
    };
}
//# sourceMappingURL=floating.js.map
