'use client'; import { useState, useEffect, useMemo } from 'react'; import { useInventoryStore } from '@/store/useInventoryStore'; import shared from '../../styles/shared.module.css'; import styles from '../../styles/Dlcs.module.css'; import { PlatformFilter, isOnSteam, isOnEpic, isOnXbox, matchesPlatform, } from './types'; import { DLC, isNamedDLC } from '@/lib/utils'; import { fetchDLCs } from '@/lib/db'; const PLATFORM_FILTER_LABELS: Record = { all: 'All', steam: 'Steam', epic: 'Epic', xbox: 'Xbox' }; export default function DlcsPage() { const store = useInventoryStore(); const [allDlcs, setAllDlcs] = useState([]); const [search, setSearch] = useState(''); const [platformFilter, setPlatformFilter] = useState('all'); const [statusFilter, setStatusFilter] = useState<'all' | 'unlocked' | 'locked'>('all'); useEffect(() => { fetchDLCs() .then((data: DLC[]) => setAllDlcs(data.filter(isNamedDLC))); }, []); const filtered = useMemo(() => { return allDlcs.filter(dlc => { if (!matchesPlatform(dlc, platformFilter)) return false; if (search.trim() && !dlc.name!.toLowerCase().includes(search.toLowerCase())) return false; if (statusFilter === 'unlocked' && !store.unlockedDLCs.includes(dlc.id)) return false; if (statusFilter === 'locked' && store.unlockedDLCs.includes(dlc.id)) return false; return true; }); }, [allDlcs, search, platformFilter, statusFilter, store.unlockedDLCs]); const handleToggle = (id: string) => store.toggleItem(id, 'dlcs'); const handleUnlockShown = () => { const ids = filtered.map(d => d.id); const merged = Array.from(new Set([...store.unlockedDLCs, ...ids])); store.unlockAllInCategory('dlcs', merged); }; const handleLockShown = () => { const ids = new Set(filtered.map(d => d.id)); const remaining = store.unlockedDLCs.filter(id => !ids.has(id)); store.unlockAllInCategory('dlcs', remaining); }; const handleUnlockAll = () => { store.unlockAllInCategory('dlcs', allDlcs.map(d => d.id)); }; return (

DLCs

{store.unlockedDLCs.length} of {allDlcs.length || '-'} dlcs unlocked

setSearch(e.target.value)} />
{(Object.keys(PLATFORM_FILTER_LABELS) as PlatformFilter[]).map(p => ( ))}
{(['all', 'unlocked', 'locked'] as const).map(s => ( ))}
{filtered.length} shown
{filtered.length === 0 ? (
No DLCs match
) : (
{filtered.map(dlc => { const unlocked = store.unlockedDLCs.includes(dlc.id); return (
handleToggle(dlc.id)} > {dlc.name}
ST EP XB
); })}
)}
); }