import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useCallback } from "react";
import cx from "classnames";
import { defineMessages, useIntl } from "react-intl";
import { ItemsWrapper, Overlay, Separator } from "@gooddata/sdk-ui-kit";
import { dataSourcePermissionMessages } from "./locales.js";
import { PermissionDropdownItem } from "./PermissionsDropdownItem.js";
const userGroupTooltipMessages = defineMessages({
    USE: { id: "userManagement.dataSources.permissionGroup.use.tooltip" },
    MANAGE: { id: "userManagement.dataSources.permissionGroup.manage.tooltip" },
});
const userTooltipMessages = defineMessages({
    USE: { id: "userManagement.dataSources.permissionUser.use.tooltip" },
    MANAGE: { id: "userManagement.dataSources.permissionUser.manage.tooltip" },
});
const overlayAlignPoints = [{ align: "br tr" }];
function RemoveItem({ disabled, onClick }) {
    const intl = useIntl();
    const className = cx("gd-list-item gd-menu-item gd-menu-item-remove", "s-user-management-permission-remove", {
        "is-disabled": disabled,
    });
    return (_jsx("div", { className: className, onClick: onClick, children: intl.formatMessage(dataSourcePermissionMessages.remove) }));
}
export function PermissionsDropdownList({ items, subjectType, alignTo, isShowDropdown, selectedPermission, toggleDropdown, onSelect, onDelete, }) {
    const tooltipSource = subjectType === "user" ? userTooltipMessages : userGroupTooltipMessages;
    const handleOnSelect = useCallback((permission) => {
        onSelect(permission);
        toggleDropdown();
    }, [onSelect, toggleDropdown]);
    const handleOnDelete = useCallback(() => {
        onDelete();
        toggleDropdown();
    }, [onDelete, toggleDropdown]);
    if (!isShowDropdown) {
        return null;
    }
    return (_jsx(Overlay, { alignTo: alignTo, alignPoints: overlayAlignPoints, className: "s-user-management-permissions-overlay", closeOnMouseDrag: true, closeOnOutsideClick: true, closeOnParentScroll: true, onClose: toggleDropdown, children: _jsxs(ItemsWrapper, { smallItemsSpacing: true, children: [items.map((permissionItem) => {
                    return (_jsx(PermissionDropdownItem, { permission: permissionItem, selectedPermission: selectedPermission, toggleDropdown: toggleDropdown, onSelect: handleOnSelect, bubbleTextId: tooltipSource[permissionItem.id].id }, permissionItem.id));
                }), _jsx(Separator, {}), _jsx(RemoveItem, { onClick: handleOnDelete })
            ] }) }, "GranularPermissionsSelect"));
}
//# sourceMappingURL=PermissionsDropdownList.js.map