"use client"; import { useState } from "react"; import { badgeVariants } from "@/components/ui/badge"; import type { Anchor, Note } from "@/lib/annotations/types"; import type { UseNotes } from "@/lib/annotations/useNotes"; import { NoteComposer, NoteThread } from "./NoteThread"; // The notes on one THING: a timeline row (`entry`), a take (`take`). A count // of the open ones, folded; unfolded, every note on it and a box for another. type Pin = { kind: "entry"; entry: string } | { kind: "take"; take: string }; export const notesOn = (notes: Note[], pin: Pin) => notes.filter((n) => { const a = n.anchor as Anchor; if (pin.kind === "entry") { return (a.kind === "entry" && a.entry === pin.entry) || (a.kind === "edit" && a.entry === pin.entry); } return (a.kind === "take" && a.take === pin.take) || (a.kind === "moment" && a.take === pin.take); }); export default function AnchoredNotes({ notes, pin, startOpen = false, label = "notes", }: { notes: UseNotes; pin: Pin; startOpen?: boolean; label?: string; }) { const [open, setOpen] = useState(startOpen); const mine = notesOn(notes.notes, pin).filter((n) => n.anchor.kind !== "moment"); const openCount = mine.filter((n) => n.status === "open").length; const key = pin.kind === "entry" ? pin.entry : pin.take; return (