export function getAvailableSidebarsForWorkspace({ sidebars, workspaces, userWorkspaces, targetWorkspaceId, isLimitedPreviewUser, }) {
    // Limited reviewers receive an intentionally reduced client configuration.
    // Do not intersect its Reviews sidebar with Sitecore workspace metadata: old
    // or customized settings may omit Reviews and would leave the reviewer with
    // an empty rail and no way to open the review they were invited to.
    if (isLimitedPreviewUser) {
        return sidebars.filter((sidebar) => sidebar.id === "reviews");
    }
    const hasBackendWorkspaceSettings = (userWorkspaces?.length ?? 0) > 0;
    const workspaceSettings = userWorkspaces?.find((workspace) => workspace.id === targetWorkspaceId);
    const workspaceAllowedSidebarIds = workspaceSettings?.sidebars ?? [];
    const workspaceDefaultSidebarIds = workspaces?.find((workspace) => workspace.id === targetWorkspaceId)
        ?.defaultSidebars ?? [];
    const allowedSidebarIds = workspaceAllowedSidebarIds.length > 0
        ? workspaceAllowedSidebarIds
        : workspaceDefaultSidebarIds;
    return sidebars.filter((sidebar) => {
        // If the backend does not provide workspace settings, fall back to the
        // globally registered sidebar list for local/static configurations.
        if (!hasBackendWorkspaceSettings) {
            return true;
        }
        if (!workspaceSettings) {
            return false;
        }
        return allowedSidebarIds.includes(sidebar.id);
    });
}
//# sourceMappingURL=sidebarAvailability.js.map