import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2025 GoodData Corporation
import { useCallback } from "react";
import cx from "classnames";
import { useIntl } from "react-intl";
import { ItemsWrapper, Overlay, Separator } from "@gooddata/sdk-ui-kit";
import { VisualizationListMenuItem } from "./VisualizationListMenuItem.js";
const menuAlignPoints = [{ align: "br tr" }];
export function VisualizationListMenu({ alignTo, isLast, isFirst, visualization, shouldRenderActions, onMenuButtonClick, onVisualizationDeleted, onVisualizationPositionChange, }) {
    const intl = useIntl();
    const handleOnVisualizationPositionChange = useCallback((disabled, direction) => {
        if (disabled) {
            return;
        }
        onVisualizationPositionChange(visualization.identifier, direction);
        onMenuButtonClick();
    }, 
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [visualization.identifier]);
    return (_jsx(Overlay, { alignTo: alignTo, alignPoints: menuAlignPoints, className: "gd-more-menu-overlay", closeOnMouseDrag: true, closeOnOutsideClick: true, onClose: onMenuButtonClick, children: _jsxs(ItemsWrapper, { smallItemsSpacing: true, className: ".s-visualization-switcher-more-menu", children: [shouldRenderActions ? (_jsxs(_Fragment, { children: [
                        _jsx(VisualizationListMenuItem, { className: cx("gd-vis-switcher-show-more-item", { "is-disabled": isFirst }), disabled: isFirst, onClick: () => {
                                handleOnVisualizationPositionChange(isFirst, "moveUp");
                            }, text: intl.formatMessage({ id: "visualizationSwitcher.list.menu.move.up" }) }), _jsx(VisualizationListMenuItem, { className: cx("gd-vis-switcher-show-more-item", { "is-disabled": isLast }), disabled: isLast, onClick: () => {
                                handleOnVisualizationPositionChange(isLast, "moveDown");
                            }, text: intl.formatMessage({ id: "visualizationSwitcher.list.menu.move.down" }) }), _jsx(Separator, {})
                    ] })) : null, _jsx(VisualizationListMenuItem, { className: "gd-vis-swicher-show-more-item-remove", onClick: () => {
                        onVisualizationDeleted(visualization.identifier);
                        onMenuButtonClick();
                    }, text: intl.formatMessage({ id: "visualizationSwitcher.list.menu.remove" }) })
            ] }) }, "VisSwitcherMoreMenu"));
}
