{#if loadingChapters && sortedChapters.length === 0}
{#if viewMode === 'grid'}
{#each Array(24) as _}
{/each}
{:else}
{#each Array(8) as _}
{/each}
{/if}
{:else if viewMode === 'grid'}
{#each sortedChapters as ch, i}
{@const inProgress = !ch.isRead && (ch.lastPageRead ?? 0) > 0}
{@const isGridSelected = selectedIds.has(ch.id)}
{/each}
{:else}
{#each pageChapters as ch}
{@const idxInSorted = sortedChapters.indexOf(ch)}
{@const isSelected = selectedIds.has(ch.id)}
{@const chInProgress = !ch.isRead && (ch.lastPageRead ?? 0) > 0}
hasSelection ? onToggleSelect(ch.id, e) : onOpen(ch, chInProgress)}
onkeydown={(e) => e.key === 'Enter' && (hasSelection ? onToggleSelect(ch.id, e) : onOpen(ch, chInProgress))}
oncontextmenu={(e) => { e.preventDefault(); ctx = { x: e.clientX, y: e.clientY, chapter: ch, idx: idxInSorted } }}
>
{ch.name}
{#if ch.scanlator}{ch.scanlator}{/if}
{#if ch.uploadDate}{formatDate(ch.uploadDate)}{/if}
{#if ch.lastPageRead && ch.lastPageRead > 0 && !ch.isRead}p.{ch.lastPageRead}{/if}
{#if ch.isRead}
{/if}
{#if ch.isDownloaded}
{:else if enqueueing.has(ch.id)}
{:else}
{/if}
{/each}
{/if}
{#if totalPages > 1}
{/if}
{#if ctx}