import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2021-2026 GoodData Corporation
import { useCallback, useEffect, useRef } from "react";
import { Overlay } from "../../../Overlay/Overlay.js";
import { AddGranteeBase } from "./AddGranteeBase.js";
import { useShareDialogInteraction } from "./ComponentInteractionContext.js";
import { ShareGranteeBase } from "./ShareGranteeBase.js";
import { useShareDialogBase } from "./useShareDialogBase.js";
const alignPoints = [{ align: "cc cc" }];
/**
 * @internal
 */
export function ShareDialogBase(props) {
    const { onCancel, sharedObject, currentUser, currentUserPermissions, dashboardFilters, dashboardParameters, dashboardLinkBasePath, isCurrentUserWorkspaceManager, isShareGrantHidden, applyShareGrantOnSelect, showDashboardShareLink, isGranteeShareLoading, onShareLinkCopy, } = props;
    const { openInteraction, closeInteraction } = useShareDialogInteraction();
    useEffect(() => {
        openInteraction();
    }, [openInteraction]);
    const handleCancel = useCallback(() => {
        onCancel();
        closeInteraction();
    }, [onCancel, closeInteraction]);
    const { onAddedGranteeDelete, onSharedGranteeDelete, onAddGranteeBackClick, onAddGranteeButtonClick, onGranteeAdd, onSubmitShareGrantee, onSubmitAddGrantee, granteesToAdd, dialogMode, isShareDialogDirty, isAddDialogDirty, sharedGrantees, appliedGranteesWithOwner, isGranteesLoading, isLockedNow, isUnderLenientControlNow, onLockChange, onUnderLenientControlChange, onGranularGranteeAddChange, onGranularGranteeShareChange, } = useShareDialogBase(props);
    const previouslyFocusedRef = useRef(document.activeElement);
    return (_jsx(Overlay, { alignPoints: alignPoints, isModal: true, positionType: "fixed", className: "gd-share-dialog-overlay", children: _jsx("div", { className: "s-gd-share-dialog", children: dialogMode === "ShareGrantee" ? (_jsx(ShareGranteeBase, { currentUserPermissions: currentUserPermissions, dashboardFilters: dashboardFilters, dashboardParameters: dashboardParameters, dashboardLinkBasePath: dashboardLinkBasePath, isShareGrantHidden: isShareGrantHidden, applyShareGrantOnSelect: applyShareGrantOnSelect, showDashboardShareLink: showDashboardShareLink, onShareLinkCopy: onShareLinkCopy, isGranteeShareLoading: isGranteeShareLoading, isLoading: isGranteesLoading, isDirty: isShareDialogDirty, isLockedNow: isLockedNow, isUnderLenientControlNow: isUnderLenientControlNow, sharedObject: sharedObject, grantees: sharedGrantees, onCancel: handleCancel, onSubmit: onSubmitShareGrantee, onAddGranteeButtonClick: onAddGranteeButtonClick, onGranteeDelete: onSharedGranteeDelete, onLockChange: onLockChange, onUnderLenientControlChange: onUnderLenientControlChange, onGranularGranteeChange: onGranularGranteeShareChange, isCurrentUserWorkspaceManager: isCurrentUserWorkspaceManager })) : (_jsx(AddGranteeBase, { currentUserPermissions: currentUserPermissions, isDirty: isAddDialogDirty, currentUser: currentUser, appliedGrantees: appliedGranteesWithOwner, addedGrantees: granteesToAdd, sharedObject: sharedObject, previouslyFocusedRef: previouslyFocusedRef, onAddUserOrGroups: onGranteeAdd, onDelete: onAddedGranteeDelete, onCancel: handleCancel, onSubmit: onSubmitAddGrantee, onBackClick: onAddGranteeBackClick, onGranularGranteeChange: onGranularGranteeAddChange, isGranteeShareLoading: isGranteeShareLoading })) }) }));
}
