"use client";
import { useMemo } from "react";
import { MobileSheet } from "components/MobileSheet";
import { useEntity } from "src/replicache";
import { useEditorStates } from "src/state/useEditorState";
import { getCommentDraftRange } from "components/Blocks/TextBlock/commentDraftPlugin";
import { useEditorCommentContext } from "./EditorCommentContext";
import {
useEditorCommentDraftStore,
useEditorCommentSheetStore,
} from "./editorCommentStores";
import { cancelEditorCommentDraft } from "./editorCommentDraftActions";
import { EditorCommentDraftComposer } from "./AnnotationSideColumn";
import { EditorCommentThread } from "./EditorCommentThread";
import { getEditorCommentQuoteText } from "./getEditorCommentQuote";
// On mobile (and canvas pages, where there's no side column) comments live in
// a slide-in panel, like the interactions drawer on published documents.
// Tapping a commented range opens just that thread; drafting opens the
// composer. A browse-all-comments flow can layer on top of this later.
export function EditorCommentMobileSheet() {
let { pageID, comments } = useEditorCommentContext();
let {
pageID: sheetPageID,
focusedCommentID,
close,
} = useEditorCommentSheetStore();
let draft = useEditorCommentDraftStore((s) => s.draft);
let draftOnThisPage = draft?.pageID === pageID;
let focusedComment = focusedCommentID
? comments.find((c) => c.commentEntityID === focusedCommentID)
: undefined;
// Closes (with the sheet's exit animation) when the focused comment goes
// away, e.g. if it's deleted while open
let open =
sheetPageID === pageID &&
pageID !== "" &&
(!!focusedComment || draftOnThisPage);
return (