import type { MediaItem } from '@shared/ipc'

/**
 * Which of a source's items are worth queuing for a one-click "Download new":
 * everything not already downloaded AND not already represented in the download
 * queue. `queuedUrls` is the set of URLs that currently have any queue entry, so
 * an item that's downloading, queued, completed, failed, or canceled is left
 * alone — matching the expanded panel's "Download N pending" semantics (a failed
 * item is retried via its own Retry, not bulk-swept here).
 *
 * Pure so the choice is unit-tested without the store; the impure enqueue lives
 * in the caller (LibraryView).
 */
export function selectUndownloaded(items: MediaItem[], queuedUrls: Set<string>): MediaItem[] {
  return items.filter((it) => !it.downloaded && !queuedUrls.has(it.url))
}
