import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2026 GoodData Corporation
import { useIntl } from "react-intl";
import { commonDialogMessages, olpAddGranteeDialogMessages, olpObjectShareDialogMessages, } from "../../locales.js";
import { bem } from "../@utils/bem.js";
import { UiButton } from "../UiButton/UiButton.js";
import { UiGranteeAsyncPicker, } from "../UiGranteeAsyncPicker/UiGranteeAsyncPicker.js";
import { UiIconButton } from "../UiIconButton/UiIconButton.js";
import { UiDialogFooter } from "../UiModalDialog/UiDialogFooter.js";
import { UiDialogHeader } from "../UiModalDialog/UiDialogHeader.js";
import { useGranteeSelection } from "./useGranteeSelection.js";
const { b } = bem("gd-ui-kit-add-grantee-dialog");
/**
 * Add-grantee dialog card — header + grantee picker (search input with
 * sectioned Groups/Users dropdown and picked-rows list) + footer with Cancel
 * and Share. Renders inline as a plain card. For modal behavior (portal,
 * backdrop, focus trap, dismiss), use `UiAddGranteeDialog` which wraps this
 * in `UiModalDialog`.
 *
 * The card owns the visual composition (picker layout) but no policy. The
 * caller controls the picked list via `selectedGrantees` / `onSelectedGranteesChange`,
 * and may override the initial permission level via `initialPermissionLevel`.
 *
 * @internal
 */
export function UiAddGranteeDialogCard({ objectTitle, loadOptions, selectedGrantees, onSelectedGranteesChange, initialPermissionLevel = "VIEW", onBack, onClose, onCancel, onShare, dataTestId, }) {
    const intl = useIntl();
    const dialogTitle = intl.formatMessage(olpObjectShareDialogMessages.title, { title: objectTitle });
    const backButton = (_jsx(UiIconButton, { icon: "chevronLeft", variant: "tertiary", size: "small", onClick: onBack, accessibilityConfig: { ariaLabel: intl.formatMessage(olpAddGranteeDialogMessages.back) } }));
    const { select, changePermission, remove } = useGranteeSelection({
        selectedGrantees,
        onSelectedGranteesChange,
        initialPermissionLevel,
    });
    return (_jsxs("div", { className: b(), "data-testid": dataTestId, children: [
            _jsx(UiDialogHeader, { title: dialogTitle, titleSize: "large", onClose: onClose, leading: backButton }), _jsx(UiGranteeAsyncPicker, { loadOptions: loadOptions, selectedGrantees: selectedGrantees, onSelect: select, onPermissionChange: changePermission, onRemove: remove }), _jsxs(UiDialogFooter, { divider: true, children: [
                    _jsx(UiButton, { label: intl.formatMessage(commonDialogMessages.cancel), variant: "secondary", size: "medium", onClick: onCancel }), _jsx(UiButton, { label: intl.formatMessage(olpAddGranteeDialogMessages.add), variant: "primary", size: "medium", onClick: onShare, isDisabled: selectedGrantees.length === 0 })
                ] })
        ] }));
}
