import { forwardRef, ReactNode, Ref, useState } from 'react'; import { Group } from '@mantine/core'; import { AutoTextSize } from 'auto-text-size'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import styles from './library-header.module.scss'; import { LibraryItem } from '/@/renderer/api/types'; import { Text } from '/@/renderer/components'; import { ItemImagePlaceholder } from '/@/renderer/features/shared/components/item-image-placeholder'; interface LibraryHeaderProps { background: string; children?: ReactNode; imagePlaceholderUrl?: string | null; imageUrl?: string | null; item: { route: string; type: LibraryItem }; title: string; } export const LibraryHeader = forwardRef( ( { imageUrl, imagePlaceholderUrl, background, title, item, children }: LibraryHeaderProps, ref: Ref, ) => { const { t } = useTranslation(); const [isImageError, setIsImageError] = useState(false); const onImageError = () => { setIsImageError(true); }; const itemTypeString = () => { switch (item.type) { case LibraryItem.ALBUM: return t('entity.album', { count: 1 }); case LibraryItem.ARTIST: return t('entity.artist', { count: 1 }); case LibraryItem.ALBUM_ARTIST: return t('entity.albumArtist', { count: 1 }); case LibraryItem.PLAYLIST: return t('entity.playlist', { count: 1 }); case LibraryItem.SONG: return t('entity.track', { count: 1 }); default: return t('common.unknown'); } }; return (
{imageUrl && !isImageError ? ( cover ) : ( )}

{itemTypeString()}

{title}

{children}
); }, );