export function activateCommentsMode(editContext, options) {
    if (!editContext)
        return;
    editContext.setShowComments(true);
    editContext.setShowSuggestedEdits?.(false);
    editContext.setShowSuggestedEditsDiff?.(false);
    if (editContext.mode === "suggestions") {
        void editContext.changeMode?.("edit", {
            reason: options?.reason || "comment-write",
        });
    }
}
/**
 * Turn on suggestions mode: edits made on the canvas are recorded as suggested
 * edits instead of direct changes, and the feedback surface is opened so the
 * suggestions are visible as they are made. Shared by the toolbar control and
 * the in-sidebar "Suggestions mode" toggle so both behave identically.
 */
export function enterSuggestionsMode(editContext, options) {
    if (!editContext)
        return;
    editContext.setShowSuggestedEdits?.(true);
    void editContext.changeMode?.("suggestions", {
        reason: options?.reason || "toolbar",
    });
    openCommentsFeedback(editContext, { forceSidebar: options?.forceSidebar });
}
/**
 * Turn off suggestions mode and return the canvas to normal editing.
 */
export function exitSuggestionsMode(editContext, options) {
    if (!editContext)
        return;
    editContext.setShowSuggestedEdits?.(false);
    editContext.setShowSuggestedEditsDiff?.(false);
    if (editContext.mode === "suggestions") {
        void editContext.changeMode?.("edit", {
            reason: options?.reason || "toolbar",
        });
    }
}
function disableSuggestionsMode(editContext) {
    exitSuggestionsMode(editContext, { reason: "feedback-sidebar-close" });
}
export function openCommentsFeedback(editContext, options) {
    if (!editContext)
        return;
    editContext.setShowComments(true);
    if (editContext.isMobile || options?.forceSidebar) {
        editContext.openSidebar("feedback", {
            preserveOpenSidebars: options?.preserveOpenSidebars,
        });
    }
}
export function toggleCommentsFeedback(editContext) {
    if (!editContext)
        return;
    const nextShowComments = !editContext.showComments;
    editContext.setShowComments(nextShowComments);
    if (!nextShowComments) {
        disableSuggestionsMode(editContext);
        return;
    }
    if (nextShowComments && editContext.isMobile) {
        editContext.openSidebar("feedback");
    }
}
export function closeCommentsFeedback(editContext) {
    if (!editContext)
        return;
    editContext.setShowComments(false);
    disableSuggestionsMode(editContext);
}
/**
 * Suggestions mode only works for items edited on the WYSIWYG canvas (items
 * with a layout). Mirrors the `hasLayout` check used by the viewport toolbar so
 * the in-sidebar control is only offered where it actually does something.
 */
export function isSuggestionsModeAvailable(editContext) {
    if (!editContext)
        return false;
    const slot = editContext.getActiveSlotContext();
    const pageItem = slot?.primaryPageViewContext?.page?.item;
    return Boolean(slot?.item?.hasLayout ??
        editContext.item?.hasLayout ??
        pageItem?.hasLayout ??
        false);
}
//# sourceMappingURL=openCommentsFeedback.js.map