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 { workspacePermissionMessages } from "./locales.js";
import { PermissionDropdownItem } from "./PermissionDropdownItem.js";
const userGroupTooltipMessages = defineMessages({
    VIEW: { id: "userManagement.workspace.permissionGroup.view.tooltip" },
    VIEW_AND_SAVE_VIEWS: { id: "userManagement.workspace.permissionGroup.viewSaveViews.tooltip" },
    VIEW_AND_EXPORT: { id: "userManagement.workspace.permissionGroup.viewExport.tooltip" },
    VIEW_AND_EXPORT_AND_SAVE_VIEWS: {
        id: "userManagement.workspace.permissionGroup.viewExportSaveViews.tooltip",
    },
    ANALYZE: { id: "userManagement.workspace.permissionGroup.analyze.tooltip" },
    ANALYZE_AND_EXPORT: { id: "userManagement.workspace.permissionGroup.analyzeExport.tooltip" },
    MANAGE: { id: "userManagement.workspace.permissionGroup.manage.tooltip" },
});
const userTooltipMessages = defineMessages({
    VIEW: { id: "userManagement.workspace.permissionUser.view.tooltip" },
    VIEW_AND_SAVE_VIEWS: { id: "userManagement.workspace.permissionUser.viewSaveViews.tooltip" },
    VIEW_AND_EXPORT: { id: "userManagement.workspace.permissionUser.viewExport.tooltip" },
    VIEW_AND_EXPORT_AND_SAVE_VIEWS: {
        id: "userManagement.workspace.permissionUser.viewExportSaveViews.tooltip",
    },
    ANALYZE: { id: "userManagement.workspace.permissionUser.analyze.tooltip" },
    ANALYZE_AND_EXPORT: { id: "userManagement.workspace.permissionUser.analyzeExport.tooltip" },
    MANAGE: { id: "userManagement.workspace.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(workspacePermissionMessages.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: permissionItem.id in tooltipSource
                            ? tooltipSource[permissionItem.id].id
                            : undefined }, permissionItem.id));
                }), _jsx(Separator, {}), _jsx(RemoveItem, { onClick: handleOnDelete })
            ] }) }, "GranularPermissionsSelect"));
}
//# sourceMappingURL=PermissionsDropdownList.js.map