import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useCallback, useMemo } from "react";
import cx from "classnames";
import { useIntl } from "react-intl";
import { Dropdown, DropdownButton, ItemsWrapper, Overlay } from "@gooddata/sdk-ui-kit";
import { messages } from "../locales.js";
import { QuestionMarkIcon } from "../Workspace/WorkspaceItem/QuestionMarkIcon.js";
const overlayAlignPoints = [{ align: "br tr" }];
export function OrganizationMemberDropdown({ isAdmin, isDisabled, onChange, }) {
    const intl = useIntl();
    const renderDropdownBody = useCallback(({ closeDropdown }) => (_jsx(Overlay, { alignTo: ".gd-user-management-dialog-detail-organization-membership", alignPoints: overlayAlignPoints, className: "s-user-management-user-permissions-overlay", closeOnMouseDrag: true, closeOnOutsideClick: true, closeOnParentScroll: true, onClose: closeDropdown, children: _jsxs(ItemsWrapper, { smallItemsSpacing: true, children: [_jsxs("div", { onClick: () => {
                        onChange(true);
                        closeDropdown();
                    }, className: cx("gd-list-item", "gd-menu-item", "gd-user-management-dialog-detail-input", "gd-user-management-permission-item", "s-user-management-permission-admin", {
                        "is-selected": isAdmin,
                    }), children: [_jsx("div", { children: intl.formatMessage(messages.userIsAdmin) }), _jsx("div", { className: "gd-user-management-help-icon-wrapper", children: _jsx(QuestionMarkIcon, { bubbleTextId: messages.userIsAdminTooltip.id }) })] }), _jsxs("div", { onClick: () => {
                        onChange(false);
                        closeDropdown();
                    }, className: cx("gd-list-item", "gd-menu-item", "gd-user-management-dialog-detail-input", "gd-user-management-permission-item", "s-user-management-permission-non-admin", {
                        "is-selected": !isAdmin,
                    }), children: [_jsx("div", { children: intl.formatMessage(messages.userIsRegularUser) }), _jsx("div", { className: "gd-user-management-help-icon-wrapper", children: _jsx(QuestionMarkIcon, { bubbleTextId: messages.userIsRegularUserTooltip.id }) })] })] }) }, "GranularPermissionsSelect")), [isAdmin, onChange, intl]);
    const selectedValue = useMemo(() => isAdmin
        ? intl.formatMessage(messages.userIsAdmin)
        : intl.formatMessage(messages.userIsRegularUser), [isAdmin, intl]);
    const renderDropdownButton = useCallback(({ openDropdown, isOpen }) => (_jsx(DropdownButton, { value: selectedValue, isOpen: isOpen, disabled: isDisabled, onClick: openDropdown, isSmall: false, className: "gd-user-management-dialog-detail-organization-membership gd-user-management-dialog-detail-input s-user-management-permission-dropdown" })), [selectedValue, isDisabled]);
    return _jsx(Dropdown, { renderBody: renderDropdownBody, renderButton: renderDropdownButton });
}
//# sourceMappingURL=OrganizationMemberDropdown.js.map