import { writable, derived } from 'svelte/store';
import { queueItems } from './upload-queue';

// Controls BottomNav visibility. Upload page sets this false on mount and restores on destroy.
export const showBottomNav = writable(true);

// Controls the UploadSheet overlay. FAB sets true; sheet sets false.
export const uploadSheetOpen = writable(false);

// Count of items still needing attention — shown as FAB badge. Includes the terminal
// states on purpose: counting only pending/uploading meant a rejected upload decremented
// the badge exactly as if it had succeeded, so the failure was indistinguishable from a
// completed upload. 'blocked' and 'error' stay counted until the user clears or retries them.
export const uploadBadgeCount = derived(
	queueItems,
	($items) =>
		$items.filter(
			(i) =>
				i.status === 'pending' ||
				i.status === 'uploading' ||
				i.status === 'error' ||
				i.status === 'blocked'
		).length
);
