{"version":3,"file":"useCanPaginateReplies.mjs","names":[],"sources":["../../../../../src/components/MessageList/hooks/useCanPaginateReplies.ts"],"sourcesContent":["import { useThreadContext } from '../../Threads';\nimport { useStateStore } from '../../../store';\n\nimport type { LocalMessage, ThreadState } from 'stream-chat';\n\nconst threadSelector = ({ replyCount }: ThreadState) => ({ replyCount });\n\nconst paginatorSelector = ({ items }: { items: LocalMessage[] | undefined }) => ({\n  loadedCount: items?.length ?? 0,\n});\n\n/**\n * Whether the list this hook is rendered in has replies left to fetch by scrolling. Always `true`\n * outside a thread.\n *\n * A short list is within the scroll threshold of both its top and bottom, and the reply paginator\n * allows more pages optimistically until it has queried, so the thread's counts decide instead.\n * Nothing loaded yet means no: the first page belongs to `Thread.reload()` (`GET /threads/:id`),\n * and a thread with no replies has nothing to load. Otherwise it is true only when the thread's\n * `replyCount` exceeds the loaded count. The loaded count is the raw window length, so local-only\n * messages (e.g. a failed send) can only make it return `false` while replies remain.\n */\nexport const useCanPaginateReplies = (): boolean => {\n  const thread = useThreadContext();\n  const { replyCount } = useStateStore(thread?.state, threadSelector) ?? {};\n  const { loadedCount } = useStateStore(\n    thread?.messagePaginator?.state,\n    paginatorSelector,\n  ) ?? { loadedCount: 0 };\n\n  if (!thread) return true;\n  if (loadedCount === 0) return false;\n  return (replyCount ?? 0) > loadedCount;\n};\n"],"mappings":";;;AAKA,IAAM,kBAAkB,EAAE,kBAA+B,EAAE,WAAW;AAEtE,IAAM,qBAAqB,EAAE,aAAoD,EAC/E,aAAa,OAAO,UAAU,EAChC;;;;;;;;;;;;AAaA,IAAa,8BAAuC;CAClD,MAAM,SAAS,iBAAiB;CAChC,MAAM,EAAE,eAAe,cAAc,QAAQ,OAAO,cAAc,KAAK,CAAC;CACxE,MAAM,EAAE,gBAAgB,cACtB,QAAQ,kBAAkB,OAC1B,iBACF,KAAK,EAAE,aAAa,EAAE;CAEtB,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,gBAAgB,GAAG,OAAO;CAC9B,QAAQ,cAAc,KAAK;AAC7B"}