"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 { useCommentContext } from "./CommentContext";
import { useCommentDraftStore, useCommentSheetStore } from "./commentStores";
import { cancelCommentDraft } from "./commentDraftActions";
import { CommentDraftComposer } from "./AnnotationSideColumn";
import { CommentThread } from "./CommentThread";
import { getCommentQuoteText } from "./getCommentQuote";
// 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 CommentMobileSheet() {
let { pageID, comments } = useCommentContext();
let { pageID: sheetPageID, focusedCommentID, close } = useCommentSheetStore();
let draft = useCommentDraftStore((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 (