import type { Manga, Chapter } from '$lib/types' class SeriesState { current = $state(null) loading = $state(false) error = $state(null) chapters = $state([]) chaptersLoading = $state(false) chaptersError = $state(null) chapterSortDesc = $state(true) chapterFilter = $state({ unread: false, downloaded: false, query: '' }) filteredChapters = $derived.by(() => { let result = this.chapters if (this.chapterFilter.unread) result = result.filter(c => !c.read) if (this.chapterFilter.downloaded) result = result.filter(c => c.downloaded) if (this.chapterFilter.query) { const q = this.chapterFilter.query.toLowerCase() result = result.filter(c => c.name.toLowerCase().includes(q)) } const sorted = [...result].sort((a, b) => a.chapterNumber - b.chapterNumber) return this.chapterSortDesc ? sorted.reverse() : sorted }) } export const seriesState = new SeriesState()