import React, { memo, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Disc3, ExternalLink, Star } from 'lucide-react'; import type { SubsonicAlbum, SubsonicSong } from '@/lib/api/subsonicTypes'; import { formatTotalDuration } from '@/utils/componentHelpers/nowPlayingHelpers'; import { formatTrackTime } from '@/lib/format/formatDuration'; interface AlbumCardProps { album: SubsonicAlbum | null; songs: SubsonicSong[]; currentTrackId: string; albumName: string; albumId?: string; albumYear?: number; onNavigate: (path: string) => void; } const ALBUM_TRACK_LIMIT = 10; const AlbumCard = memo(function AlbumCard({ album, songs, currentTrackId, albumName, albumId, albumYear, onNavigate }: AlbumCardProps) { const { t } = useTranslation(); const [showAll, setShowAll] = useState(false); useEffect(() => { setShowAll(false); }, [albumId]); if (songs.length === 0) return null; const totalDur = songs.reduce((sum, s) => sum + (s.duration || 0), 0); const currentIdx = songs.findIndex(s => s.id === currentTrackId); const position = currentIdx >= 0 ? `${currentIdx + 1} / ${songs.length}` : `${songs.length}`; // Sliding window anchored at the current track: when the running track sits // beyond position N, show the N tracks ending with (and including) it. // "Show all" expands to the full list. let visibleSongs: SubsonicSong[]; if (showAll) { visibleSongs = songs; } else if (currentIdx < ALBUM_TRACK_LIMIT) { visibleSongs = songs.slice(0, ALBUM_TRACK_LIMIT); } else { const end = currentIdx + 1; visibleSongs = songs.slice(end - ALBUM_TRACK_LIMIT, end); } const hiddenCount = Math.max(0, songs.length - visibleSongs.length); return (

{t('nowPlaying.fromAlbum')}

{albumId && ( )}
{albumName} {albumYear && {albumYear}} {albumYear && ·} {t('nowPlaying.trackPosition', { pos: position, defaultValue: 'Track {{pos}}' })} · {formatTotalDuration(totalDur)} {album?.playCount != null && album.playCount > 0 && ( <>·{t('nowPlaying.playsCount', { count: album.playCount, defaultValue: '{{count}} plays' })} )}
{visibleSongs.map((track, idx) => { const isActive = track.id === currentTrackId; return (
{isActive ? : track.track ?? '—'} {track.title} {formatTrackTime(track.duration)}
); })}
{songs.length > ALBUM_TRACK_LIMIT && ( )}
); }); export default AlbumCard;