// HACK: hide "Podcasts" from the music library.
//
// The user stores podcasts inside the music library under a folder/album named
// "Podcasts", so they leak into album/artist/track/playlist queries. Jellyfin's
// item queries here don't give us a clean server-side exclusion for that folder,
// so we filter client-side by name. This is intentionally a blunt instrument:
// anything whose own name, album, or (album) artist is literally "Podcasts" is
// dropped. If the folder is ever renamed, update PODCAST_FOLDER_NAME.
import type { MediaItem } from "$lib/api/types";

const PODCAST_FOLDER_NAME = "podcasts";

function isPodcastName(value: string | null | undefined): boolean {
  return value?.trim().toLowerCase() === PODCAST_FOLDER_NAME;
}

/** True when an item belongs to the "Podcasts" folder/album and should be hidden. */
export function isPodcastItem(item: MediaItem): boolean {
  return (
    isPodcastName(item.name) ||
    isPodcastName(item.albumName) ||
    isPodcastName(item.albumArtist) ||
    (item.artists?.some(isPodcastName) ?? false)
  );
}

/** Remove "Podcasts" entries from a list of music items. */
export function excludePodcasts(items: MediaItem[]): MediaItem[] {
  return items.filter((item) => !isPodcastItem(item));
}
